1- /*
2- * Copyright 2016 , Optimizely
3- * <p/>
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- * <p/>
8- * http://www.apache.org/licenses/LICENSE-2.0
9- * <p/>
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
1+ /****************************************************************************
2+ * Copyright 2017 , Optimizely, Inc. and contributors *
3+ * *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); *
5+ * you may not use this file except in compliance with the License. *
6+ * You may obtain a copy of the License at *
7+ * *
8+ * http://www.apache.org/licenses/LICENSE-2.0 *
9+ * *
10+ * Unless required by applicable law or agreed to in writing, software *
11+ * distributed under the License is distributed on an "AS IS" BASIS, *
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+ * See the License for the specific language governing permissions and *
14+ * limitations under the License. *
15+ *************************************************************************** /
1616package com .optimizely .ab .android .test_app ;
1717
1818import android .app .AlarmManager ;
4747import static android .support .test .espresso .Espresso .onView ;
4848import static android .support .test .espresso .action .ViewActions .click ;
4949import static android .support .test .espresso .assertion .ViewAssertions .matches ;
50+ import static android .support .test .espresso .matcher .ViewMatchers .isDisplayed ;
5051import static android .support .test .espresso .matcher .ViewMatchers .withId ;
5152import static android .support .test .espresso .matcher .ViewMatchers .withText ;
5253import static junit .framework .Assert .assertFalse ;
@@ -62,7 +63,7 @@ public class MainActivityEspressoTest {
6263 private ServiceScheduler serviceScheduler ;
6364 private Intent dataFileServiceIntent , eventIntentService ;
6465
65- private ActivityTestRule <MainActivity > activityTestRule = new ActivityTestRule <>(MainActivity .class );
66+ private ActivityTestRule <SplashScreenActivity > activityTestRule = new ActivityTestRule <>(SplashScreenActivity .class );
6667 @ Rule public TestRule chain = RuleChain
6768 .outerRule (new ExternalResource () {
6869 @ Override
@@ -148,46 +149,32 @@ protected void after() {
148149 public void experimentActivationForWhitelistUser () throws InterruptedException {
149150 // Check that the text was changed.
150151 // These tests are pointed at a real project.
151- // The user 'test_user` is in the whitelist for variation 1 for experiment 0 and experiment 1.
152- onView (withId (R .id .button_1 ))
153- .check (matches (withText ( context . getString ( R . string . main_act_button_1_text_var_1 ) )));
152+ // The user 'test_user` is in the whitelist for variation_a for experiment background_experiment
153+ onView (withId (R .id .tv_variation_a_text_1 ))
154+ .check (matches (isDisplayed ( )));
154155
155156 // Espresso will wait for Optimizely to start due to the registered idling resources
156- onView (withId (R .id .text_view_1 ))
157- .check (matches (withText (context .getString (R .string .main_act_text_view_1_var_1 ))));
158-
159157 assertTrue (serviceScheduler .isScheduled (dataFileServiceIntent ));
160158
161- onView (withId (R .id .button_1 )) // withId(R.id.my_view) is a ViewMatcher
162- .perform (click ()); // click() is a ViewAction
163-
164- onView (withId (R .id .text_view_1 ))
165- .check (matches (withText (context .getString (R .string .secondary_frag_text_view_1_var_1 ))));
166-
167- onView (withId (R .id .button_1 )) // withId(R.id.my_view) is a ViewMatcher
168- .perform (click ()); // click() is a ViewAction
159+ onView (withId (R .id .btn_variation_conversion )) // withId(R.id.my_view) is a ViewMatcher
160+ .perform (click ()); // click() is a ViewAction
169161
170162 List <Pair <String , String >> events = CountingIdlingResourceManager .getEvents ();
171- assertTrue (events .size () == 6 );
163+ assertTrue (events .size () == 2 );
172164 Iterator <Pair <String , String >> iterator = events .iterator ();
173165 while (iterator .hasNext ()) {
174166 Pair <String , String > event = iterator .next ();
175167 final String url = event .first ;
176168 final String payload = event .second ;
177- if (url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("7676481120" ) && payload .contains ("7661891902" )
178- || url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("7651112186" ) && payload .contains ("7674261140" )
179- || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("experiment_0" )
180- || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("experiment_1" )
181- || url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("7680080715" ) && payload .contains ("7685562539" )
182- || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("experiment_2" )) {
169+ if (url .equals ("https://logx.optimizely.com/log/decision" ) && payload .contains ("8126664113" ) && payload .contains ("8146590584" )
170+ || url .equals ("https://logx.optimizely.com/log/event" ) && payload .contains ("sample_conversion" )) {
183171 iterator .remove ();
184172 }
185173 }
186174 assertTrue (events .isEmpty ());
187175 MyApplication myApplication = (MyApplication ) activityTestRule .getActivity ().getApplication ();
188176 UserProfile userProfile = myApplication .getOptimizelyManager ().getUserProfile ();
189177 // Being in the white list should override user profile
190- assertNull (userProfile .lookup ("test_user" , "experiment_0" ));
191- assertNull (userProfile .lookup ("test_user" , "experiment_1" ));
178+ assertNull (userProfile .lookup ("test_user" , "background_experiment" ));
192179 }
193180}
0 commit comments