@Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Mockito.stub(mPhotoListManager.getPhotoListFetched()).toReturn(true);

    activityController = Robolectric.buildActivity(PhotosListViewActivity.class);
    subject = activityController.get();
    Mockito.doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                subject.requestPermissionCallback.Granted(1);
                return null;
              }
            })
        .when(mRequestPermissionUtils)
        .requestPermission(
            subject,
            Manifest.permission.ACCESS_FINE_LOCATION,
            subject.requestPermissionCallback,
            Constants.MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
    flickrPhotoList =
        new ArrayList<FlickrPhoto>(
            Arrays.asList(new FlickrPhoto("some-photo", "some-small-url", "some-big-url")));
    subject.setFlickrPhotoList(flickrPhotoList);
    activityController.create().start();
  }
  @Test
  public void testOnCreateWhenASKEnabledAndInactive() throws Exception {
    // mocking ASK as enable and inactive
    ShadowSettings.ShadowSecure.putString(
        RuntimeEnvironment.application.getContentResolver(),
        Settings.Secure.ENABLED_INPUT_METHODS,
        new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString()
            + ":"
            + new ComponentName(
                    RuntimeEnvironment.application.getPackageName(),
                    RuntimeEnvironment.application.getPackageName() + ".IME")
                .flattenToString());
    ShadowSettings.ShadowSecure.putString(
        RuntimeEnvironment.application.getContentResolver(),
        Settings.Secure.DEFAULT_INPUT_METHOD,
        new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString());

    Assert.assertNull(ShadowApplication.getInstance().getNextStartedActivity());
    ActivityController<LauncherSettingsActivity> controller =
        Robolectric.buildActivity(LauncherSettingsActivity.class).attach().create().resume();
    Intent startMainApp = ShadowApplication.getInstance().getNextStartedActivity();
    Assert.assertNotNull(startMainApp);

    Intent expectIntent = new Intent(controller.get(), MainSettingsActivity.class);

    Assert.assertEquals(expectIntent.getComponent(), startMainApp.getComponent());
  }
Exemplo n.º 3
0
 @Before
 public void prepare() {
   ActivityController<MainActivity_> activityController =
       Robolectric.buildActivity(MainActivity_.class);
   activityController.create();
   activity = activityController.get();
 }
 @Before
 public void setup() {
   ((TestApplicationComponent) RacquetApplication.getApplication().getApplicationComponent())
       .inject(this);
   Club club = ModelBuilder.getClub(1, "My Club");
   Intent intent = ClubActivity.getIntent(RuntimeEnvironment.application, club);
   ActivityController<ClubActivity> activityController =
       ActivityController.of(Robolectric.getShadowsAdapter(), ClubActivity.class);
   activity = activityController.withIntent(intent).setup().get();
 }
 @Test
 public void testJustFinishIfResumedAgain() throws Exception {
   ActivityController<LauncherSettingsActivity> controller =
       Robolectric.buildActivity(LauncherSettingsActivity.class).attach().create().resume();
   ShadowActivity shadowActivity = Shadows.shadowOf(controller.get());
   Assert.assertFalse(shadowActivity.isFinishing());
   controller.pause().stop();
   Assert.assertFalse(shadowActivity.isFinishing());
   controller.restart().resume();
   Assert.assertTrue(shadowActivity.isFinishing());
 }
  @Before
  public void setUp() {
    final ActivityController<Activity> activityController = buildActivity(Activity.class);
    final Activity activity = activityController.create().get();
    activityController.start().resume().visible();

    TextInputLayout textInputLayout;
    activity.setContentView(textInputLayout = new TextInputLayout(activity));
    textInputLayout.addView(editText = new EditText(activity));
    editText.setText("0,00");
  }
    public SupportRequestManagerHarness() {
      supportFragment = new SupportRequestManagerFragment(lifecycle);
      supportController = Robolectric.buildActivity(FragmentActivity.class).create();

      supportController
          .get()
          .getSupportFragmentManager()
          .beginTransaction()
          .add(supportFragment, TAG)
          .commit();
      supportController.get().getSupportFragmentManager().executePendingTransactions();
    }
Exemplo n.º 8
0
  @Test
  public void shouldHaveContextInScopeMapAfterOnCreate() throws Exception {
    final ActivityController<A> aController = Robolectric.buildActivity(A.class);
    final A a = aController.get();

    assertThat(a.getScopedObjectMap().size(), equalTo(0));
    aController.create();

    boolean found = false;
    for (Object o : a.getScopedObjectMap().values()) if (o == a) found = true;

    assertTrue("Couldn't find context in scope map", found);
  }
Exemplo n.º 9
0
  @Test
  public void shouldHaveTwoItemsInScopeMapAfterOnCreate() throws Exception {
    final ActivityController<B> bController = Robolectric.buildActivity(B.class);
    final B b = bController.get();

    assertThat(b.getScopedObjectMap().size(), equalTo(0));
    bController.create();

    boolean found = false;
    for (Object o : b.getScopedObjectMap().values()) if (o == b) found = true;

    assertTrue("Couldn't find context in scope map", found);
    assertTrue(b.getScopedObjectMap().containsKey(Key.get(C.class)));
  }
Exemplo n.º 10
0
  @Test
  public void shouldCallActivityLifecycleCallbacks() {
    final Transcript transcript = new Transcript();
    final ActivityController<Activity> controller = buildActivity(Activity.class);
    RuntimeEnvironment.application.registerActivityLifecycleCallbacks(
        new ActivityLifecycleCallbacks(transcript));

    controller.create();
    transcript.assertEventsSoFar("onActivityCreated");

    controller.start();
    transcript.assertEventsSoFar("onActivityStarted");

    controller.resume();
    transcript.assertEventsSoFar("onActivityResumed");

    controller.saveInstanceState(new Bundle());
    transcript.assertEventsSoFar("onActivitySaveInstanceState");

    controller.pause();
    transcript.assertEventsSoFar("onActivityPaused");

    controller.stop();
    transcript.assertEventsSoFar("onActivityStopped");

    controller.destroy();
    transcript.assertEventsSoFar("onActivityDestroyed");
  }
Exemplo n.º 11
0
 /**
  * Attaches the fragment to the activity.
  *
  * @param activity activity the fragment is added to
  * @param tag tag to add the fragment
  * @param visible true if the activity should have visible called
  */
 private static void startFragmentHelper(
     Activity activity, Fragment fragment, String tag, boolean visible) {
   if (visible) {
     ActivityController.of(activity).visible();
   }
   FragmentManager fragmentManager = activity.getFragmentManager();
   fragmentManager.beginTransaction().add(fragment, tag).commit();
 }
  @Before
  public void setUp() {
    mActivityController = Robolectric.buildActivity(MainActivity.class).create().start().resume();

    mActivity = mActivityController.get();
    sut = WordDetailsTranslationFragment.newInstance(TestHelper.createWord(), 1);

    SupportFragmentTestUtil.startVisibleFragment(sut);
  }
  public void teardown() {
    if (activity != null) {
      activity.finish();
      activity = null;
    }

    if (controller != null) {
      controller.pause().stop().destroy();
      controller = null;
    }
  }
Exemplo n.º 14
0
 @Before
 public void setUp() {
   controller =
       Robolectric.buildActivity(TestListActivity.class)
           .create()
           .postCreate(null)
           .start()
           .resume()
           .visible();
   activity = controller.get();
   shadowOf(activity).clickMenuItem(android.R.id.home);
 }
  @Test
  public void testOnCreateWhenASKNotEnabled() throws Exception {
    // mocking ASK as disabled and inactive
    ShadowSettings.ShadowSecure.putString(
        RuntimeEnvironment.application.getContentResolver(),
        Settings.Secure.ENABLED_INPUT_METHODS,
        new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString());
    ShadowSettings.ShadowSecure.putString(
        RuntimeEnvironment.application.getContentResolver(),
        Settings.Secure.DEFAULT_INPUT_METHOD,
        new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString());

    Assert.assertNull(ShadowApplication.getInstance().getNextStartedActivity());
    ActivityController<LauncherSettingsActivity> controller =
        Robolectric.buildActivity(LauncherSettingsActivity.class).attach().create().resume();
    Intent startWizardActivityIntent = ShadowApplication.getInstance().getNextStartedActivity();
    Assert.assertNotNull(startWizardActivityIntent);

    Intent expectIntent =
        MainSettingsActivity.createStartActivityIntentForAddingFragmentToUi(
            controller.get(),
            MainSettingsActivity.class,
            new SetUpKeyboardWizardFragment(),
            TransitionExperiences.ROOT_FRAGMENT_EXPERIENCE_TRANSITION);

    Assert.assertEquals(expectIntent.getComponent(), startWizardActivityIntent.getComponent());
    Assert.assertEquals(expectIntent.getAction(), startWizardActivityIntent.getAction());
    Assert.assertEquals(
        expectIntent.getParcelableExtra("FragmentChauffeurActivity_KEY_FRAGMENT_ANIMATION"),
        startWizardActivityIntent.getParcelableExtra(
            "FragmentChauffeurActivity_KEY_FRAGMENT_ANIMATION"));
    Assert.assertEquals(
        expectIntent.getSerializableExtra("FragmentChauffeurActivity_KEY_FRAGMENT_CLASS_TO_ADD"),
        startWizardActivityIntent.getSerializableExtra(
            "FragmentChauffeurActivity_KEY_FRAGMENT_CLASS_TO_ADD"));
  }
Exemplo n.º 16
0
 public RequestManagerHarness() {
   fragment = new RequestManagerFragment(lifecycle);
   controller = Robolectric.buildActivity(Activity.class).create();
   controller.get().getFragmentManager().beginTransaction().add(fragment, TAG).commit();
   controller.get().getFragmentManager().executePendingTransactions();
 }
Exemplo n.º 17
0
 @After
 public void tearDown() {
   controller.pause().stop().destroy();
 }
 @Override
 public SupportFragmentController<F> attach() {
   activityController.attach();
   return this;
 }
 @Before
 public void setUp() {
   super.setUp();
   this.activityController = Robolectric.buildActivity(RemindersActivity.class);
   this.activity = activityController.create().start().visible().get();
 }
 public void setupActivity() {
   mActivity = mActivityHolder.create().start().resume().visible().get();
 }
 // @After => JUnit 4 annotation that specifies this method should be run after each test
 @After
 public void tearDown() {
   // Destroy activity after every test
   activityController.pause().stop().destroy();
 }
 public Activity getActivityWithIntent(Intent intent) {
   controller = Robolectric.buildActivity(instanceOfClass);
   activity = controller.withIntent(intent).create().get();
   return activity;
 }