@Test
  public void execute_whenUberAppInsalled_shouldPointToUberApp() throws IOException {
    String expectedUri =
        readUriResourceWithUserAgentParam(
            "src/test/resources/deeplinkuris/just_client_provided", USER_AGENT_DEEPLINK);

    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);

    RobolectricPackageManager packageManager =
        (RobolectricPackageManager) shadowActivity.getPackageManager();

    PackageInfo uberPackage = new PackageInfo();
    uberPackage.packageName = UBER_PACKAGE_NAME;
    packageManager.addPackage(uberPackage);

    RideParameters rideParameters = new RideParameters.Builder().build();

    RequestDeeplink requestDeeplink =
        new RequestDeeplink.Builder()
            .setClientId(CLIENT_ID)
            .setRideParameters(rideParameters)
            .build();

    requestDeeplink.execute(activity);

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(expectedUri, startedIntent.getData().toString());
  }
 @Test
 public void viewPager_CurrentPage() {
   MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class);
   ViewPager viewPager = (ViewPager) mainActivity.findViewById(R.id.viewPager);
   assertEquals(viewPager.getCurrentItem(), 2);
   assertEquals(viewPager.getAdapter().getPageTitle(2).toString(), "Today");
 }
Beispiel #3
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    main = Robolectric.setupActivity(Activity.class);

    db = new DBCore(main);
  }
Beispiel #4
0
  @Test
  @PrepareForTest(WXImageView.class)
  public void testInitComponentHostView() throws Exception {

    ImageView imageView =
        mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
    assertEquals(imageView.getClass(), WXImageView.class);
  }
  @Test
  public void testCreateActivity() {
    when(restService.getSomething()).thenReturn("abc");

    Robolectric.setupActivity(MainActivity.class);

    verify(myPrinter).print("ABC");
  }
  // Should fail
  @Test
  public void testButtonThree_shouldChangeText() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.button_3).performClick();

    TextView textView = (TextView) activity.findViewById(R.id.test_text);
    Assert.assertTrue("Button 3 Clicked".equals(textView.getText()));
  }
 @Test
 public void onContentChangedShouldBeCalledAfterContentViewIsSet() throws RuntimeException {
   final Transcript transcript = new Transcript();
   ActivityWithContentChangedTranscript customActivity =
       Robolectric.setupActivity(ActivityWithContentChangedTranscript.class);
   customActivity.setTranscript(transcript);
   customActivity.setContentView(R.layout.main);
   transcript.assertEventsSoFar("onContentChanged was called; title is \"Main Layout\"");
 }
Beispiel #8
0
  @Test
  public void testSetResize() throws Exception {
    ImageView imageView =
        mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
    mWXImage.mHost = imageView;

    mWXImage.setResize("cover");
    ImageView.ScaleType scaleType = mWXImage.getHostView().getScaleType();
    assertEquals(scaleType, ImageView.ScaleType.CENTER_CROP);
  }
  @Before
  public void setup() throws Exception {
    mActivity = Robolectric.setupActivity(MainActivity.class);
    assertNotNull("MainActivity is not instantiated.", mActivity);

    mSavedGameManager = new SavedGameManager(mActivity);
    assertNotNull("SavedGameManager is not instantiated.", mSavedGameManager);

    mGame = new Game(DIFFICULTY, BOARD_SIZE);
    assertNotNull("Game is not instantiated.", mGame);
  }
  // Should pass
  @Test
  public void testButtonOneClick_shouldShowToast() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.button_1).performClick();

    ShadowLooper.idleMainLooper();
    // Check toast correctness
    Assert.assertTrue(ShadowToast.getTextOfLatestToast().equals("Button #1 Clicked"));

    // Check textView text
    TextView textView = (TextView) activity.findViewById(R.id.test_text);
    Assert.assertTrue("Button 1 Clicked".equals(textView.getText()));
  }
Beispiel #11
0
  @Test
  @PrepareForTest(WXImageView.class)
  public void testSetBackgroundColor() throws Exception {

    ImageView imageView =
        mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
    mWXImage.mHost = imageView;

    mWXImage.setBackgroundColor("#FFFFFF");

    Drawable drawable = mWXImage.getHostView().getBackground();
    assertEquals(drawable instanceof BorderDrawable, true);
  }
  @Test
  public void execute_whenNoUberApp_shouldPointToMobileSite() throws IOException {
    String expectedUri =
        readUriResourceWithUserAgentParam(
            "src/test/resources/deeplinkuris/no_app_installed", USER_AGENT_DEEPLINK);

    Activity activity = Robolectric.setupActivity(Activity.class);
    ShadowActivity shadowActivity = shadowOf(activity);

    RideParameters rideParameters = new RideParameters.Builder().build();

    RequestDeeplink requestDeeplink =
        new RequestDeeplink.Builder()
            .setClientId(CLIENT_ID)
            .setRideParameters(rideParameters)
            .build();
    requestDeeplink.execute(activity);

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertEquals(expectedUri, startedIntent.getData().toString());
  }
  @Test
  public void deveListarOpcoesDoCarpdaio() {

    GrupoOpcaoCardapioActivity grupoOpcaoCardapioActivity =
        Robolectric.setupActivity(GrupoOpcaoCardapioActivity.class);

    GrupoItems grupoItems = new GrupoItems();
    grupoItems.newItem("Feijao");
    grupoItems.newItem("Arroz");
    Intent i = new Intent(grupoOpcaoCardapioActivity, OpcaoCardapioActivity.class);
    i.putExtra(OpcaoCardapioListFragment.ARG_GRUPO_OPCAO, grupoItems);

    OpcaoCardapioActivity opcaoCardapioActivity =
        Robolectric.buildActivity(OpcaoCardapioActivity.class)
            .withIntent(i)
            .create()
            .visible()
            .get();

    OpcaoCardapioListFragment opcoesFragment = opcaoCardapioActivity.getOpcoesFragment();
    ListView opcoesListView = opcoesFragment.getListView();
    ListAdapter adapter = opcoesListView.getAdapter();
    EditText arroz =
        (EditText)
            adapter
                .getView(0, null, null)
                .findViewById(R.id.cardapio_opcao_item_list_descricao_input);
    EditText feijao =
        (EditText)
            adapter
                .getView(1, null, null)
                .findViewById(R.id.cardapio_opcao_item_list_descricao_input);

    Assert.assertEquals("Arroz", arroz.getText().toString());
    Assert.assertEquals("Feijao", feijao.getText().toString());
  }
 @Before
 public void setUp() throws Exception {
   mActivity = Robolectric.setupActivity(Activity.class);
   db = new DbHelper(mActivity);
   database = db.getWritableDatabase();
 }
 @Test
 public void shouldRetrievePackageNameFromTheManifest() throws Exception {
   assertThat(Robolectric.setupActivity(Activity.class).getPackageName())
       .isEqualTo(RuntimeEnvironment.application.getPackageName());
 }
 @Test
 public void testOnCreateView() throws Exception {
   MainActivity_ activity = Robolectric.setupActivity(MainActivity_.class);
   assertNotNull(activity);
 }
 @Before
 public void setUp() throws Exception {
   activity = Robolectric.setupActivity(ParsingActivity_.class);
 }
 @Before
 public void setUp() throws Exception {
   activity = Robolectric.setupActivity(MainActivity.class);
 }
 @Test
 public void testSomething() throws Exception {
   assertTrue(Robolectric.setupActivity(PhotosListViewActivity.class) != null);
 }
 @Before
 public void setUpContext() {
   mockActivity = Robolectric.setupActivity(Activity.class);
   mockContext = shadowOf(mockActivity).getApplicationContext();
 }
 @Before
 public void setup() throws Exception {
   BluetoothSetup.UNIT_TEST = true;
   activity = Robolectric.setupActivity(BluetoothSetup.class);
 }
Beispiel #22
0
 @Before
 public void setup() throws Exception {
   activity = Robolectric.setupActivity(MainActivity.class);
   assertNotNull("MainActivity is not instantiated", activity);
 }