• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
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  */
16 
17 package com.android.myroboapplication;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotEquals;
21 
22 import android.content.Intent;
23 
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.robolectric.Robolectric;
28 import org.robolectric.RobolectricTestRunner;
29 import org.robolectric.android.controller.ActivityController;
30 import org.robolectric.shadows.ShadowApplication;
31 
32 @RunWith(RobolectricTestRunner.class)
33 public class WelcomeActivityTest {
34 
35     @Before
setup()36     public void setup() throws Exception {}
37 
38     @Test
clickingLogin_shouldStartLoginActivity()39     public void clickingLogin_shouldStartLoginActivity() throws Exception {
40         System.out.println("\n\nSystem Properties:");
41         System.getProperties().forEach((key, value) -> System.out.println(key + ": " + value));
42         assertNotEquals(System.getProperty("robolectric.strict.mode"), "true");
43 
44        ActivityController<WelcomeActivity> controller =
45                 Robolectric.buildActivity(WelcomeActivity.class);
46         controller.setup(); // Moves Activity to RESUMED state
47         WelcomeActivity activity = controller.get();
48         activity.findViewById(R.id.login).performClick();
49         Intent expectedIntent = new Intent(activity, LoginActivity.class);
50         Intent actual = ShadowApplication.getInstance().getNextStartedActivity();
51         assertEquals(expectedIntent.getComponent(), actual.getComponent());
52     }
53 }
54