2
2
3
3
import com .dockerx .rxreact .domain .*;
4
4
import com .dockerx .rxreact .repository .GitHbubRepos ;
5
+ import io .reactivex .Flowable ;
5
6
import io .reactivex .subscribers .TestSubscriber ;
6
7
import org .junit .Before ;
7
8
import org .junit .Test ;
@@ -33,11 +34,13 @@ public class GitHubServiceImplTest {
33
34
@ Before
34
35
public void setup () {
35
36
initMocks (this );
36
- gitHubService = new GitHubServiceImpl (gitHbubRepos );
37
- when (gitHbubRepos .getRepos (anyString ())).thenAnswer (m -> getReposForTest ());
37
+ gitHubService = new GitHubServiceImpl (gitHbubRepos );
38
+ when (gitHbubRepos .getRepos (anyString ())).thenAnswer (m -> getReposForTest ());
38
39
39
40
when (gitHbubRepos .getCommitsInWeek (anyString (), anyString ())).thenAnswer (m -> getCommitsInWeekForTest ());
40
- when (gitHbubRepos .getSingleCommit (anyString (), anyString (), anyString ())).thenAnswer (m -> getSingleCommitForTest ());
41
+ when (gitHbubRepos .getSingleCommit (anyString (),
42
+ anyString (),
43
+ anyString ())).thenAnswer (m -> getSingleCommitForTest ());
41
44
when (gitHbubRepos .getSingleCommitByUrl (anyString ())).thenAnswer (m -> getSingleCommitForTest ());
42
45
}
43
46
@@ -52,6 +55,7 @@ private List<Repository> getReposForTest() {
52
55
new Repository ("repo3" , LocalDateTime .now ().minusDays (3 ))
53
56
);
54
57
}
58
+
55
59
@ Test
56
60
public void getRepos () {
57
61
TestSubscriber <String > testSubscriber = new TestSubscriber <>();
@@ -63,7 +67,7 @@ public void getRepos() {
63
67
testSubscriber .assertNoErrors ();
64
68
assertThat (testSubscriber .values ())
65
69
.as ("getRepos returns all user code repository " )
66
- .containsExactly ("repo1 " ,"repo2 " , "repo3 " );
70
+ .containsExactly ("repo1 " , "repo2 " , "repo3 " );
67
71
}
68
72
69
73
@ Test
@@ -94,7 +98,6 @@ public void getCommitsInWeek() {
94
98
}
95
99
96
100
97
-
98
101
@ Test
99
102
public void getCommittedFilesByUser () {
100
103
TestSubscriber <CommittedFile > testSubscriber = new TestSubscriber <>();
@@ -117,13 +120,23 @@ private List<Commit> getCommitsInWeekForTest() {
117
120
return Arrays .asList (
118
121
Commit .builder ()
119
122
.sha ("sha1" )
120
- .committer (new Committer ("test-user" ,"https://github.com/muyinchen" ,"https://api.github.com/users/muyinchen/orgs" ))
121
- .author (new Author ("url2" ,"https://github.com/muyinchen" ,true ,"https://api.github.com/users/muyinchen/orgs" ))
123
+ .committer (new Committer ("test-user" ,
124
+ "https://github.com/muyinchen" ,
125
+ "https://api.github.com/users/muyinchen/orgs" ))
126
+ .author (new Author ("url2" ,
127
+ "https://github.com/muyinchen" ,
128
+ true ,
129
+ "https://api.github.com/users/muyinchen/orgs" ))
122
130
.build (),
123
131
Commit .builder ()
124
132
.sha ("sha2" )
125
- .committer (new Committer ("no-test-user" ,"https://github.com/muyinchen/no-test-user" ,"https://api.github.com/users/muyinchen/orgs/no-test-user" ))
126
- .author (new Author ("url2" ,"https://github.com/muyinchen/no-test-user" ,true ,"https://api.github.com/users/muyinchen/orgs/no-test-user" ))
133
+ .committer (new Committer ("no-test-user" ,
134
+ "https://github.com/muyinchen/no-test-user" ,
135
+ "https://api.github.com/users/muyinchen/orgs/no-test-user" ))
136
+ .author (new Author ("url2" ,
137
+ "https://github.com/muyinchen/no-test-user" ,
138
+ true ,
139
+ "https://api.github.com/users/muyinchen/orgs/no-test-user" ))
127
140
.build ()
128
141
);
129
142
}
@@ -140,4 +153,20 @@ private SingleCommit getSingleCommitForTest() {
140
153
)
141
154
);
142
155
}
156
+
157
+ @ Test
158
+ public void testTestSubscriber () {
159
+
160
+ TestSubscriber <String > testSubscriber = new TestSubscriber <>();
161
+ //In order to emit "1", "2", "3"
162
+ Flowable .just ("1" , "2" , "3" ).subscribe (testSubscriber );
163
+ //Assert whether values are equal
164
+ testSubscriber .assertValues ("1" , "2" , "3" );
165
+ //Assert value does not exist
166
+ testSubscriber .assertNever ("4" );
167
+ //Is the number of asserted values equal?
168
+ testSubscriber .assertValueCount (3 );
169
+ //Assertion terminated
170
+ testSubscriber .assertTerminated ();
171
+ }
143
172
}
0 commit comments