2
2
3
3
import static org .junit .Assert .assertEquals ;
4
4
import static org .junit .Assert .assertNotNull ;
5
+ import static org .junit .Assert .assertTrue ;
5
6
import static org .junit .Assert .fail ;
6
7
import static org .junit .Assume .assumeNotNull ;
7
8
8
9
import java .util .List ;
10
+ import java .util .Optional ;
9
11
10
12
import org .gitlab4j .api .models .Namespace ;
11
13
import org .junit .Before ;
@@ -47,12 +49,9 @@ public void beforeMethod() {
47
49
public void testGetNamespaces () throws GitLabApiException {
48
50
List <Namespace > namespaces = gitLabApi .getNamespaceApi ().getNamespaces ();
49
51
assertNotNull (namespaces );
50
- for (Namespace namespace : namespaces ) {
51
- if (TEST_NAMESPACE .equals (namespace .getName ()))
52
- return ;
53
- }
54
-
55
- fail (TEST_NAMESPACE + " not found!" );
52
+ Optional <Namespace > matchingNamespace = namespaces .stream ().
53
+ filter (n -> n .getPath ().equals (TEST_NAMESPACE )).findFirst ();
54
+ assertTrue (TEST_NAMESPACE + " not found!" , matchingNamespace .isPresent ());
56
55
}
57
56
58
57
@ Test
@@ -63,7 +62,7 @@ public void testGetNamespacesViaPager() throws GitLabApiException {
63
62
while (pager .hasNext ()) {
64
63
List <Namespace > namespaces = pager .next ();
65
64
for (Namespace namespace : namespaces ) {
66
- if (TEST_NAMESPACE .equals (namespace .getName ()))
65
+ if (TEST_NAMESPACE .equals (namespace .getPath ()))
67
66
return ;
68
67
}
69
68
}
@@ -75,39 +74,36 @@ public void testGetNamespacesViaPager() throws GitLabApiException {
75
74
public void testGetNamespacesByPage () throws GitLabApiException {
76
75
List <Namespace > namespaces = gitLabApi .getNamespaceApi ().getNamespaces (1 , 10 );
77
76
assertNotNull (namespaces );
78
- for (Namespace namespace : namespaces ) {
79
- if (TEST_NAMESPACE .equals (namespace .getName ()))
80
- return ;
81
- }
82
-
83
- fail (TEST_NAMESPACE + " not found!" );
77
+ Optional <Namespace > matchingNamespace = namespaces .stream ().
78
+ filter (n -> n .getPath ().equals (TEST_NAMESPACE )).findFirst ();
79
+ assertTrue (TEST_NAMESPACE + " not found!" , matchingNamespace .isPresent ());
84
80
}
85
81
86
82
@ Test
87
83
public void testFindNamespaces () throws GitLabApiException {
88
84
List <Namespace > namespaces = gitLabApi .getNamespaceApi ().findNamespaces (TEST_NAMESPACE );
89
85
assertNotNull (namespaces );
90
- assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getName ());
86
+ assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getPath ());
91
87
}
92
88
93
89
@ Test
94
90
public void testFindSubgroupNamespaces () throws GitLabApiException {
95
91
List <Namespace > namespaces = gitLabApi .getNamespaceApi ().findNamespaces (TEST_SUB_GROUP );
96
92
assertNotNull (namespaces );
97
- assertEquals (TEST_SUB_GROUP , namespaces .get (0 ).getName ());
93
+ assertEquals (TEST_SUB_GROUP , namespaces .get (0 ).getPath ());
98
94
}
99
95
100
96
@ Test
101
97
public void testFindNamespacesByPage () throws GitLabApiException {
102
98
List <Namespace > namespaces = gitLabApi .getNamespaceApi ().findNamespaces (TEST_NAMESPACE , 1 , 10 );
103
99
assertNotNull (namespaces );
104
- assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getName ());
100
+ assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getPath ());
105
101
}
106
102
107
103
@ Test
108
104
public void testFindNamespacesViaPager () throws GitLabApiException {
109
105
Pager <Namespace > pager = gitLabApi .getNamespaceApi ().findNamespaces (TEST_NAMESPACE , 10 );
110
106
assertNotNull (pager );
111
- assertEquals (TEST_NAMESPACE , pager .next ().get (0 ).getName ());
107
+ assertEquals (TEST_NAMESPACE , pager .next ().get (0 ).getPath ());
112
108
}
113
109
}
0 commit comments