Search in sources :

Example 86 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 87 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)

Example 88 with Config

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

the class UserActivityTest method testScrollToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollToTop() {
    verify(userManager).getUser(eq("username"), userCaptor.capture());
    userCaptor.getValue().onResponse(user);
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    recyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1);
    TabLayout.Tab tab = ((TabLayout) activity.findViewById(R.id.tab_layout)).getTabAt(0);
    tab.select();
    tab.select();
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : TabLayout(android.support.design.widget.TabLayout) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 89 with Config

use of org.robolectric.annotation.Config in project android-oss by kickstarter.

the class DateTimeUtilsTest method testRelative_withLocale.

@Test
@Config(qualifiers = "de")
public void testRelative_withLocale() {
    final Context context = context();
    final KSString ksString = ksString();
    final DateTime dateTime = DateTime.parse("2015-12-17T18:35:05Z");
    final RelativeDateTimeOptions.Builder builder = RelativeDateTimeOptions.builder();
    assertEquals("vor 2 Minuten", DateTimeUtils.relative(context, ksString, dateTime, builder.relativeToDateTime(DateTime.parse("2015-12-17T18:37:05Z")).build()));
    assertEquals("in 2 Minuten", DateTimeUtils.relative(context, ksString, dateTime, builder.relativeToDateTime(DateTime.parse("2015-12-17T18:33:05Z")).build()));
}
Also used : Context(android.content.Context) RelativeDateTimeOptions(com.kickstarter.libs.RelativeDateTimeOptions) KSString(com.kickstarter.libs.KSString) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 90 with Config

use of org.robolectric.annotation.Config in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldCancelAndClearNotifications.

@Test
@Config(shadows = { ShadowRoboNotificationManager.class, ShadowBadgeCountUpdater.class })
public void shouldCancelAndClearNotifications() throws Exception {
    ShadowRoboNotificationManager.notifications.clear();
    OneSignalInitFromApplication();
    threadAndTaskWait();
    // Create 2 notifications
    Bundle bundle = getBaseNotifBundle();
    OneSignalPackagePrivateHelper.NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
    bundle = getBaseNotifBundle("UUID2");
    OneSignalPackagePrivateHelper.NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
    // Test canceling
    Map<Integer, ShadowRoboNotificationManager.PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
    Iterator<Map.Entry<Integer, ShadowRoboNotificationManager.PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
    ShadowRoboNotificationManager.PostedNotification postedNotification = postedNotifsIterator.next().getValue();
    OneSignal.cancelNotification(postedNotification.id);
    Assert.assertEquals(1, ShadowBadgeCountUpdater.lastCount);
    Assert.assertEquals(1, ShadowRoboNotificationManager.notifications.size());
    OneSignal.clearOneSignalNotifications();
    Assert.assertEquals(0, ShadowBadgeCountUpdater.lastCount);
    Assert.assertEquals(0, ShadowRoboNotificationManager.notifications.size());
    // Make sure they are marked dismissed.
    SQLiteDatabase readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase();
    Cursor cursor = readableDb.query(OneSignalPackagePrivateHelper.NotificationTable.TABLE_NAME, new String[] { "created_time" }, OneSignalPackagePrivateHelper.NotificationTable.COLUMN_NAME_DISMISSED + " = 1", null, null, null, null);
    Assert.assertEquals(2, cursor.getCount());
    cursor.close();
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Bundle(android.os.Bundle) GcmBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle) GenerateNotificationRunner.getBaseNotifBundle(com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle) Cursor(android.database.Cursor) ShadowRoboNotificationManager(com.onesignal.ShadowRoboNotificationManager) Test(org.junit.Test) BuildConfig(com.onesignal.BuildConfig) 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