/
TestActivityRepoList.java
executable file
·133 lines (116 loc) · 4.48 KB
/
TestActivityRepoList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package fr.guddy.androidstarter.tests.ui;
import android.support.annotation.NonNull;
import android.support.test.rule.ActivityTestRule;
import com.github.polok.localify.LocalifyClient;
import org.frutilla.FrutillaTestRunner;
import org.frutilla.annotations.Frutilla;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import fr.guddy.androidstarter.mvp.repo_detail.ActivityRepoDetail;
import fr.guddy.androidstarter.mvp.repo_list.ActivityRepoList;
import fr.guddy.androidstarter.tests.mock.MockApplication;
import fr.guddy.androidstarter.tests.mock.MockModuleRest;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import static com.google.common.truth.Truth.assertThat;
//@org.junit.Ignore
@RunWith(FrutillaTestRunner.class)
public class TestActivityRepoList extends AbstractRobotiumTestCase<ActivityRepoList> {
//region Fields
private LocalifyClient mLocalifyClient;
private MockModuleRest mModuleRest;
private MockWebServer mMockWebServer;
//endregion
//region Constructor matching super
public TestActivityRepoList() {
super(new ActivityTestRule<>(ActivityRepoList.class, true, false));
}
//endregion
//region Test lifecycle
@Before
@Override
public void setUp() throws Exception {
super.setUp();
mModuleRest = MockApplication.sharedMockApplication().getModuleRest();
mModuleRest.setUp();
mMockWebServer = mModuleRest.getMockWebServer();
mLocalifyClient = new LocalifyClient.Builder()
.withResources(mContextTest.getResources())
.build();
}
@After
@Override
public void tearDown() throws Exception {
super.tearDown();
try {
mMockWebServer.shutdown();
} catch (@NonNull final Exception loException) {
loException.printStackTrace();
}
}
//endregion
//region Test methods
@Frutilla(
Given = "A single GitHub repo from the API",
When = "",
Then = "It should display a repo named \"git-consortium\""
)
@Test
public void test_ListRepos_WithOneRepo_DisplayListWithOnlyThisRepo() {
Given:
{
final String lsOneRepoJSONData = mLocalifyClient.localify().loadRawFile(fr.guddy.androidstarter.test.R.raw.repos_octocat);
final MockResponse loMockResponseWithOneRepo = new MockResponse().setResponseCode(200);
loMockResponseWithOneRepo.setBody(lsOneRepoJSONData);
mMockWebServer.enqueue(loMockResponseWithOneRepo);
try {
mMockWebServer.start(4000);
} catch (@NonNull final Exception loException) {
loException.printStackTrace();
}
mActivity = mActivityTestRule.launchActivity(null);
}
When:
{
}
Then:
{
final boolean lbFoundTheRepo = mSolo.waitForText("git-consortium", 1, 5000L, true);
assertThat(lbFoundTheRepo).isTrue();
}
}
@Frutilla(
Given = "A single GitHub repo from the API",
When = "Click on its name",
Then = "It should display the detail of this repo"
)
@Test
public void test_ListRepos_ClickOnOneRepo_DisplayDetailWithOnlyThisRepo() {
Given:
{
final String lsOneRepoJSONData = mLocalifyClient.localify().loadRawFile(fr.guddy.androidstarter.test.R.raw.repos_octocat);
final MockResponse loMockResponseWithOneRepo = new MockResponse().setResponseCode(200);
loMockResponseWithOneRepo.setBody(lsOneRepoJSONData);
mMockWebServer.enqueue(loMockResponseWithOneRepo);
try {
mMockWebServer.start(4000);
} catch (@NonNull final Exception loException) {
loException.printStackTrace();
}
mActivity = mActivityTestRule.launchActivity(null);
}
When:
{
mSolo.clickOnText("git-consortium");
}
Then:
{
mSolo.assertCurrentActivity("should be on ActivityRepoDetail", ActivityRepoDetail.class);
final boolean lbFoundTheRepo = mSolo.waitForText("This repo is for demonstration purposes only.", 1, 5000L, true);
assertThat(lbFoundTheRepo).isTrue();
}
}
//endregion
}