Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
3cf79186
Commit
3cf79186
authored
Dec 16, 2018
by
Greg Messner
Browse files
Modified to use compareJson() for comparing the items in the stream.
parent
0a1d1eda
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestStreams.java
View file @
3cf79186
package
org.gitlab4j.api
;
package
org.gitlab4j.api
;
import
static
java
.
util
.
Comparator
.
comparing
;
import
static
java
.
util
.
Comparator
.
comparing
;
import
static
org
.
gitlab4j
.
api
.
JsonUtils
.
compareJson
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
...
@@ -35,7 +37,8 @@ public class TestStreams implements Constants {
...
@@ -35,7 +37,8 @@ public class TestStreams implements Constants {
@BeforeClass
@BeforeClass
public
static
void
setupClass
()
throws
Exception
{
public
static
void
setupClass
()
throws
Exception
{
// Get a list of users sorted by username
// Get a list of users sorted by username, we use this as thye source of truth for the asserts
sortedUsers
=
JsonUtils
.
unmarshalResourceList
(
User
.
class
,
"user-list.json"
);
sortedUsers
=
JsonUtils
.
unmarshalResourceList
(
User
.
class
,
"user-list.json"
);
sortedUsers
.
sort
(
comparing
(
User:
:
getUsername
));
sortedUsers
.
sort
(
comparing
(
User:
:
getUsername
));
}
}
...
@@ -52,34 +55,34 @@ public class TestStreams implements Constants {
...
@@ -52,34 +55,34 @@ public class TestStreams implements Constants {
@Test
@Test
public
void
testStream
()
throws
Exception
{
public
void
testStream
()
throws
Exception
{
// Arrange
Stream
<
User
>
stream
=
new
UserApi
(
gitLabApi
).
getUsersStream
();
Stream
<
User
>
stream
=
new
UserApi
(
gitLabApi
).
getUsersStream
();
assertNotNull
(
stream
);
// Assert
assertNotNull
(
stream
);
List
<
User
>
users
=
stream
.
sorted
(
comparing
(
User:
:
getUsername
)).
collect
(
toList
());
List
<
User
>
users
=
stream
.
sorted
(
comparing
(
User:
:
getUsername
)).
collect
(
toList
());
assertNotNull
(
users
);
assertNotNull
(
users
);
assertEquals
(
users
.
size
(),
sortedUsers
.
size
());
assertEquals
(
users
.
size
(),
sortedUsers
.
size
());
for
(
int
i
=
0
;
i
<
users
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
users
.
size
();
i
++)
{
assertEquals
(
users
.
get
(
i
).
getId
(),
sortedUsers
.
get
(
i
).
getId
());
assertTrue
(
compareJson
(
sortedUsers
.
get
(
i
),
users
.
get
(
i
)));
assertEquals
(
users
.
get
(
i
).
getUsername
(),
sortedUsers
.
get
(
i
).
getUsername
());
}
}
}
}
@Test
@Test
public
void
testParallelStream
()
throws
Exception
{
public
void
testParallelStream
()
throws
Exception
{
// Arrange
Stream
<
User
>
stream
=
new
UserApi
(
gitLabApi
).
getUsersStream
();
Stream
<
User
>
stream
=
new
UserApi
(
gitLabApi
).
getUsersStream
();
assertNotNull
(
stream
);
// Assert
assertNotNull
(
stream
);
List
<
User
>
users
=
stream
.
parallel
().
sorted
(
comparing
(
User:
:
getUsername
)).
collect
(
toList
());
List
<
User
>
users
=
stream
.
parallel
().
sorted
(
comparing
(
User:
:
getUsername
)).
collect
(
toList
());
assertNotNull
(
users
);
assertNotNull
(
users
);
assertEquals
(
users
.
size
(),
sortedUsers
.
size
());
assertEquals
(
users
.
size
(),
sortedUsers
.
size
());
for
(
int
i
=
0
;
i
<
users
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
users
.
size
();
i
++)
{
assertEquals
(
users
.
get
(
i
).
getId
(),
sortedUsers
.
get
(
i
).
getId
());
assertTrue
(
compareJson
(
sortedUsers
.
get
(
i
),
users
.
get
(
i
)));
assertEquals
(
users
.
get
(
i
).
getUsername
(),
sortedUsers
.
get
(
i
).
getUsername
());
}
}
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment