Search in sources :

Example 81 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class ShadowLayoutInflaterTest method testSetContentViewByItemResource.

@Test
@Config(qualifiers = "w0dp")
public void testSetContentViewByItemResource() throws Exception {
    Activity activity = buildActivity(Activity.class).create().get();
    activity.setContentView(R.layout.main_layout);
    TextView tv1 = (TextView) activity.findViewById(R.id.hello);
    TextView tv2 = (TextView) activity.findViewById(R.id.world);
    assertNotNull(tv1);
    assertNull(tv2);
}
Also used : Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) TextView(android.widget.TextView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 82 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class ShadowLayoutInflaterTest method testMultiOrientation_explicitLandscape.

@Test
@Config(qualifiers = "land")
public void testMultiOrientation_explicitLandscape() throws Exception {
    context = buildActivity(Activity.class).create().start().resume().get();
    // Confirm explicit "orientation = landscape" works.
    context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    int layoutResId = context.getResources().getIdentifier("multi_orientation", "layout", TEST_PACKAGE);
    ViewGroup view = (ViewGroup) LayoutInflater.from(context).inflate(layoutResId, null);
    assertEquals(view.getId(), R.id.landscape);
    assertInstanceOf(LinearLayout.class, view);
}
Also used : ViewGroup(android.view.ViewGroup) Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 83 with Config

use of org.robolectric.annotation.Config in project glide by bumptech.

the class GifDecoderTest method testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone.

@Test
@Config(shadows = { CustomShadowBitmap.class })
public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone() throws IOException {
    byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_disposal_none.gif");
    GifHeaderParser headerParser = new GifHeaderParser();
    headerParser.setData(data);
    GifHeader header = headerParser.parseHeader();
    GifDecoder decoder = new StandardGifDecoder(provider);
    decoder.setData(header, data);
    decoder.advance();
    Bitmap firstFrame = decoder.getNextFrame();
    decoder.advance();
    decoder.getNextFrame();
    decoder.advance();
    Bitmap firstFrameTwice = decoder.getNextFrame();
    assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(), (((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels()));
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 84 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class ItemActivityTest method testScrollToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollToTop() {
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public int getKidCount() {
            return 10;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    controller.withIntent(intent).create().start().resume();
    // see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    recyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1);
    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
    assertThat(tabLayout.getTabCount()).isEqualTo(2);
    tabLayout.getTabAt(1).select();
    tabLayout.getTabAt(0).select();
    tabLayout.getTabAt(0).select();
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : TabLayout(android.support.design.widget.TabLayout) NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 85 with Config

use of org.robolectric.annotation.Config in project materialistic by hidroh.

the class DrawerActivityLoginTest method testRemoveAccount.

@Config(sdk = 21)
@Test
public void testRemoveAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null);
    Preferences.setUsername(activity, "existing");
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick();
    assertThat(alertDialog).isNotShowing();
    assertThat(ShadowAccountManager.get(activity).getAccounts()).isEmpty();
}
Also used : AlertDialog(android.app.AlertDialog) ShadowAlertDialog(org.robolectric.shadows.ShadowAlertDialog) Account(android.accounts.Account) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

Config (org.robolectric.annotation.Config)158 Test (org.junit.Test)153 Intent (android.content.Intent)21 ComponentName (android.content.ComponentName)16 Bundle (android.os.Bundle)10 Activity (android.app.Activity)7 Bitmap (android.graphics.Bitmap)7 Notification (android.app.Notification)6 Button (android.widget.Button)6 TextView (android.widget.TextView)6 BuildConfig (com.firebase.ui.auth.BuildConfig)6 BuildConfig (com.onesignal.BuildConfig)6 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)6 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)6 Properties (java.util.Properties)6 Account (android.accounts.Account)5 Network (android.net.Network)5 NetworkInfo (android.net.NetworkInfo)5 RecyclerView (android.support.v7.widget.RecyclerView)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4