Search in sources :

Example 31 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class BaseListActivityLandTest method testRotate.

@Test
public void testRotate() {
    activity.onItemSelected(new TestHnItem(1L) {

        @Override
        public String getDisplayedTitle() {
            return "item title";
        }

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    assertThat(activity).hasTitle("item title");
    Bundle savedState = new Bundle();
    activity.onSaveInstanceState(savedState);
    RuntimeEnvironment.setQualifiers("");
    controller = Robolectric.buildActivity(TestListActivity.class);
    activity = controller.create(savedState).postCreate(null).start().resume().get();
    assertThat(activity).hasTitle(activity.getString(R.string.title_activity_list));
    savedState = new Bundle();
    activity.onSaveInstanceState(savedState);
    RuntimeEnvironment.setQualifiers("w820dp-land");
    controller = Robolectric.buildActivity(TestListActivity.class);
    activity = controller.create(savedState).postCreate(null).start().resume().get();
    assertThat(activity).hasTitle("item title");
    assertTrue(((ShadowFloatingActionButton) ShadowExtractor.extract(activity.findViewById(R.id.reply_button))).isVisible());
}
Also used : TestListActivity(io.github.hidroh.materialistic.test.TestListActivity) Bundle(android.os.Bundle) NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 32 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class FavoriteActivityTest method testClearClearSelection.

@Test
public void testClearClearSelection() {
    activity.onItemSelected(new TestHnItem(1L));
    shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next()).dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("clear").build());
    assertNull(activity.getSelectedItem());
}
Also used : TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 33 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class FavoriteActivityTest method testRemoveClearSelection.

@Test
public void testRemoveClearSelection() {
    ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("3").build());
    assertNull(activity.getSelectedItem());
    activity.onItemSelected(new TestHnItem(1L));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("2").build());
    assertNotNull(activity.getSelectedItem());
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
    assertNull(activity.getSelectedItem());
}
Also used : ShadowContentObserver(org.robolectric.shadows.ShadowContentObserver) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 34 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class AppUtilsTest method testOpenExternalUrlNoConnection.

@Test
public void testOpenExternalUrlNoConnection() {
    shadowOf((ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE)).setActiveNetworkInfo(null);
    AppUtils.openWebUrlExternal(RuntimeEnvironment.application, new TestHnItem(1L) {

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    }, "http://example.com", null);
    assertThat(shadowOf(RuntimeEnvironment.application).getNextStartedActivity()).hasComponent(RuntimeEnvironment.application, OfflineWebActivity.class).hasExtra(OfflineWebActivity.EXTRA_URL, "http://example.com");
}
Also used : ConnectivityManager(android.net.ConnectivityManager) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Test(org.junit.Test)

Example 35 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class BaseListActivityLandTest method testDefaultCommentView.

@Test
public void testDefaultCommentView() {
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_comments)).apply();
    controller.pause().resume();
    activity.onItemSelected(new TestHnItem(1L) {

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

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    assertCommentMode();
    activity.findViewById(R.id.reply_button).performClick();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class);
}
Also used : NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Aggregations

TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)35 Test (org.junit.Test)31 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)23 RecyclerView (android.support.v7.widget.RecyclerView)12 TextView (android.widget.TextView)9 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 NonNull (android.support.annotation.NonNull)8 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)8 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)6 Context (android.content.Context)5 TestItem (io.github.hidroh.materialistic.test.TestItem)5 Before (org.junit.Before)4 Fragment (android.support.v4.app.Fragment)3 View (android.view.View)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 Item (io.github.hidroh.materialistic.data.Item)3 WebItem (io.github.hidroh.materialistic.data.WebItem)3 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)3 ShadowContentObserver (org.robolectric.shadows.ShadowContentObserver)3