1
1
package org .gitlab4j .api ;
2
2
3
3
import static java .util .Comparator .comparing ;
4
+ import static org .gitlab4j .api .JsonUtils .compareJson ;
4
5
import static org .junit .Assert .assertEquals ;
5
6
import static org .junit .Assert .assertNotNull ;
7
+ import static org .junit .Assert .assertTrue ;
6
8
import static org .mockito .ArgumentMatchers .any ;
7
9
import static org .mockito .Mockito .when ;
8
10
import static org .mockito .MockitoAnnotations .initMocks ;
@@ -35,7 +37,8 @@ public class TestStreams implements Constants {
35
37
36
38
@ BeforeClass
37
39
public static void setupClass () throws Exception {
38
- // Get a list of users sorted by username
40
+
41
+ // Get a list of users sorted by username, we use this as thye source of truth for the asserts
39
42
sortedUsers = JsonUtils .unmarshalResourceList (User .class , "user-list.json" );
40
43
sortedUsers .sort (comparing (User ::getUsername ));
41
44
}
@@ -52,34 +55,34 @@ public void setup() throws Exception {
52
55
@ Test
53
56
public void testStream () throws Exception {
54
57
58
+ // Arrange
55
59
Stream <User > stream = new UserApi (gitLabApi ).getUsersStream ();
56
- assertNotNull (stream );
57
60
61
+ // Assert
62
+ assertNotNull (stream );
58
63
List <User > users = stream .sorted (comparing (User ::getUsername )).collect (toList ());
59
64
assertNotNull (users );
60
65
61
66
assertEquals (users .size (), sortedUsers .size ());
62
-
63
67
for (int i = 0 ; i < users .size (); i ++) {
64
- assertEquals (users .get (i ).getId (), sortedUsers .get (i ).getId ());
65
- assertEquals (users .get (i ).getUsername (), sortedUsers .get (i ).getUsername ());
68
+ assertTrue (compareJson (sortedUsers .get (i ), users .get (i )));
66
69
}
67
70
}
68
71
69
72
@ Test
70
73
public void testParallelStream () throws Exception {
71
74
75
+ // Arrange
72
76
Stream <User > stream = new UserApi (gitLabApi ).getUsersStream ();
73
- assertNotNull (stream );
74
77
78
+ // Assert
79
+ assertNotNull (stream );
75
80
List <User > users = stream .parallel ().sorted (comparing (User ::getUsername )).collect (toList ());
76
81
assertNotNull (users );
77
82
78
83
assertEquals (users .size (), sortedUsers .size ());
79
-
80
84
for (int i = 0 ; i < users .size (); i ++) {
81
- assertEquals (users .get (i ).getId (), sortedUsers .get (i ).getId ());
82
- assertEquals (users .get (i ).getUsername (), sortedUsers .get (i ).getUsername ());
85
+ assertTrue (compareJson (sortedUsers .get (i ), users .get (i )));
83
86
}
84
87
}
85
88
}
0 commit comments