22
33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertNotNull ;
5+ import static org .junit .Assert .assertTrue ;
56import static org .junit .Assert .fail ;
67import static org .junit .Assume .assumeNotNull ;
78
89import java .util .List ;
10+ import java .util .Optional ;
911
1012import org .gitlab4j .api .models .Namespace ;
1113import org .junit .Before ;
@@ -47,12 +49,9 @@ public void beforeMethod() {
4749 public void testGetNamespaces () throws GitLabApiException {
4850 List <Namespace > namespaces = gitLabApi .getNamespaceApi ().getNamespaces ();
4951 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 ());
5655 }
5756
5857 @ Test
@@ -63,7 +62,7 @@ public void testGetNamespacesViaPager() throws GitLabApiException {
6362 while (pager .hasNext ()) {
6463 List <Namespace > namespaces = pager .next ();
6564 for (Namespace namespace : namespaces ) {
66- if (TEST_NAMESPACE .equals (namespace .getName ()))
65+ if (TEST_NAMESPACE .equals (namespace .getPath ()))
6766 return ;
6867 }
6968 }
@@ -75,39 +74,36 @@ public void testGetNamespacesViaPager() throws GitLabApiException {
7574 public void testGetNamespacesByPage () throws GitLabApiException {
7675 List <Namespace > namespaces = gitLabApi .getNamespaceApi ().getNamespaces (1 , 10 );
7776 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 ());
8480 }
8581
8682 @ Test
8783 public void testFindNamespaces () throws GitLabApiException {
8884 List <Namespace > namespaces = gitLabApi .getNamespaceApi ().findNamespaces (TEST_NAMESPACE );
8985 assertNotNull (namespaces );
90- assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getName ());
86+ assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getPath ());
9187 }
9288
9389 @ Test
9490 public void testFindSubgroupNamespaces () throws GitLabApiException {
9591 List <Namespace > namespaces = gitLabApi .getNamespaceApi ().findNamespaces (TEST_SUB_GROUP );
9692 assertNotNull (namespaces );
97- assertEquals (TEST_SUB_GROUP , namespaces .get (0 ).getName ());
93+ assertEquals (TEST_SUB_GROUP , namespaces .get (0 ).getPath ());
9894 }
9995
10096 @ Test
10197 public void testFindNamespacesByPage () throws GitLabApiException {
10298 List <Namespace > namespaces = gitLabApi .getNamespaceApi ().findNamespaces (TEST_NAMESPACE , 1 , 10 );
10399 assertNotNull (namespaces );
104- assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getName ());
100+ assertEquals (TEST_NAMESPACE , namespaces .get (0 ).getPath ());
105101 }
106102
107103 @ Test
108104 public void testFindNamespacesViaPager () throws GitLabApiException {
109105 Pager <Namespace > pager = gitLabApi .getNamespaceApi ().findNamespaces (TEST_NAMESPACE , 10 );
110106 assertNotNull (pager );
111- assertEquals (TEST_NAMESPACE , pager .next ().get (0 ).getName ());
107+ assertEquals (TEST_NAMESPACE , pager .next ().get (0 ).getPath ());
112108 }
113109}
0 commit comments