Skip to content

Commit

Permalink
#859 add tests for GitlabCollaborators.iterator()
Browse files Browse the repository at this point in the history
  • Loading branch information
alilosoft committed Jan 7, 2021
1 parent 70a9927 commit 7ec32b5
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import org.mockito.Mockito;

import javax.json.Json;
import javax.json.JsonObject;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URI;

/**
* Unit tests for {@link GitlabCollaborators}.
Expand Down Expand Up @@ -289,4 +292,69 @@ public void removesUserNotFound() {
);
}

/**
* GitlabCollaborators can iterate over repo collaborators.
*/
@Test
public void canIterateOverCollaborators(){
final GitlabCollaborators collaborators = new GitlabCollaborators(
new MockJsonResources(req -> {
MatcherAssert.assertThat(
req.getUri().toString(),
Matchers.equalTo("../projects/id/members")
);
MatcherAssert.assertThat(
req.getMethod(),
Matchers.equalTo("GET")
);
return new MockJsonResources.MockResource(
HttpURLConnection.HTTP_OK,
Json.createReader(
new StringReader(
"[ {\"id\" : \"1\"}, {\"id\" : \"2\"} ]"
)
).readArray()
);
}),
URI.create("../projects/id/members"),
Mockito.mock(Storage.class)
);
MatcherAssert.assertThat(
collaborators,
Matchers.iterableWithSize(2)
);
MatcherAssert.assertThat(
collaborators.iterator().next(),
Matchers.instanceOf(GitlabCollaborator.class)
);
}

/**
* GitlabCollaborators can iterate over repo collaborators.
*/
@Test
public void emptyCollaborators(){
final GitlabCollaborators collaborators = new GitlabCollaborators(
new MockJsonResources(req -> {
MatcherAssert.assertThat(
req.getUri().toString(),
Matchers.equalTo("../projects/id/members")
);
MatcherAssert.assertThat(
req.getMethod(),
Matchers.equalTo("GET")
);
return new MockJsonResources.MockResource(
HttpURLConnection.HTTP_INTERNAL_ERROR,
JsonObject.NULL
);
}),
URI.create("../projects/id/members"),
Mockito.mock(Storage.class)
);
MatcherAssert.assertThat(
collaborators,
Matchers.emptyIterable()
);
}
}

2 comments on commit 7ec32b5

@charlesmike
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fellahi-ali I've opened the Issues [#865, #866, #867, #868, #869, #870, #871, #873, #875, #877, #879, #881, #883] for the newly added to-dos.

The to-dos may have been added in an earlier commit, but I've found them just now.

@charlesmike
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fellahi-ali I've closed the Issues [#861, #859, #828, #692, #684, #682, #680, #679, #555, #504, #465] since their to-dos disappeared from the code.

The to-dos may have been removed in an earlier commit, but I've found it just now.

Please sign in to comment.