-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#984 BitbucketOrganizationRepos impl & test
- Loading branch information
Showing
2 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
self-core-impl/src/test/java/com/selfxdsd/core/BitbucketOrganizationReposTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.selfxdsd.core; | ||
|
||
import com.selfxdsd.api.Repos; | ||
import com.selfxdsd.api.User; | ||
import com.selfxdsd.api.storage.Storage; | ||
import com.selfxdsd.core.mock.MockJsonResources; | ||
import com.selfxdsd.core.mock.MockJsonResources.MockResource; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonValue; | ||
import java.net.HttpURLConnection; | ||
import java.net.URI; | ||
|
||
/** | ||
* Unit tests for {@link BitbucketOrganizationRepos}. | ||
* | ||
* @author Ali FELLAHI (fellahi.ali@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.68 | ||
*/ | ||
public final class BitbucketOrganizationReposTestCase { | ||
|
||
/** | ||
* Can fetches organization repos. | ||
*/ | ||
@Test | ||
public void fetchOk() { | ||
final JsonResources resources = new MockJsonResources( | ||
req -> { | ||
MatcherAssert.assertThat( | ||
req.getMethod(), | ||
Matchers.is("GET") | ||
); | ||
MatcherAssert.assertThat( | ||
req.getUri().toString(), | ||
Matchers.equalTo( | ||
"https://bitbucket.org/api/2.0/repositories/alilosoft" | ||
) | ||
); | ||
return new MockResource( | ||
HttpURLConnection.HTTP_OK, | ||
Json.createObjectBuilder().add( | ||
"values", | ||
Json.createArrayBuilder() | ||
.add(Json.createObjectBuilder() | ||
.add("slug", "repo1") | ||
.build()) | ||
.add(Json.createObjectBuilder() | ||
.add("slug", "repo2") | ||
.build()) | ||
.add(Json.createObjectBuilder() | ||
.add("slug", "repo3") | ||
.build()) | ||
.build() | ||
).build() | ||
); | ||
} | ||
); | ||
final Repos repos = new BitbucketOrganizationRepos( | ||
URI.create("https://bitbucket.org/api/2.0/repositories/alilosoft"), | ||
Mockito.mock(User.class), | ||
resources, | ||
Mockito.mock(Storage.class) | ||
); | ||
MatcherAssert.assertThat(repos, Matchers.iterableWithSize(3)); | ||
} | ||
|
||
/** | ||
* Throw if organization repos are not fetched. | ||
*/ | ||
@Test(expected = IllegalStateException.class) | ||
public void fetchNotOk() { | ||
final JsonResources resources = new MockJsonResources( | ||
req -> new MockResource(404, JsonValue.NULL) | ||
); | ||
new BitbucketOrganizationRepos( | ||
URI.create("bad/uri"), | ||
Mockito.mock(User.class), | ||
resources, | ||
Mockito.mock(Storage.class) | ||
).iterator(); | ||
} | ||
|
||
} |