Skip to content

Commit 3cf7918

Browse files
committed
Modified to use compareJson() for comparing the items in the stream.
1 parent 0a1d1ed commit 3cf7918

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/test/java/org/gitlab4j/api/TestStreams.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.gitlab4j.api;
22

33
import static java.util.Comparator.comparing;
4+
import static org.gitlab4j.api.JsonUtils.compareJson;
45
import static org.junit.Assert.assertEquals;
56
import static org.junit.Assert.assertNotNull;
7+
import static org.junit.Assert.assertTrue;
68
import static org.mockito.ArgumentMatchers.any;
79
import static org.mockito.Mockito.when;
810
import static org.mockito.MockitoAnnotations.initMocks;
@@ -35,7 +37,8 @@ public class TestStreams implements Constants {
3537

3638
@BeforeClass
3739
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
3942
sortedUsers = JsonUtils.unmarshalResourceList(User.class, "user-list.json");
4043
sortedUsers.sort(comparing(User::getUsername));
4144
}
@@ -52,34 +55,34 @@ public void setup() throws Exception {
5255
@Test
5356
public void testStream() throws Exception {
5457

58+
// Arrange
5559
Stream<User> stream = new UserApi(gitLabApi).getUsersStream();
56-
assertNotNull(stream);
5760

61+
// Assert
62+
assertNotNull(stream);
5863
List<User> users = stream.sorted(comparing(User::getUsername)).collect(toList());
5964
assertNotNull(users);
6065

6166
assertEquals(users.size(), sortedUsers.size());
62-
6367
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)));
6669
}
6770
}
6871

6972
@Test
7073
public void testParallelStream() throws Exception {
7174

75+
// Arrange
7276
Stream<User> stream = new UserApi(gitLabApi).getUsersStream();
73-
assertNotNull(stream);
7477

78+
// Assert
79+
assertNotNull(stream);
7580
List<User> users = stream.parallel().sorted(comparing(User::getUsername)).collect(toList());
7681
assertNotNull(users);
7782

7883
assertEquals(users.size(), sortedUsers.size());
79-
8084
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)));
8386
}
8487
}
8588
}

0 commit comments

Comments
 (0)