Search in sources :

Example 21 with TestItem

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

the class WebFragmentLocalTest method testStory.

@Test
public void testStory() {
    TestWebItem item = new TestWebItem() {

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

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

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

        @Override
        public String getDisplayedTitle() {
            return "Ask HN";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {

        @Override
        public String getText() {
            return "text";
        }
    });
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 22 with TestItem

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

the class HackerNewsItemTest method testKidCountNull.

@Test
public void testKidCountNull() {
    item.populate(new TestItem() {

        @Override
        public long[] getKids() {
            return null;
        }
    });
    assertEquals(0, item.getKidCount());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 23 with TestItem

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

the class HackerNewsItemTest method testGetUrlNonStory.

@Test
public void testGetUrlNonStory() {
    item.populate(new TestItem() {

        @Override
        public String getRawType() {
            return "comment";
        }
    });
    assertEquals(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"), item.getUrl());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 24 with TestItem

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

the class HackerNewsItemTest method testGetDisplayedTime.

@Test
public void testGetDisplayedTime() {
    item.populate(new TestItem() {

        @Override
        public long getTime() {
            // Apr 15 2015
            return 1429027200l;
        }

        @Override
        public String getBy() {
            return "author";
        }
    });
    assertThat(item.getDisplayedAuthor(RuntimeEnvironment.application, true, 0)).contains(" - author");
    assertThat(item.getDisplayedAuthor(RuntimeEnvironment.application, false, 0)).contains(" - author");
    item.populate(new TestItem() {

        @Override
        public String getBy() {
            return "author";
        }

        @Override
        public boolean isDead() {
            return true;
        }
    });
    assertThat(item.getDisplayedTime(RuntimeEnvironment.application)).contains(RuntimeEnvironment.application.getString(R.string.dead_prefix));
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 25 with TestItem

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

the class HackerNewsItemTest method testGetUrlStoryNoUrl.

@Test
public void testGetUrlStoryNoUrl() {
    item.populate(new TestItem() {

        @Override
        public String getRawType() {
            return "story";
        }
    });
    assertEquals(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"), item.getUrl());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) 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