Skip to content

Commit

Permalink
#1252 unit tests for GithubRepo.enableIssues()
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 16, 2021
1 parent a357cf4 commit 2b6e026
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
* @todo #1248:60min Write some integration tests using MkGrizzly server for
* method enableIssues().
*/
final class GithubRepo extends BaseRepo {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.selfxdsd.core.mock.MockJsonResources;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -282,4 +283,92 @@ public void throwsRepoAlreadyActiveExceptionIfActive(){

repo.activate();
}

/**
* GithubRepo can enable its Issues.
*/
@Test
public void canEnableIssues() {
final JsonResources res = new MockJsonResources(request -> {
MatcherAssert.assertThat(
request.getUri(),
Matchers.equalTo(URI.create("/repos/mihai/testrepo"))
);
MatcherAssert.assertThat(
request.getMethod(),
Matchers.equalTo("PATCH")
);
MatcherAssert.assertThat(
request.getBody(),
Matchers.equalTo(
Json.createObjectBuilder()
.add("has_issues", true)
.build()
)
);
return new MockJsonResources.MockResource(
200,
Json.createObjectBuilder().build()
);
});
final Repo repo = new GithubRepo(
res,
URI.create("/repos/mihai/testrepo"),
Mockito.mock(User.class),
Mockito.mock(Storage.class)
);
MatcherAssert.assertThat(
repo.enableIssues(),
Matchers.instanceOf(Issues.class)
);
}

/**
* GithubRepo throws IllegalStateException if enableIssues returns status
* != 200 OK.
*/
@Test
public void throwsIllegalStateExceptionIfEnableIssueNotOk() {
final JsonResources res = new MockJsonResources(request -> {
MatcherAssert.assertThat(
request.getUri(),
Matchers.equalTo(URI.create("/repos/mihai/testrepo"))
);
MatcherAssert.assertThat(
request.getMethod(),
Matchers.equalTo("PATCH")
);
MatcherAssert.assertThat(
request.getBody(),
Matchers.equalTo(
Json.createObjectBuilder()
.add("has_issues", true)
.build()
)
);
return new MockJsonResources.MockResource(
410,
Json.createObjectBuilder().build()
);
});
final Repo repo = new GithubRepo(
res,
URI.create("/repos/mihai/testrepo"),
Mockito.mock(User.class),
Mockito.mock(Storage.class)
);
try {
repo.enableIssues();
Assert.fail("IllegalStateException was expected.");
} catch (final IllegalStateException ex) {
MatcherAssert.assertThat(
ex.getMessage(),
Matchers.equalTo(
"Could not enable Issues for Repo "
+ "[/repos/mihai/testrepo]. Received Status is 410, "
+ "while Status 200 OK was expected."
)
);
}
}
}

1 comment on commit 2b6e026

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

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

@amihaiemil I've closed the Issues [#1252] 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.