Search in sources :

Example 31 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class HackerNewsItemTest method testGetSource.

@Test
public void testGetSource() {
    assertEquals("news.ycombinator.com", item.getSource());
    item.populate(new TestItem() {

        @Override
        public String getRawUrl() {
            return "http://example.com";
        }
    });
    assertEquals("example.com", item.getSource());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 32 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class HackerNewsItemTest method testParcelFavorite.

@Test
public void testParcelFavorite() {
    Parcel parcel = Parcel.obtain();
    item.populate(new TestItem() {
    });
    item.setFavorite(true);
    item.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    assertTrue(HackerNewsItem.CREATOR.createFromParcel(parcel).isFavorite());
}
Also used : Parcel(android.os.Parcel) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 33 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class HackerNewsItemTest method testGetKidItems.

@Test
public void testGetKidItems() {
    assertThat(item.getKidItems()).isEmpty();
    item.populate(new TestItem() {

        @Override
        public long[] getKids() {
            return new long[] { 1l, 2l };
        }
    });
    assertThat(item.getKidItems()).hasSize(2);
    assertEquals(1, item.getKidItems()[0].getRank());
    assertEquals(2, item.getKidItems()[1].getRank());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 34 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class ItemActivityTest method testPoll.

@Test
public void testPoll() {
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {

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

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

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    controller.withIntent(intent).create().start().resume();
    assertThat(activity.findViewById(R.id.source)).isNotVisible();
    assertEquals(R.drawable.ic_poll_white_18dp, shadowOf(((TextView) activity.findViewById(R.id.posted)).getCompoundDrawables()[0]).getCreatedFromResId());
}
Also used : NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) TextView(android.widget.TextView) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 35 with TestItem

use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.

the class ItemActivityTest method testJobGivenDeepLink.

@Test
public void testJobGivenDeepLink() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("https://news.ycombinator.com/item?id=1"));
    controller.withIntent(intent).create().start().resume();
    verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {

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

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

        @Override
        public String getUrl() {
            return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
        }

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

        @Override
        public boolean isStoryType() {
            return true;
        }
    });
    assertEquals(R.drawable.ic_work_white_18dp, shadowOf(((TextView) activity.findViewById(R.id.posted)).getCompoundDrawables()[0]).getCreatedFromResId());
    assertThat((TextView) activity.findViewById(R.id.source)).hasText("http://example.com");
    reset(hackerNewsClient);
    shadowOf(activity).recreate();
    verify(hackerNewsClient, never()).getItem(any(), eq(ItemManager.MODE_DEFAULT), any(ResponseListener.class));
}
Also used : NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) TextView(android.widget.TextView) ResponseListener(io.github.hidroh.materialistic.data.ResponseListener) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

TestItem (io.github.hidroh.materialistic.test.TestItem)40 Test (org.junit.Test)38 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)15 Intent (android.content.Intent)12 Bundle (android.os.Bundle)9 NonNull (android.support.annotation.NonNull)8 Fragment (android.support.v4.app.Fragment)7 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)5 TextView (android.widget.TextView)4 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)4 RecyclerView (android.support.v7.widget.RecyclerView)3 WebView (android.webkit.WebView)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 ShadowWebView (org.robolectric.shadows.ShadowWebView)3 SuppressLint (android.annotation.SuppressLint)2 Parcel (android.os.Parcel)2 TabLayout (android.support.design.widget.TabLayout)2 Item (io.github.hidroh.materialistic.data.Item)2 ResponseListener (io.github.hidroh.materialistic.data.ResponseListener)2 WebItem (io.github.hidroh.materialistic.data.WebItem)2