Search in sources :

Example 1 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 2 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 3 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)

Example 4 with Config

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

the class ItemActivityTest method testFullscreen.

@Config(shadows = { ShadowFloatingActionButton.class })
@Test
public void testFullscreen() {
    Intent intent = new Intent();
    WebItem webItem = new TestWebItem() {

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public String getId() {
            return "1";
        }
    };
    intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
    controller.withIntent(intent).create().start().resume().visible();
    ShadowFloatingActionButton shadowFab = (ShadowFloatingActionButton) ShadowExtractor.extract(activity.findViewById(R.id.reply_button));
    assertTrue(shadowFab.isVisible());
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    assertFalse(shadowFab.isVisible());
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, false));
    assertTrue(shadowFab.isVisible());
}
Also used : ShadowFloatingActionButton(io.github.hidroh.materialistic.test.shadow.ShadowFloatingActionButton) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Intent(android.content.Intent) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 5 with Config

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

the class BaseListActivityLandTest method testScrollItemToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollItemToTop() {
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
    assertThat(tabLayout.getTabCount()).isEqualTo(2);
    tabLayout.getTabAt(0).select();
    ViewPager viewPager = (ViewPager) activity.findViewById(R.id.content);
    viewPager.getAdapter().instantiateItem(viewPager, 0);
    viewPager.getAdapter().finishUpdate(viewPager);
    RecyclerView itemRecyclerView = (RecyclerView) viewPager.findViewById(R.id.recycler_view);
    itemRecyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(1);
    tabLayout.getTabAt(1).select();
    tabLayout.getTabAt(0).select();
    tabLayout.getTabAt(0).select();
    assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : TabLayout(android.support.design.widget.TabLayout) NonNull(android.support.annotation.NonNull) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) ViewPager(android.support.v4.view.ViewPager) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) 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