Deprecate all asserts other than assertThat

This commit is contained in:
Liam Newman
2021-04-19 19:09:47 -07:00
parent bd38897d48
commit 3d451526ef
41 changed files with 944 additions and 896 deletions

View File

@@ -271,60 +271,74 @@ public abstract class AbstractGitHubWireMockTest {
MatcherAssert.assertThat(reason, assertion);
}
@Deprecated
public static void assertEquals(Object expected, Object actual) {
assertThat(actual, equalTo(expected));
fail("In this project we use 'assertThat(actual, equalTo(expected))");
}
@Deprecated
public static void assertEquals(String reason, Object expected, Object actual) {
assertThat(reason, actual, equalTo(expected));
fail("In this project we use 'assertThat(reason, actual, equalTo(expected))");
}
@Deprecated
public static void assertNotEquals(Object expected, Object actual) {
assertThat(actual, not(expected));
fail("In this project we use 'assertThat(actual, not(expected))");
}
@Deprecated
public static void assertNotEquals(String reason, Object expected, Object actual) {
assertThat(reason, actual, not(expected));
fail("In this project we use 'assertThat(reason, actual, not(expected))");
}
@Deprecated
public static void assertNotNull(Object actual) {
assertThat(actual, notNullValue());
fail("In this project we use 'assertThat(actual, notNullValue())");
}
@Deprecated
public static void assertNotNull(String reason, Object actual) {
assertThat(reason, actual, notNullValue());
fail("In this project we use 'assertThat(reason, actual, notNullValue())");
}
@Deprecated
public static void assertNull(Object actual) {
assertThat(actual, nullValue());
fail("In this project we use 'assertThat(actual, nullValue())");
}
public static void assertNull(String message, Object actual) {
assertThat(message, actual, nullValue());
@Deprecated
public static void assertNull(String reason, Object actual) {
fail("In this project we use 'assertThat(reason, actual, nullValue())");
}
@Deprecated
public static void assertSame(Object expected, Object actual) {
assertThat(actual, sameInstance(expected));
fail("In this project we use 'assertThat(actual, sameInstance(expected))");
}
public static void assertSame(String message, Object expected, Object actual) {
Assert.assertSame(message, expected, actual);
@Deprecated
public static void assertSame(String reason, Object expected, Object actual) {
fail("In this project we use 'assertThat(reason, actual, sameInstance(expected))");
}
@Deprecated
public static void assertTrue(Boolean condition) {
assertThat(condition, is(true));
fail("In this project we use 'assertThat(condition, is(true)) or more appropirate matchers");
}
@Deprecated
public static void assertTrue(String reason, Boolean condition) {
assertThat(reason, condition, is(true));
fail("In this project we use 'assertThat(reason, condition, is(true)) or more appropirate matchers");
}
@Deprecated
public static void assertFalse(Boolean condition) {
assertThat(condition, is(false));
fail("In this project we use 'assertThat(condition, is(true)) or more appropirate matchers");
}
@Deprecated
public static void assertFalse(String reason, Boolean condition) {
assertThat(reason, condition, is(false));
fail("In this project we use 'assertThat(reason, condition, is(false)) or more appropirate matchers");
}
protected static class TemplatingHelper {

View File

@@ -84,7 +84,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
if (mockGitHub.isUseProxy()) {
Thread.sleep(3000);
}
assertNotNull(r.getReadme());
assertThat(r.getReadme(), notNullValue());
r.delete();
}
@@ -97,7 +97,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testCredentialValid() throws IOException {
assertTrue(gitHub.isCredentialValid());
assertThat(gitHub.isCredentialValid(), is(true));
assertThat(gitHub.lastRateLimit().getCore(), not(instanceOf(GHRateLimit.UnknownLimitRecord.class)));
assertThat(gitHub.lastRateLimit().getCore().getLimit(), equalTo(5000));
@@ -105,7 +105,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
.withEndpoint(mockGitHub.apiServer().baseUrl())
.build();
assertThat(gitHub.lastRateLimit(), sameInstance(GHRateLimit.DEFAULT));
assertFalse(gitHub.isCredentialValid());
assertThat(gitHub.isCredentialValid(), is(false));
// For invalid credentials, we get a 401 but it includes anonymous rate limit headers
assertThat(gitHub.lastRateLimit().getCore(), not(instanceOf(GHRateLimit.UnknownLimitRecord.class)));
assertThat(gitHub.lastRateLimit().getCore().getLimit(), equalTo(60));
@@ -116,7 +116,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
// Simulated GHE: getRateLimit returns 404
assertThat(gitHub.lastRateLimit(), sameInstance(GHRateLimit.DEFAULT));
assertThat(gitHub.lastRateLimit().getCore().isExpired(), is(true));
assertTrue(gitHub.isCredentialValid());
assertThat(gitHub.isCredentialValid(), is(true));
// lastRateLimitUpdates because 404 still includes header rate limit info
assertThat(gitHub.lastRateLimit(), notNullValue());
@@ -127,7 +127,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
.withEndpoint(mockGitHub.apiServer().baseUrl())
.build();
assertThat(gitHub.lastRateLimit(), sameInstance(GHRateLimit.DEFAULT));
assertFalse(gitHub.isCredentialValid());
assertThat(gitHub.isCredentialValid(), is(false));
// Simulated GHE: For invalid credentials, we get a 401 that does not include ratelimit info
assertThat(gitHub.lastRateLimit(), sameInstance(GHRateLimit.DEFAULT));
}
@@ -138,7 +138,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHIssue i = repository.getIssue(4);
List<GHIssueComment> v = i.getComments();
// System.out.println(v);
assertTrue(v.isEmpty());
assertThat(v.isEmpty(), is(true));
i = repository.getIssue(3);
v = i.getComments();
@@ -179,7 +179,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
.label("question")
.milestone(milestone)
.create();
assertNotNull(o);
assertThat(o, notNullValue());
o.close();
}
@@ -192,17 +192,17 @@ public class AppTest extends AbstractGitHubWireMockTest {
.environment("unittest")
.create();
try {
assertNotNull(deployment.getCreator());
assertNotNull(deployment.getId());
assertThat(deployment.getCreator(), notNullValue());
assertThat(deployment.getId(), notNullValue());
List<GHDeployment> deployments = repository.listDeployments(null, "main", null, "unittest").toList();
assertNotNull(deployments);
assertFalse(Iterables.isEmpty(deployments));
assertThat(deployments, notNullValue());
assertThat(Iterables.isEmpty(deployments), is(false));
GHDeployment unitTestDeployment = deployments.get(0);
assertEquals("unittest", unitTestDeployment.getEnvironment());
assertEquals("unittest", unitTestDeployment.getOriginalEnvironment());
assertEquals(false, unitTestDeployment.isProductionEnvironment());
assertEquals(false, unitTestDeployment.isTransientEnvironment());
assertEquals("main", unitTestDeployment.getRef());
assertThat(unitTestDeployment.getEnvironment(), equalTo("unittest"));
assertThat(unitTestDeployment.getOriginalEnvironment(), equalTo("unittest"));
assertThat(unitTestDeployment.isProductionEnvironment(), equalTo(false));
assertThat(unitTestDeployment.isTransientEnvironment(), equalTo(false));
assertThat(unitTestDeployment.getRef(), equalTo("main"));
} finally {
// deployment.delete();
assert true;
@@ -225,15 +225,15 @@ public class AppTest extends AbstractGitHubWireMockTest {
.environment("new-ci-env")
.create();
Iterable<GHDeploymentStatus> deploymentStatuses = deployment.listStatuses();
assertNotNull(deploymentStatuses);
assertEquals(1, Iterables.size(deploymentStatuses));
assertThat(deploymentStatuses, notNullValue());
assertThat(Iterables.size(deploymentStatuses), equalTo(1));
GHDeploymentStatus actualStatus = Iterables.get(deploymentStatuses, 0);
assertEquals(ghDeploymentStatus.getId(), actualStatus.getId());
assertEquals(ghDeploymentStatus.getState(), actualStatus.getState());
assertEquals(ghDeploymentStatus.getLogUrl(), actualStatus.getLogUrl());
assertThat(actualStatus.getId(), equalTo(ghDeploymentStatus.getId()));
assertThat(actualStatus.getState(), equalTo(ghDeploymentStatus.getState()));
assertThat(actualStatus.getLogUrl(), equalTo(ghDeploymentStatus.getLogUrl()));
// Target url was deprecated and replaced with log url. The gh api will
// prefer the log url value and return it in place of target url.
assertEquals(ghDeploymentStatus.getTargetUrl(), actualStatus.getLogUrl());
assertThat(actualStatus.getLogUrl(), equalTo(ghDeploymentStatus.getTargetUrl()));
assertThat(ghDeploymentStatus.getDeploymentUrl(), equalTo(deployment.getUrl()));
assertThat(ghDeploymentStatus.getRepositoryUrl(), equalTo(repository.getUrl()));
} finally {
@@ -248,7 +248,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
.getRepository("github-api")
.getIssues(GHIssueState.CLOSED);
// prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues
assertTrue(closedIssues.size() > 150);
assertThat(closedIssues.size() > 150, is(true));
String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(closedIssues.get(0));
}
@@ -264,11 +264,11 @@ public class AppTest extends AbstractGitHubWireMockTest {
int x = 0;
for (GHIssue issue : closedIssues) {
assertNotNull(issue);
assertThat(issue, notNullValue());
x++;
}
assertTrue(x > 150);
assertThat(x > 150, is(true));
}
@Test
@@ -279,7 +279,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testMyOrganizations() throws IOException {
Map<String, GHOrganization> org = gitHub.getMyOrganizations();
assertFalse(org.keySet().contains(null));
assertThat(org.keySet().contains(null), is(false));
// System.out.println(org);
}
@@ -289,7 +289,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
Map<String, GHOrganization> myOrganizations = gitHub.getMyOrganizations();
// GitHub no longer has default 'owners' team, so there may be organization memberships without a team
// https://help.github.com/articles/about-improved-organization-permissions/
assertTrue(myOrganizations.keySet().containsAll(teams.keySet()));
assertThat(myOrganizations.keySet().containsAll(teams.keySet()), is(true));
}
@Test
@@ -299,8 +299,9 @@ public class AppTest extends AbstractGitHubWireMockTest {
String organizationName = teamsPerOrg.getKey();
for (GHTeam team : teamsPerOrg.getValue()) {
String teamName = team.getName();
assertTrue("Team " + teamName + " in organization " + organizationName + " does not contain myself",
shouldBelongToTeam(organizationName, teamName));
assertThat("Team " + teamName + " in organization " + organizationName + " does not contain myself",
shouldBelongToTeam(organizationName, teamName),
is(true));
}
}
}
@@ -312,7 +313,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
user.login = "kohsuke";
Map<String, GHOrganization> orgs = gitHub.getUserPublicOrganizations(user);
assertFalse(orgs.isEmpty());
assertThat(orgs.isEmpty(), is(false));
}
@Test
@@ -322,14 +323,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
user.login = "bitwiseman";
Map<String, GHOrganization> orgs = gitHub.getUserPublicOrganizations(user);
assertTrue(orgs.isEmpty());
assertThat(orgs.isEmpty(), is(true));
}
private boolean shouldBelongToTeam(String organizationName, String teamName) throws IOException {
GHOrganization org = gitHub.getOrganization(organizationName);
assertNotNull(org);
assertThat(org, notNullValue());
GHTeam team = org.getTeamByName(teamName);
assertNotNull(team);
assertThat(team, notNullValue());
return team.hasMember(gitHub.getMyself());
}
@@ -339,10 +340,10 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHTeam teamByName = organization.getTeams().get("Core Developers");
GHTeam teamById = gitHub.getTeam((int) teamByName.getId());
assertNotNull(teamById);
assertThat(teamById, notNullValue());
assertEquals(teamByName.getId(), teamById.getId());
assertEquals(teamByName.getDescription(), teamById.getDescription());
assertThat(teamById.getId(), equalTo(teamByName.getId()));
assertThat(teamById.getDescription(), equalTo(teamByName.getDescription()));
}
@Test
@@ -351,16 +352,16 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHTeam teamByName = organization.getTeams().get("Core Developers");
GHTeam teamById = organization.getTeam(teamByName.getId());
assertNotNull(teamById);
assertThat(teamById, notNullValue());
assertEquals(teamByName.getId(), teamById.getId());
assertEquals(teamByName.getDescription(), teamById.getDescription());
assertThat(teamById.getId(), equalTo(teamByName.getId()));
assertThat(teamById.getDescription(), equalTo(teamByName.getDescription()));
GHTeam teamById2 = organization.getTeam(teamByName.getId());
assertNotNull(teamById2);
assertThat(teamById2, notNullValue());
assertEquals(teamByName.getId(), teamById2.getId());
assertEquals(teamByName.getDescription(), teamById2.getDescription());
assertThat(teamById2.getId(), equalTo(teamByName.getId()));
assertThat(teamById2.getDescription(), equalTo(teamByName.getDescription()));
}
@@ -368,8 +369,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testFetchPullRequest() throws Exception {
GHRepository r = gitHub.getOrganization("jenkinsci").getRepository("jenkins");
assertEquals("main", r.getMasterBranch());
assertEquals("main", r.getDefaultBranch());
assertThat(r.getMasterBranch(), equalTo("main"));
assertThat(r.getDefaultBranch(), equalTo("main"));
r.getPullRequest(1);
r.getPullRequests(GHIssueState.OPEN);
}
@@ -378,11 +379,11 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testFetchPullRequestAsList() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
assertEquals("main", r.getMasterBranch());
assertThat(r.getMasterBranch(), equalTo("main"));
PagedIterable<GHPullRequest> i = r.listPullRequests(GHIssueState.CLOSED);
List<GHPullRequest> prs = i.toList();
assertNotNull(prs);
assertTrue(prs.size() > 0);
assertThat(prs, notNullValue());
assertThat(prs.size() > 0, is(true));
}
@Ignore("Needs mocking check")
@@ -391,26 +392,26 @@ public class AppTest extends AbstractGitHubWireMockTest {
kohsuke();
GHRepository r = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
assertTrue(r.hasPullAccess());
assertThat(r.hasPullAccess(), is(true));
r = gitHub.getOrganization("github").getRepository("hub");
assertFalse(r.hasAdminAccess());
assertThat(r.hasAdminAccess(), is(false));
}
@Test
public void testGetMyself() throws Exception {
GHMyself me = gitHub.getMyself();
assertNotNull(me);
assertNotNull(gitHub.getUser("bitwiseman"));
assertThat(me, notNullValue());
assertThat(gitHub.getUser("bitwiseman"), notNullValue());
PagedIterable<GHRepository> ghRepositories = me.listRepositories();
assertTrue(ghRepositories.iterator().hasNext());
assertThat(ghRepositories.iterator().hasNext(), is(true));
}
@Ignore("Needs mocking check")
@Test
public void testPublicKeys() throws Exception {
List<GHKey> keys = gitHub.getMyself().getPublicKeys();
assertFalse(keys.isEmpty());
assertThat(keys.isEmpty(), is(false));
}
@Test
@@ -423,8 +424,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
public void testGetTeamsForRepo() throws Exception {
kohsuke();
// 'Core Developers' and 'Owners'
assertEquals(2,
gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("testGetTeamsForRepo").getTeams().size());
assertThat(gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("testGetTeamsForRepo").getTeams().size(),
equalTo(2));
}
@Test
@@ -446,24 +447,24 @@ public class AppTest extends AbstractGitHubWireMockTest {
kohsuke();
int sz = 0;
for (GHTeam t : gitHub.getOrganization(GITHUB_API_TEST_ORG).listTeams()) {
assertNotNull(t.getName());
assertThat(t.getName(), notNullValue());
sz++;
}
assertTrue(sz < 100);
assertThat(sz < 100, is(true));
}
@Test
public void testOrgTeamByName() throws Exception {
kohsuke();
GHTeam e = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamByName("Core Developers");
assertNotNull(e);
assertThat(e, notNullValue());
}
@Test
public void testOrgTeamBySlug() throws Exception {
kohsuke();
GHTeam e = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug("core-developers");
assertNotNull(e);
assertThat(e, notNullValue());
}
@Test
@@ -471,13 +472,13 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHCommit commit = gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.getCommit("08c1c9970af4d609ae754fbe803e06186e3206f7");
assertEquals(1, commit.getParents().size());
assertEquals(1, commit.getFiles().size());
assertEquals("https://github.com/jenkinsci/jenkins/commit/08c1c9970af4d609ae754fbe803e06186e3206f7",
commit.getHtmlUrl().toString());
assertThat(commit.getParents().size(), equalTo(1));
assertThat(commit.getFiles().size(), equalTo(1));
assertThat(commit.getHtmlUrl().toString(),
equalTo("https://github.com/jenkinsci/jenkins/commit/08c1c9970af4d609ae754fbe803e06186e3206f7"));
File f = commit.getFiles().get(0);
assertEquals(48, f.getLinesChanged());
assertThat(f.getLinesChanged(), equalTo(48));
assertThat(f.getLinesAdded(), equalTo(40));
assertThat(f.getLinesDeleted(), equalTo(8));
assertThat(f.getPreviousFilename(), nullValue());
@@ -488,13 +489,13 @@ public class AppTest extends AbstractGitHubWireMockTest {
assertThat(f.getRawUrl().toString(),
equalTo("https://github.com/jenkinsci/jenkins/raw/08c1c9970af4d609ae754fbe803e06186e3206f7/changelog.html"));
assertEquals("modified", f.getStatus());
assertEquals("changelog.html", f.getFileName());
assertThat(f.getStatus(), equalTo("modified"));
assertThat(f.getFileName(), equalTo("changelog.html"));
// walk the tree
GHTree t = commit.getTree();
assertThat(IOUtils.toString(t.getEntry("todo.txt").readAsBlob()), containsString("executor rendering"));
assertNotNull(t.getEntry("war").asTree());
assertThat(t.getEntry("war").asTree(), notNullValue());
}
@Test
@@ -503,8 +504,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
for (GHCommit c : gitHub.getUser("kohsuke").getRepository("empty-commit").listCommits()) {
sha1.add(c.getSHA1());
}
assertEquals("fdfad6be4db6f96faea1f153fb447b479a7a9cb7", sha1.get(0));
assertEquals(1, sha1.size());
assertThat(sha1.get(0), equalTo("fdfad6be4db6f96faea1f153fb447b479a7a9cb7"));
assertThat(sha1.size(), equalTo(1));
}
@Ignore("Needs mocking check")
@@ -521,7 +522,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
List<GHCommitComment> batch = comments.iterator().nextPage();
for (GHCommitComment comment : batch) {
// System.out.println(comment.getBody());
assertSame(comment.getOwner(), r);
assertThat(r, sameInstance(comment.getOwner()));
}
}
@@ -720,7 +721,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHOrganization j = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam t = j.getTeams().get("Core Developers");
assertNotNull(j.getRepository("jenkins"));
assertThat(j.getRepository("jenkins"), notNullValue());
// t.add(labs.getRepository("xyz"));
}
@@ -737,18 +738,18 @@ public class AppTest extends AbstractGitHubWireMockTest {
List<GHCommitStatus> lst = r.listCommitStatuses("ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396").toList();
state = lst.get(0);
// System.out.println(state);
assertEquals("testing!", state.getDescription());
assertEquals("http://kohsuke.org/", state.getTargetUrl());
assertThat(state.getDescription(), equalTo("testing!"));
assertThat(state.getTargetUrl(), equalTo("http://kohsuke.org/"));
}
@Test
public void testCommitShortInfo() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f23");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Kohsuke Kawaguchi");
assertEquals(commit.getCommitShortInfo().getMessage(), "doc");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.UNSIGNED);
assertThat("Kohsuke Kawaguchi", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat("doc", equalTo(commit.getCommitShortInfo().getMessage()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.UNSIGNED, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
assertThat(commit.getCommitShortInfo().getAuthor().getDate().toInstant().getEpochSecond(),
equalTo(1271650361L));
assertThat(commit.getCommitShortInfo().getCommitter().getDate().toInstant().getEpochSecond(),
@@ -761,7 +762,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHRepository r = gitHub.getUser("kohsuke").getRepository("github-api");
GHPullRequest p = r.getPullRequest(17);
GHUser u = p.getUser();
assertNotNull(u.getName());
assertThat(u.getName(), notNullValue());
}
@Test
@@ -771,11 +772,11 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHUser kohsuke = gitHub.getUser("kohsuke");
GHUser b = gitHub.getUser("b");
assertTrue(j.hasMember(kohsuke));
assertFalse(j.hasMember(b));
assertThat(j.hasMember(kohsuke), is(true));
assertThat(j.hasMember(b), is(false));
assertTrue(j.hasPublicMember(kohsuke));
assertFalse(j.hasPublicMember(b));
assertThat(j.hasPublicMember(kohsuke), is(true));
assertThat(j.hasPublicMember(b), is(false));
}
@Ignore("Needs mocking check")
@@ -798,7 +799,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
if (tagName.equals(tag.getName())) {
String ash = tag.getCommit().getSHA1();
GHRef ref = r.createRef("refs/heads/" + releaseName, ash);
assertEquals(ref.getRef(), "refs/heads/" + releaseName);
assertThat(("refs/heads/" + releaseName), equalTo(ref.getRef()));
for (Map.Entry<String, GHBranch> entry : r.getBranches().entrySet()) {
// System.out.println(entry.getKey() + "/" + entry.getValue());
@@ -818,8 +819,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testRef() throws IOException {
GHRef mainRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/main");
assertEquals(mockGitHub.apiServer().baseUrl() + "/repos/jenkinsci/jenkins/git/refs/heads/main",
mainRef.getUrl().toString());
assertThat(mainRef.getUrl().toString(),
equalTo(mockGitHub.apiServer().baseUrl() + "/repos/jenkinsci/jenkins/git/refs/heads/main"));
}
@Test
@@ -842,14 +843,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
final GHDeployKey newDeployKey = myRepository.addDeployKey("test",
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUt0RAycC5cS42JKh6SecfFZBR1RrF+2hYMctz4mk74/arBE+wFb7fnSHGzdGKX2h5CFOWODifRCJVhB7hlVxodxe+QkQQYAEL/x1WVCJnGgTGQGOrhOMj95V3UE5pQKhsKD608C+u5tSofcWXLToP1/wZ7U4/AHjqYi08OLsWToHCax55TZkvdt2jo0hbIoYU+XI9Q8Uv4ONDN1oabiOdgeKi8+crvHAuvNleiBhWVBzFh8KdfzaH5uNdw7ihhFjEd1vzqACsjCINCjdMfzl6jD9ExuWuE92nZJnucls2cEoNC6k2aPmrZDg9hA32FXVpyseY+bDUWFU6LO2LG6PB kohsuke@atlas");
try {
assertNotNull(newDeployKey.getId());
assertThat(newDeployKey.getId(), notNullValue());
GHDeployKey k = Iterables.find(myRepository.getDeployKeys(), new Predicate<GHDeployKey>() {
public boolean apply(GHDeployKey deployKey) {
return newDeployKey.getId() == deployKey.getId();
}
});
assertNotNull(k);
assertThat(k, notNullValue());
} finally {
newDeployKey.delete();
}
@@ -862,7 +863,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHRef mainRef = myRepository.getRef("heads/main");
GHCommitStatus commitStatus = myRepository.createCommitStatus(mainRef.getObject()
.getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
assertEquals("test/context", commitStatus.getContext());
assertThat(commitStatus.getContext(), equalTo("test/context"));
}
@@ -874,7 +875,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
// System.out.println(u.getLogin());
all.add(u);
}
assertFalse(all.isEmpty());
assertThat(all.isEmpty(), is(false));
}
@Test
@@ -885,10 +886,10 @@ public class AppTest extends AbstractGitHubWireMockTest {
.author("kohsuke")
.sort(GHCommitSearchBuilder.Sort.COMMITTER_DATE)
.list();
assertTrue(r.getTotalCount() > 0);
assertThat(r.getTotalCount() > 0, is(true));
GHCommit firstCommit = r.iterator().next();
assertTrue(firstCommit.getFiles().size() > 0);
assertThat(firstCommit.getFiles().size() > 0, is(true));
}
@Test
@@ -898,7 +899,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
.isOpen()
.sort(GHIssueSearchBuilder.Sort.UPDATED)
.list();
assertTrue(r.getTotalCount() > 0);
assertThat(r.getTotalCount() > 0, is(true));
for (GHIssue issue : r) {
assertThat(issue.getTitle(), notNullValue());
PagedIterable<GHIssueComment> comments = issue.listComments();
@@ -911,8 +912,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test // issue #99
public void testReadme() throws IOException {
GHContent readme = gitHub.getRepository("hub4j-test-org/test-readme").getReadme();
assertEquals(readme.getName(), "README.md");
assertEquals(readme.getContent(), "This is a markdown readme.\n");
assertThat("README.md", equalTo(readme.getName()));
assertThat("This is a markdown readme.\n", equalTo(readme.getContent()));
}
@Ignore("Needs mocking check")
@@ -926,7 +927,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
break;
}
}
assertTrue(foundReadme);
assertThat(foundReadme, is(true));
}
@Test
@@ -949,7 +950,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
}
}
assertTrue(foundThisFile);
assertThat(foundThisFile, is(true));
}
@Test
@@ -962,14 +963,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
for (GHLabel l : lst) {
assertThat(l.getUrl(), containsString(l.getName().replace(" ", "%20")));
}
assertTrue(lst.size() > 5);
assertThat(lst.size() > 5, is(true));
GHLabel e = r.getLabel("enhancement");
assertEquals("enhancement", e.getName());
assertNotNull(e.getUrl());
assertEquals(177339106L, e.getId());
assertEquals("MDU6TGFiZWwxNzczMzkxMDY=", e.getNodeId());
assertTrue(e.isDefault());
assertTrue(Pattern.matches("[0-9a-fA-F]{6}", e.getColor()));
assertThat(e.getName(), equalTo("enhancement"));
assertThat(e.getUrl(), notNullValue());
assertThat(e.getId(), equalTo(177339106L));
assertThat(e.getNodeId(), equalTo("MDU6TGFiZWwxNzczMzkxMDY="));
assertThat(e.isDefault(), is(true));
assertThat(Pattern.matches("[0-9a-fA-F]{6}", e.getColor()), is(true));
GHLabel t = null;
GHLabel t2 = null;
@@ -980,17 +981,17 @@ public class AppTest extends AbstractGitHubWireMockTest {
assertThat(t, not(sameInstance(t2)));
assertThat(t, equalTo(t2));
assertFalse(t2.isDefault());
assertThat(t2.isDefault(), is(false));
assertEquals(t.getId(), t2.getId());
assertEquals(t.getNodeId(), t2.getNodeId());
assertEquals(t.getName(), t2.getName());
assertEquals(t.getColor(), "123456");
assertEquals(t.getColor(), t2.getColor());
assertEquals(t.getDescription(), "");
assertEquals(t.getDescription(), t2.getDescription());
assertEquals(t.getUrl(), t2.getUrl());
assertEquals(t.isDefault(), t2.isDefault());
assertThat(t2.getId(), equalTo(t.getId()));
assertThat(t2.getNodeId(), equalTo(t.getNodeId()));
assertThat(t2.getName(), equalTo(t.getName()));
assertThat("123456", equalTo(t.getColor()));
assertThat(t2.getColor(), equalTo(t.getColor()));
assertThat("", equalTo(t.getDescription()));
assertThat(t2.getDescription(), equalTo(t.getDescription()));
assertThat(t2.getUrl(), equalTo(t.getUrl()));
assertThat(t2.isDefault(), equalTo(t.isDefault()));
// update works on multiple changes in one call
t3 = t.update().color("000000").description("It is dark!").done();
@@ -1002,10 +1003,10 @@ public class AppTest extends AbstractGitHubWireMockTest {
assertThat(t, not(sameInstance(t3)));
assertThat(t, not(equalTo(t3)));
assertEquals(t.getColor(), "123456");
assertEquals(t.getDescription(), "");
assertEquals(t3.getColor(), "000000");
assertEquals(t3.getDescription(), "It is dark!");
assertThat("123456", equalTo(t.getColor()));
assertThat("", equalTo(t.getDescription()));
assertThat("000000", equalTo(t3.getColor()));
assertThat("It is dark!", equalTo(t3.getDescription()));
// Test deprecated methods
t.setDescription("Deprecated");
@@ -1013,13 +1014,13 @@ public class AppTest extends AbstractGitHubWireMockTest {
// By using the old instance t when calling setDescription it also sets color to the old value
// this is a bad behavior, but it is expected
assertEquals(t.getColor(), "123456");
assertEquals(t.getDescription(), "Deprecated");
assertThat("123456", equalTo(t.getColor()));
assertThat("Deprecated", equalTo(t.getDescription()));
t.setColor("000000");
t = r.getLabel("test");
assertEquals(t.getColor(), "000000");
assertEquals(t.getDescription(), "Deprecated");
assertThat("000000", equalTo(t.getColor()));
assertThat("Deprecated", equalTo(t.getDescription()));
// set() makes a single change
t3 = t.set().description("this is also a test");
@@ -1028,8 +1029,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
assertThat(t, not(sameInstance(t3)));
assertThat(t, not(equalTo(t3)));
assertEquals(t3.getColor(), "000000");
assertEquals(t3.getDescription(), "this is also a test");
assertThat("000000", equalTo(t3.getColor()));
assertThat("this is also a test", equalTo(t3.getDescription()));
t.delete();
try {
@@ -1042,12 +1043,12 @@ public class AppTest extends AbstractGitHubWireMockTest {
t = r.createLabel("test2", "123457", "this is a different test");
t2 = r.getLabel("test2");
assertEquals(t.getName(), t2.getName());
assertEquals(t.getColor(), "123457");
assertEquals(t.getColor(), t2.getColor());
assertEquals(t.getDescription(), "this is a different test");
assertEquals(t.getDescription(), t2.getDescription());
assertEquals(t.getUrl(), t2.getUrl());
assertThat(t2.getName(), equalTo(t.getName()));
assertThat("123457", equalTo(t.getColor()));
assertThat(t2.getColor(), equalTo(t.getColor()));
assertThat("this is a different test", equalTo(t.getDescription()));
assertThat(t2.getDescription(), equalTo(t.getDescription()));
assertThat(t2.getUrl(), equalTo(t.getUrl()));
t.delete();
// Allow null description
@@ -1079,13 +1080,13 @@ public class AppTest extends AbstractGitHubWireMockTest {
for (GHUser u : mr.listSubscribers()) {
bitwiseman |= u.getLogin().equals("bitwiseman");
}
assertTrue(bitwiseman);
assertThat(bitwiseman, is(true));
boolean githubApiFound = false;
for (GHRepository r : gitHub.getUser("bitwiseman").listRepositories()) {
githubApiFound |= r.equals(mr);
}
assertTrue(githubApiFound);
assertThat(githubApiFound, is(true));
}
@Test
@@ -1116,7 +1117,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
assertThat(t.getCreatedAt(), nullValue());
}
assertTrue(found);
assertThat(found, is(true));
gitHub.listNotifications().markAsRead();
}
@@ -1196,8 +1197,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHMyself me = gitHub.getMyself();
for (GHMembership m : me.listOrgMemberships()) {
assertThat(m.getUser(), is((GHUser) me));
assertNotNull(m.getState());
assertNotNull(m.getRole());
assertThat(m.getState(), notNullValue());
assertThat(m.getRole(), notNullValue());
}
}

View File

@@ -10,6 +10,7 @@ import java.util.Date;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
/**
* @author Kohsuke Kawaguchi
@@ -18,7 +19,7 @@ public class CommitTest extends AbstractGitHubWireMockTest {
@Test // issue 152
public void lastStatus() throws IOException {
GHTag t = gitHub.getRepository("stapler/stapler").listTags().iterator().next();
assertNotNull(t.getCommit().getLastStatus());
assertThat(t.getCommit().getLastStatus(), notNullValue());
}
@Test // issue 230
@@ -27,7 +28,7 @@ public class CommitTest extends AbstractGitHubWireMockTest {
PagedIterable<GHCommit> commits = repo.queryCommits().path("pom.xml").list();
for (GHCommit commit : Iterables.limit(commits, 10)) {
GHCommit expected = repo.getCommit(commit.getSHA1());
assertEquals(expected.getFiles().size(), commit.getFiles().size());
assertThat(commit.getFiles().size(), equalTo(expected.getFiles().size()));
}
}
@@ -129,7 +130,7 @@ public class CommitTest extends AbstractGitHubWireMockTest {
List<GHPullRequest> listedPrs = commit.listPullRequests().toList();
assertEquals(listedPrs.size(), 1);
assertThat(1, equalTo(listedPrs.size()));
assertThat("Pull request " + prNumber + " not found by searching from commit.",
listedPrs.stream().findFirst().filter(it -> it.getNumber() == prNumber).isPresent());
@@ -144,7 +145,7 @@ public class CommitTest extends AbstractGitHubWireMockTest {
List<GHPullRequest> listedPrs = commit.listPullRequests().toList();
assertEquals(listedPrs.size(), 2);
assertThat(2, equalTo(listedPrs.size()));
listedPrs.stream()
.forEach(pr -> assertThat("PR#" + pr.getNumber() + " not expected to be matched.",
@@ -172,9 +173,9 @@ public class CommitTest extends AbstractGitHubWireMockTest {
GHCommit commit = repo.getCommit("ab92e13c0fc844fd51a379a48a3ad0b18231215c");
assertEquals("Commit which was supposed to be HEAD in 2 branches was not found as such.",
2,
commit.listBranchesWhereHead().toList().size());
assertThat("Commit which was supposed to be HEAD in 2 branches was not found as such.",
commit.listBranchesWhereHead().toList().size(),
equalTo(2));
}
@Test
@@ -193,14 +194,14 @@ public class CommitTest extends AbstractGitHubWireMockTest {
PagedIterable<GHCommit> commits = repo.queryCommits().path("pom.xml").list();
for (GHCommit commit : Iterables.limit(commits, 10)) {
GHCommit expected = repo.getCommit(commit.getSHA1());
assertEquals(expected.getCommitShortInfo().getVerification().isVerified(),
commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(expected.getCommitShortInfo().getVerification().getReason(),
commit.getCommitShortInfo().getVerification().getReason());
assertEquals(expected.getCommitShortInfo().getVerification().getSignature(),
commit.getCommitShortInfo().getVerification().getSignature());
assertEquals(expected.getCommitShortInfo().getVerification().getPayload(),
commit.getCommitShortInfo().getVerification().getPayload());
assertThat(commit.getCommitShortInfo().getVerification().isVerified(),
equalTo(expected.getCommitShortInfo().getVerification().isVerified()));
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
equalTo(expected.getCommitShortInfo().getVerification().getReason()));
assertThat(commit.getCommitShortInfo().getVerification().getSignature(),
equalTo(expected.getCommitShortInfo().getVerification().getSignature()));
assertThat(commit.getCommitShortInfo().getVerification().getPayload(),
equalTo(expected.getCommitShortInfo().getVerification().getPayload()));
}
}

View File

@@ -5,6 +5,9 @@ import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
public class GHAppInstallationTest extends AbstractGHAppInstallationTest {
@Test
@@ -13,17 +16,18 @@ public class GHAppInstallationTest extends AbstractGHAppInstallationTest {
List<GHRepository> repositories = appInstallation.listRepositories().toList();
assertEquals(2, repositories.size());
assertTrue(repositories.stream().anyMatch(it -> it.getName().equals("empty")));
assertTrue(repositories.stream().anyMatch(it -> it.getName().equals("test-readme")));
assertThat(repositories.size(), equalTo(2));
assertThat(repositories.stream().anyMatch(it1 -> it1.getName().equals("empty")), is(true));
assertThat(repositories.stream().anyMatch(it -> it.getName().equals("test-readme")), is(true));
}
@Test
public void testListRepositoriesNoPermissions() throws IOException {
GHAppInstallation appInstallation = getAppInstallationWithTokenApp2();
assertTrue("App does not have permissions and should have 0 repositories",
appInstallation.listRepositories().toList().isEmpty());
assertThat("App does not have permissions and should have 0 repositories",
appInstallation.listRepositories().toList().isEmpty(),
is(true));
}
}

View File

@@ -126,7 +126,7 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
assertThat(installationToken2.getRepositorySelection(), is(GHRepositorySelection.ALL));
assertThat(installationToken2.getExpiresAt(), is(GitHubClient.parseDate("2019-12-19T12:27:59Z")));
assertNull(installationToken2.getRepositories());;
assertThat(installationToken2.getRepositories(), nullValue());;
}
private void testAppInstallation(GHAppInstallation appInstallation) throws IOException {
@@ -154,7 +154,7 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0])));
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z")));
assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseDate("2019-07-30T22:48:09.000Z")));
assertNull(appInstallation.getSingleFileName());
assertThat(appInstallation.getSingleFileName(), nullValue());
}
}

View File

@@ -6,7 +6,7 @@ import org.kohsuke.github.GHBranchProtection.EnforceAdmins;
import org.kohsuke.github.GHBranchProtection.RequiredReviews;
import org.kohsuke.github.GHBranchProtection.RequiredStatusChecks;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.*;
public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
private static final String BRANCH = "main";
@@ -43,33 +43,33 @@ public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
private void verifyBranchProtection(GHBranchProtection protection) {
RequiredStatusChecks statusChecks = protection.getRequiredStatusChecks();
assertNotNull(statusChecks);
assertTrue(statusChecks.isRequiresBranchUpToDate());
assertTrue(statusChecks.getContexts().contains("test-status-check"));
assertThat(statusChecks, notNullValue());
assertThat(statusChecks.isRequiresBranchUpToDate(), is(true));
assertThat(statusChecks.getContexts().contains("test-status-check"), is(true));
RequiredReviews requiredReviews = protection.getRequiredReviews();
assertNotNull(requiredReviews);
assertTrue(requiredReviews.isDismissStaleReviews());
assertTrue(requiredReviews.isRequireCodeOwnerReviews());
assertEquals(2, requiredReviews.getRequiredReviewers());
assertThat(requiredReviews, notNullValue());
assertThat(requiredReviews.isDismissStaleReviews(), is(true));
assertThat(requiredReviews.isRequireCodeOwnerReviews(), is(true));
assertThat(requiredReviews.getRequiredReviewers(), equalTo(2));
EnforceAdmins enforceAdmins = protection.getEnforceAdmins();
assertNotNull(enforceAdmins);
assertTrue(enforceAdmins.isEnabled());
assertThat(enforceAdmins, notNullValue());
assertThat(enforceAdmins.isEnabled(), is(true));
}
@Test
public void testEnableProtectionOnly() throws Exception {
branch.enableProtection().enable();
assertTrue(repo.getBranch(BRANCH).isProtected());
assertThat(repo.getBranch(BRANCH).isProtected(), is(true));
}
@Test
public void testDisableProtectionOnly() throws Exception {
GHBranchProtection protection = branch.enableProtection().enable();
assertTrue(repo.getBranch(BRANCH).isProtected());
assertThat(repo.getBranch(BRANCH).isProtected(), is(true));
branch.disableProtection();
assertFalse(repo.getBranch(BRANCH).isProtected());
assertThat(repo.getBranch(BRANCH).isProtected(), is(false));
}
@Test
@@ -77,18 +77,18 @@ public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
GHBranchProtection protection = branch.enableProtection().requireReviews().enable();
RequiredReviews requiredReviews = protection.getRequiredReviews();
assertNotNull(protection.getRequiredReviews());
assertFalse(requiredReviews.isDismissStaleReviews());
assertFalse(requiredReviews.isRequireCodeOwnerReviews());
assertThat(protection.getRequiredReviews(), notNullValue());
assertThat(requiredReviews.isDismissStaleReviews(), is(false));
assertThat(requiredReviews.isRequireCodeOwnerReviews(), is(false));
assertThat(protection.getRequiredReviews().getRequiredReviewers(), equalTo(1));
// Get goes through a different code path. Make sure it also gets the correct data.
protection = branch.getProtection();
requiredReviews = protection.getRequiredReviews();
assertNotNull(protection.getRequiredReviews());
assertFalse(requiredReviews.isDismissStaleReviews());
assertFalse(requiredReviews.isRequireCodeOwnerReviews());
assertThat(protection.getRequiredReviews(), notNullValue());
assertThat(requiredReviews.isDismissStaleReviews(), is(false));
assertThat(requiredReviews.isRequireCodeOwnerReviews(), is(false));
assertThat(protection.getRequiredReviews().getRequiredReviewers(), equalTo(1));
}
@@ -96,20 +96,21 @@ public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
public void testSignedCommits() throws Exception {
GHBranchProtection protection = branch.enableProtection().enable();
assertFalse(protection.getRequiredSignatures());
assertThat(protection.getRequiredSignatures(), is(false));
protection.enabledSignedCommits();
assertTrue(protection.getRequiredSignatures());
assertThat(protection.getRequiredSignatures(), is(true));
protection.disableSignedCommits();
assertFalse(protection.getRequiredSignatures());
assertThat(protection.getRequiredSignatures(), is(false));
}
@Test
public void testGetProtection() throws Exception {
GHBranchProtection protection = branch.enableProtection().enable();
GHBranchProtection protectionTest = repo.getBranch(BRANCH).getProtection();
assertTrue(protectionTest instanceof GHBranchProtection);
assertTrue(repo.getBranch(BRANCH).isProtected());
Boolean condition = protectionTest instanceof GHBranchProtection;
assertThat(condition, is(true));
assertThat(repo.getBranch(BRANCH).isProtected(), is(true));
}
}

View File

@@ -30,8 +30,7 @@ import org.kohsuke.github.GHCheckRun.Status;
import java.io.IOException;
import java.util.Date;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.*;
@SuppressWarnings("deprecation") // preview
public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
@@ -60,10 +59,10 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
.withCaption("Princess Unikitty")))
.add(new GHCheckRunBuilder.Action("Help", "what I need help with", "doit"))
.create();
assertEquals(Status.COMPLETED, checkRun.getStatus());
assertEquals(1, checkRun.getOutput().getAnnotationsCount());
assertEquals(1424883286L, checkRun.getId());
assertEquals("Hello Text!", checkRun.getOutput().getText());
assertThat(checkRun.getStatus(), equalTo(Status.COMPLETED));
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
assertThat(checkRun.getId(), equalTo(1424883286L));
assertThat(checkRun.getOutput().getText(), equalTo("Hello Text!"));
}
@Test
@@ -80,12 +79,12 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.add(output)
.create();
assertEquals(Status.COMPLETED, checkRun.getStatus());
assertEquals("Big Run", checkRun.getOutput().getTitle());
assertEquals("Lots of stuff here »", checkRun.getOutput().getSummary());
assertEquals(101, checkRun.getOutput().getAnnotationsCount());
assertEquals("Hello Text!", checkRun.getOutput().getText());
assertEquals(1424883599L, checkRun.getId());
assertThat(checkRun.getStatus(), equalTo(Status.COMPLETED));
assertThat(checkRun.getOutput().getTitle(), equalTo("Big Run"));
assertThat(checkRun.getOutput().getSummary(), equalTo("Lots of stuff here »"));
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(101));
assertThat(checkRun.getOutput().getText(), equalTo("Hello Text!"));
assertThat(checkRun.getId(), equalTo(1424883599L));
}
@Test
@@ -95,9 +94,9 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
.withConclusion(GHCheckRun.Conclusion.NEUTRAL)
.add(new GHCheckRunBuilder.Output("Quick note", "nothing more to see here"))
.create();
assertEquals(Status.COMPLETED, checkRun.getStatus());
assertEquals(0, checkRun.getOutput().getAnnotationsCount());
assertEquals(1424883957L, checkRun.getId());
assertThat(checkRun.getStatus(), equalTo(Status.COMPLETED));
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(0));
assertThat(checkRun.getId(), equalTo(1424883957L));
}
@Test
@@ -106,9 +105,9 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
.createCheckRun("outstanding", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
.withStatus(GHCheckRun.Status.IN_PROGRESS)
.create();
assertEquals(Status.IN_PROGRESS, checkRun.getStatus());
assertNull(checkRun.getConclusion());
assertEquals(1424883451L, checkRun.getId());
assertThat(checkRun.getStatus(), equalTo(Status.IN_PROGRESS));
assertThat(checkRun.getConclusion(), nullValue());
assertThat(checkRun.getId(), equalTo(1424883451L));
}
@Test
@@ -120,7 +119,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
.create();
fail("should have been rejected");
} catch (HttpException x) {
assertEquals(422, x.getResponseCode());
assertThat(x.getResponseCode(), equalTo(422));
assertThat(x.getMessage(), containsString("\\\"conclusion\\\" wasn't supplied"));
assertThat(x.getUrl(), containsString("/repos/hub4j-test-org/test-checks/check-runs"));
assertThat(x.getResponseMessage(), equalTo("422 Unprocessable Entity"));
@@ -144,9 +143,9 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withCompletedAt(new Date(999_999_999))
.create();
assertEquals(updated.getStartedAt(), new Date(999_999_000));
assertEquals(updated.getName(), "foo");
assertEquals(1, checkRun.getOutput().getAnnotationsCount());
assertThat(new Date(999_999_000), equalTo(updated.getStartedAt()));
assertThat("foo", equalTo(updated.getName()));
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
}
}

View File

@@ -12,7 +12,11 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* Integration test for {@link GHContent}.
@@ -58,23 +62,23 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
repo = gitHub.getRepository("hub4j-test-org/GHContentIntegrationTest");
GHContent content = repo.getFileContent("ghcontent-ro/a-file-with-content");
assertTrue(content.isFile());
assertEquals("thanks for reading me\n", content.getContent());
assertThat(content.isFile(), is(true));
assertThat(content.getContent(), equalTo("thanks for reading me\n"));
}
@Test
public void testGetEmptyFileContent() throws Exception {
GHContent content = repo.getFileContent("ghcontent-ro/an-empty-file");
assertTrue(content.isFile());
assertEquals("", content.getContent());
assertThat(content.isFile(), is(true));
assertThat(content.getContent(), equalTo(""));
}
@Test
public void testGetDirectoryContent() throws Exception {
List<GHContent> entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries");
assertTrue(entries.size() == 3);
assertThat(entries.size() == 3, is(true));
}
@Test
@@ -82,7 +86,7 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
// Used to truncate the ?ref=main, see gh-224 https://github.com/kohsuke/github-api/pull/224
List<GHContent> entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries/", "main");
assertTrue(entries.get(0).getUrl().endsWith("?ref=main"));
assertThat(entries.get(0).getUrl().endsWith("?ref=main"), is(true));
}
@Test
@@ -92,11 +96,11 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
createdFilename);
GHContent createdContent = created.getContent();
assertNotNull(created.getCommit());
assertNotNull(created.getContent());
assertNotNull(createdContent.getContent());
assertThat(created.getCommit(), notNullValue());
assertThat(created.getContent(), notNullValue());
assertThat(createdContent.getContent(), notNullValue());
assertThat(createdContent.getPath(), equalTo(createdFilename));
assertEquals("this is an awesome file I created\n", createdContent.getContent());
assertThat(createdContent.getContent(), equalTo("this is an awesome file I created\n"));
GHContent content = repo.getFileContent(createdFilename);
assertThat(content, is(notNullValue()));
@@ -116,17 +120,17 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
"Updated file for integration tests.");
GHContent updatedContent = updatedContentResponse.getContent();
assertNotNull(updatedContentResponse.getCommit());
assertNotNull(updatedContentResponse.getContent());
assertThat(updatedContentResponse.getCommit(), notNullValue());
assertThat(updatedContentResponse.getContent(), notNullValue());
// due to what appears to be a cache propagation delay, this test is too flaky
assertEquals("this is some new content",
new BufferedReader(new InputStreamReader(updatedContent.read())).readLine());
assertEquals("this is some new content\n", updatedContent.getContent());
assertThat(new BufferedReader(new InputStreamReader(updatedContent.read())).readLine(),
equalTo("this is some new content"));
assertThat(updatedContent.getContent(), equalTo("this is some new content\n"));
GHContentUpdateResponse deleteResponse = updatedContent.delete("Enough of this foolishness!");
assertNotNull(deleteResponse.getCommit());
assertNull(deleteResponse.getContent());
assertThat(deleteResponse.getCommit(), notNullValue());
assertThat(deleteResponse.getContent(), nullValue());
try {
repo.getFileContent(createdFilename);

View File

@@ -6,6 +6,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import static org.hamcrest.Matchers.*;
/**
* @author Martin van Zijl
*/
@@ -15,38 +17,38 @@ public class GHDeploymentTest extends AbstractGitHubWireMockTest {
public void testGetDeploymentByIdStringPayload() throws IOException {
final GHRepository repo = getRepository();
final GHDeployment deployment = repo.getDeployment(178653229);
assertNotNull(deployment);
assertEquals(178653229L, deployment.getId());
assertEquals("production", deployment.getEnvironment());
assertEquals("custom", deployment.getPayload());
assertEquals("custom", deployment.getPayloadObject());
assertEquals("main", deployment.getRef());
assertEquals("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353", deployment.getSha());
assertEquals("deploy", deployment.getTask());
assertEquals("production", deployment.getOriginalEnvironment());
assertEquals(false, deployment.isProductionEnvironment());
assertEquals(true, deployment.isTransientEnvironment());
assertThat(deployment, notNullValue());
assertThat(deployment.getId(), equalTo(178653229L));
assertThat(deployment.getEnvironment(), equalTo("production"));
assertThat(deployment.getPayload(), equalTo("custom"));
assertThat(deployment.getPayloadObject(), equalTo("custom"));
assertThat(deployment.getRef(), equalTo("main"));
assertThat(deployment.getSha(), equalTo("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353"));
assertThat(deployment.getTask(), equalTo("deploy"));
assertThat(deployment.getOriginalEnvironment(), equalTo("production"));
assertThat(deployment.isProductionEnvironment(), equalTo(false));
assertThat(deployment.isTransientEnvironment(), equalTo(true));
}
@Test
public void testGetDeploymentByIdObjectPayload() throws IOException {
final GHRepository repo = getRepository();
final GHDeployment deployment = repo.getDeployment(178653229);
assertNotNull(deployment);
assertEquals(178653229L, deployment.getId());
assertEquals("production", deployment.getEnvironment());
assertEquals("main", deployment.getRef());
assertEquals("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353", deployment.getSha());
assertEquals("deploy", deployment.getTask());
assertThat(deployment, notNullValue());
assertThat(deployment.getId(), equalTo(178653229L));
assertThat(deployment.getEnvironment(), equalTo("production"));
assertThat(deployment.getRef(), equalTo("main"));
assertThat(deployment.getSha(), equalTo("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353"));
assertThat(deployment.getTask(), equalTo("deploy"));
final Map<String, Object> payload = deployment.getPayloadMap();
assertEquals(4, payload.size());
assertEquals(1, payload.get("custom1"));
assertEquals("two", payload.get("custom2"));
assertEquals(Arrays.asList("3", 3, "three"), payload.get("custom3"));
assertNull(payload.get("custom4"));
assertEquals("production", deployment.getOriginalEnvironment());
assertEquals(false, deployment.isProductionEnvironment());
assertEquals(true, deployment.isTransientEnvironment());
assertThat(payload.size(), equalTo(4));
assertThat(payload.get("custom1"), equalTo(1));
assertThat(payload.get("custom2"), equalTo("two"));
assertThat(payload.get("custom3"), equalTo(Arrays.asList("3", 3, "three")));
assertThat(payload.get("custom4"), nullValue());
assertThat(deployment.getOriginalEnvironment(), equalTo("production"));
assertThat(deployment.isProductionEnvironment(), equalTo(false));
assertThat(deployment.isTransientEnvironment(), equalTo(true));
}
protected GHRepository getRepository() throws IOException {

View File

@@ -525,7 +525,7 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
assertThat(event.getState(), is(GHCommitState.SUCCESS));
assertThat(event.getCommit().getSHA1(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b"));
assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker"));
assertNull(event.getTargetUrl());
assertThat(event.getTargetUrl(), nullValue());
}
@Test

View File

@@ -1,5 +1,6 @@
package org.kohsuke.github;
import org.hamcrest.Matchers;
import org.junit.Test;
import java.io.FileNotFoundException;
@@ -26,12 +27,12 @@ public class GHGistTest extends AbstractGitHubWireMockTest {
assertThat(gist.getDescription(), equalTo("Test Gist"));
assertThat(gist.getFiles().size(), equalTo(3));
assertNotNull(gist.getUpdatedAt());
assertNotNull(gist.getCommentsUrl());
assertNotNull(gist.getCommitsUrl());
assertNotNull(gist.getGitPullUrl());
assertNotNull(gist.getGitPushUrl());
assertNotNull(gist.getHtmlUrl());
assertThat(gist.getUpdatedAt(), notNullValue());
assertThat(gist.getCommentsUrl(), notNullValue());
assertThat(gist.getCommitsUrl(), notNullValue());
assertThat(gist.getGitPullUrl(), notNullValue());
assertThat(gist.getGitPushUrl(), notNullValue());
assertThat(gist.getHtmlUrl(), notNullValue());
String id = gist.getGistId();
@@ -98,13 +99,13 @@ public class GHGistTest extends AbstractGitHubWireMockTest {
@Test
public void starTest() throws Exception {
GHGist gist = gitHub.getGist("9903708");
assertEquals("rtyler", gist.getOwner().getLogin());
assertThat(gist.getOwner().getLogin(), equalTo("rtyler"));
gist.star();
assertTrue(gist.isStarred());
assertThat(gist.isStarred(), Matchers.is(true));
gist.unstar();
assertFalse(gist.isStarred());
assertThat(gist.isStarred(), Matchers.is(false));
GHGist newGist = gist.fork();
@@ -126,16 +127,16 @@ public class GHGistTest extends AbstractGitHubWireMockTest {
public void gistFile() throws Exception {
GHGist gist = gitHub.getGist("9903708");
assertTrue(gist.isPublic());
assertThat(gist.isPublic(), Matchers.is(true));
assertThat(gist.getId(), equalTo(9903708L));
assertThat(gist.getGistId(), equalTo("9903708"));
assertEquals(1, gist.getFiles().size());
assertThat(gist.getFiles().size(), equalTo(1));
GHGistFile f = gist.getFile("keybase.md");
assertEquals("text/markdown", f.getType());
assertEquals("Markdown", f.getLanguage());
assertTrue(f.getContent().contains("### Keybase proof"));
assertNotNull(f.getContent());
assertThat(f.getType(), equalTo("text/markdown"));
assertThat(f.getLanguage(), equalTo("Markdown"));
assertThat(f.getContent().contains("### Keybase proof"), Matchers.is(true));
assertThat(f.getContent(), notNullValue());
}
}

View File

@@ -7,6 +7,9 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Map;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
/**
* @author Martin van Zijl
*/
@@ -46,24 +49,24 @@ public class GHGistUpdaterTest extends AbstractGitHubWireMockTest {
.updateFile("update-me.txt", "Content updated by API")
.update();
assertEquals("Description updated by API", updatedGist.getDescription());
assertThat(updatedGist.getDescription(), equalTo("Description updated by API"));
Map<String, GHGistFile> files = updatedGist.getFiles();
// Check that the unmodified file stays intact.
assertTrue(files.containsKey("unmodified.txt"));
assertEquals("Should be unmodified", files.get("unmodified.txt").getContent());
assertThat(files.containsKey("unmodified.txt"), is(true));
assertThat(files.get("unmodified.txt").getContent(), equalTo("Should be unmodified"));
// Check that the files are updated as expected.
// assertFalse("File was not deleted.", files.containsKey("delete-me.txt"));
assertTrue(files.containsKey("new-file.txt"));
assertEquals("Added by updater", files.get("new-file.txt").getContent());
assertThat(files.containsKey("new-file.txt"), is(true));
assertThat(files.get("new-file.txt").getContent(), equalTo("Added by updater"));
assertFalse(files.containsKey("rename-me.py"));
assertTrue(files.containsKey("renamed.py"));
assertEquals("print 'hello'", files.get("renamed.py").getContent());
assertThat(files.containsKey("rename-me.py"), is(false));
assertThat(files.containsKey("renamed.py"), is(true));
assertThat(files.get("renamed.py").getContent(), equalTo("print 'hello'"));
assertEquals("Content updated by API", files.get("update-me.txt").getContent());
assertThat(files.get("update-me.txt").getContent(), equalTo("Content updated by API"));
}
}

View File

@@ -13,13 +13,14 @@ import java.util.stream.StreamSupport;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
public class GHIssueEventAttributeTest extends AbstractGitHubWireMockTest {
private enum Type implements Predicate<GHIssueEvent>, Consumer<GHIssueEvent> {
milestone(e -> assertNotNull(e.getMilestone()), "milestoned", "demilestoned"),
label(e -> assertNotNull(e.getLabel()), "labeled", "unlabeled"),
assignment(e -> assertNotNull(e.getAssignee()), "assigned", "unassigned");
milestone(e -> assertThat(e.getMilestone(), notNullValue()), "milestoned", "demilestoned"),
label(e -> assertThat(e.getLabel(), notNullValue()), "labeled", "unlabeled"),
assignment(e -> assertThat(e.getAssignee(), notNullValue()), "assigned", "unassigned");
private final Consumer<GHIssueEvent> assertion;
private final Set<String> subtypes;

View File

@@ -5,6 +5,8 @@ import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static org.hamcrest.Matchers.*;
/**
* @author Martin van Zijl
*/
@@ -22,16 +24,16 @@ public class GHIssueEventTest extends AbstractGitHubWireMockTest {
// Test that the events are present.
List<GHIssueEvent> list = issue.listEvents().toList();
assertEquals(1, list.size());
assertThat(list.size(), equalTo(1));
GHIssueEvent event = list.get(0);
assertEquals(issue.getNumber(), event.getIssue().getNumber());
assertEquals("labeled", event.getEvent());
assertThat(event.getIssue().getNumber(), equalTo(issue.getNumber()));
assertThat(event.getEvent(), equalTo("labeled"));
// Test that we can get a single event directly.
GHIssueEvent eventFromRepo = repo.getIssueEvent(event.getId());
assertEquals(event.getId(), eventFromRepo.getId());
assertEquals(event.getCreatedAt(), eventFromRepo.getCreatedAt());
assertThat(eventFromRepo.getId(), equalTo(event.getId()));
assertThat(eventFromRepo.getCreatedAt(), equalTo(event.getCreatedAt()));
// Close the issue.
issue.close();
@@ -41,11 +43,11 @@ public class GHIssueEventTest extends AbstractGitHubWireMockTest {
public void testRepositoryEvents() throws Exception {
GHRepository repo = getRepository();
List<GHIssueEvent> list = repo.listIssueEvents().toList();
assertTrue(list.size() > 0);
assertThat(list.size() > 0, is(true));
int i = 0;
for (GHIssueEvent event : list) {
assertNotNull(event.getIssue());
assertThat(event.getIssue(), notNullValue());
if (i++ > 10)
break;
}

View File

@@ -46,7 +46,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
@Test
public void listLicenses() throws IOException {
Iterable<GHLicense> licenses = gitHub.listLicenses();
assertTrue(licenses.iterator().hasNext());
assertThat(licenses.iterator().hasNext(), is(true));
}
/**
@@ -60,7 +60,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
PagedIterable<GHLicense> licenses = gitHub.listLicenses();
for (GHLicense lic : licenses) {
if (lic.getKey().equals("mit")) {
assertTrue(lic.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
assertThat(lic.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")), is(true));
return;
}
}
@@ -78,7 +78,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void getLicense() throws IOException {
String key = "mit";
GHLicense license = gitHub.getLicense(key);
assertNotNull(license);
assertThat(license, notNullValue());
assertThat("The name is correct", license.getName(), equalTo("MIT License"));
assertThat("The HTML URL is correct",
license.getHtmlUrl(),
@@ -105,11 +105,12 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryLicense() throws IOException {
GHRepository repo = gitHub.getRepository("hub4j/github-api");
GHLicense license = repo.getLicense();
assertNotNull("The license is populated", license);
assertTrue("The key is correct", license.getKey().equals("mit"));
assertTrue("The name is correct", license.getName().equals("MIT License"));
assertTrue("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
assertThat("The license is populated", license, notNullValue());
assertThat("The key is correct", license.getKey().equals("mit"), is(true));
assertThat("The name is correct", license.getName().equals("MIT License"), is(true));
assertThat("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")),
is(true));
}
/**
@@ -122,11 +123,12 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryLicenseAtom() throws IOException {
GHRepository repo = gitHub.getRepository("atom/atom");
GHLicense license = repo.getLicense();
assertNotNull("The license is populated", license);
assertTrue("The key is correct", license.getKey().equals("mit"));
assertTrue("The name is correct", license.getName().equals("MIT License"));
assertTrue("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
assertThat("The license is populated", license, notNullValue());
assertThat("The key is correct", license.getKey().equals("mit"), is(true));
assertThat("The name is correct", license.getName().equals("MIT License"), is(true));
assertThat("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")),
is(true));
}
/**
@@ -139,11 +141,12 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryLicensePomes() throws IOException {
GHRepository repo = gitHub.getRepository("pomes/pomes");
GHLicense license = repo.getLicense();
assertNotNull("The license is populated", license);
assertTrue("The key is correct", license.getKey().equals("apache-2.0"));
assertTrue("The name is correct", license.getName().equals("Apache License 2.0"));
assertTrue("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/apache-2.0")));
assertThat("The license is populated", license, notNullValue());
assertThat("The key is correct", license.getKey().equals("apache-2.0"), is(true));
assertThat("The name is correct", license.getName().equals("Apache License 2.0"), is(true));
assertThat("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/apache-2.0")),
is(true));
}
/**
@@ -157,7 +160,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryWithoutLicense() throws IOException {
GHRepository repo = gitHub.getRepository(GITHUB_API_TEST_ORG + "/empty");
GHLicense license = repo.getLicense();
assertNull("There is no license", license);
assertThat("There is no license", license, nullValue());
}
/**
@@ -171,13 +174,15 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryFullLicense() throws IOException {
GHRepository repo = gitHub.getRepository("hub4j/github-api");
GHLicense license = repo.getLicense();
assertNotNull("The license is populated", license);
assertTrue("The key is correct", license.getKey().equals("mit"));
assertTrue("The name is correct", license.getName().equals("MIT License"));
assertTrue("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
assertTrue("The HTML URL is correct",
license.getHtmlUrl().equals(new URL("http://choosealicense.com/licenses/mit/")));
assertThat("The license is populated", license, notNullValue());
assertThat("The key is correct", license.getKey().equals("mit"), is(true));
assertThat("The name is correct", license.getName().equals("MIT License"), is(true));
assertThat("The URL is correct",
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")),
is(true));
assertThat("The HTML URL is correct",
license.getHtmlUrl().equals(new URL("http://choosealicense.com/licenses/mit/")),
is(true));
}
/**
@@ -191,13 +196,13 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryLicenseContent() throws IOException {
GHRepository repo = gitHub.getRepository("pomes/pomes");
GHContent content = repo.getLicenseContent();
assertNotNull("The license content is populated", content);
assertTrue("The type is 'file'", content.getType().equals("file"));
assertTrue("The license file is 'LICENSE'", content.getName().equals("LICENSE"));
assertThat("The license content is populated", content, notNullValue());
assertThat("The type is 'file'", content.getType().equals("file"), is(true));
assertThat("The license file is 'LICENSE'", content.getName().equals("LICENSE"), is(true));
if (content.getEncoding().equals("base64")) {
String licenseText = new String(IOUtils.toByteArray(content.read()));
assertTrue("The license appears to be an Apache License", licenseText.contains("Apache License"));
assertThat("The license appears to be an Apache License", licenseText.contains("Apache License"), is(true));
} else {
fail("Expected the license to be Base64 encoded but instead it was " + content.getEncoding());
}
@@ -214,7 +219,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
public void checkRepositoryLicenseForIndeterminate() throws IOException {
GHRepository repo = gitHub.getRepository("bndtools/bnd");
GHLicense license = repo.getLicense();
assertNotNull("The license is populated", license);
assertThat("The license is populated", license, notNullValue());
assertThat(license.getKey(), equalTo("other"));
assertThat(license.getDescription(), is(nullValue()));
assertThat(license.getUrl(), is(nullValue()));

View File

@@ -5,11 +5,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.*;
import static org.kohsuke.github.GHDirection.DESC;
import static org.kohsuke.github.GHMarketplaceAccountType.ORGANIZATION;
import static org.kohsuke.github.GHMarketplaceListAccountBuilder.Sort.UPDATED;
@@ -31,30 +27,30 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
@Test
public void listMarketplacePlans() throws IOException {
List<GHMarketplacePlan> plans = gitHub.listMarketplacePlans().toList();
assertEquals(3, plans.size());
assertThat(plans.size(), equalTo(3));
plans.forEach(this::testMarketplacePlan);
}
@Test
public void listAccounts() throws IOException {
List<GHMarketplacePlan> plans = gitHub.listMarketplacePlans().toList();
assertEquals(3, plans.size());
assertThat(plans.size(), equalTo(3));
List<GHMarketplaceAccountPlan> marketplaceUsers = plans.get(0).listAccounts().createRequest().toList();
assertEquals(2, marketplaceUsers.size());
assertThat(marketplaceUsers.size(), equalTo(2));
marketplaceUsers.forEach(this::testMarketplaceAccount);
}
@Test
public void listAccountsWithDirection() throws IOException {
List<GHMarketplacePlan> plans = gitHub.listMarketplacePlans().toList();
assertEquals(3, plans.size());
assertThat(plans.size(), equalTo(3));
for (GHMarketplacePlan plan : plans) {
List<GHMarketplaceAccountPlan> marketplaceUsers = plan.listAccounts()
.direction(DESC)
.createRequest()
.toList();
assertEquals(2, marketplaceUsers.size());
assertThat(marketplaceUsers.size(), equalTo(2));
marketplaceUsers.forEach(this::testMarketplaceAccount);
}
@@ -63,7 +59,7 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
@Test
public void listAccountsWithSortAndDirection() throws IOException {
List<GHMarketplacePlan> plans = gitHub.listMarketplacePlans().toList();
assertEquals(3, plans.size());
assertThat(plans.size(), equalTo(3));
for (GHMarketplacePlan plan : plans) {
List<GHMarketplaceAccountPlan> marketplaceUsers = plan.listAccounts()
@@ -71,7 +67,7 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
.direction(DESC)
.createRequest()
.toList();
assertEquals(2, marketplaceUsers.size());
assertThat(marketplaceUsers.size(), equalTo(2));
marketplaceUsers.forEach(this::testMarketplaceAccount);
}
@@ -79,39 +75,39 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
private void testMarketplacePlan(GHMarketplacePlan plan) {
// Non-nullable fields
assertNotNull(plan.getUrl());
assertNotNull(plan.getAccountsUrl());
assertNotNull(plan.getName());
assertNotNull(plan.getDescription());
assertNotNull(plan.getPriceModel());
assertNotNull(plan.getState());
assertThat(plan.getUrl(), notNullValue());
assertThat(plan.getAccountsUrl(), notNullValue());
assertThat(plan.getName(), notNullValue());
assertThat(plan.getDescription(), notNullValue());
assertThat(plan.getPriceModel(), notNullValue());
assertThat(plan.getState(), notNullValue());
// primitive fields
assertNotEquals(0L, plan.getId());
assertNotEquals(0L, plan.getNumber());
assertTrue(plan.getMonthlyPriceInCents() >= 0);
assertThat(plan.getId(), not(0L));
assertThat(plan.getNumber(), not(0L));
assertThat(plan.getMonthlyPriceInCents() >= 0, is(true));
// list
assertEquals(2, plan.getBullets().size());
assertThat(plan.getBullets().size(), equalTo(2));
}
private void testMarketplaceAccount(GHMarketplaceAccountPlan account) {
// Non-nullable fields
assertNotNull(account.getLogin());
assertNotNull(account.getUrl());
assertNotNull(account.getType());
assertNotNull(account.getMarketplacePurchase());
assertThat(account.getLogin(), notNullValue());
assertThat(account.getUrl(), notNullValue());
assertThat(account.getType(), notNullValue());
assertThat(account.getMarketplacePurchase(), notNullValue());
testMarketplacePurchase(account.getMarketplacePurchase());
// primitive fields
assertNotEquals(0L, account.getId());
assertThat(account.getId(), not(0L));
/* logical combination tests */
// Rationale: organization_billing_email is only set when account type is ORGANIZATION.
if (account.getType() == ORGANIZATION)
assertNotNull(account.getOrganizationBillingEmail());
assertThat(account.getOrganizationBillingEmail(), notNullValue());
else
assertNull(account.getOrganizationBillingEmail());
assertThat(account.getOrganizationBillingEmail(), nullValue());
// Rationale: marketplace_pending_change isn't always set... This is what GitHub says about it:
// "When someone submits a plan change that won't be processed until the end of their billing cycle,
@@ -122,41 +118,41 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
private void testMarketplacePurchase(GHMarketplacePurchase marketplacePurchase) {
// Non-nullable fields
assertNotNull(marketplacePurchase.getBillingCycle());
assertNotNull(marketplacePurchase.getNextBillingDate());
assertNotNull(marketplacePurchase.getUpdatedAt());
assertThat(marketplacePurchase.getBillingCycle(), notNullValue());
assertThat(marketplacePurchase.getNextBillingDate(), notNullValue());
assertThat(marketplacePurchase.getUpdatedAt(), notNullValue());
testMarketplacePlan(marketplacePurchase.getPlan());
/* logical combination tests */
// Rationale: if onFreeTrial is true, then we should see free_trial_ends_on property set to something
// different than null
if (marketplacePurchase.isOnFreeTrial())
assertNotNull(marketplacePurchase.getFreeTrialEndsOn());
assertThat(marketplacePurchase.getFreeTrialEndsOn(), notNullValue());
else
assertNull(marketplacePurchase.getFreeTrialEndsOn());
assertThat(marketplacePurchase.getFreeTrialEndsOn(), nullValue());
// Rationale: if price model is PER_UNIT then unit_count can't be null
if (marketplacePurchase.getPlan().getPriceModel() == GHMarketplacePriceModel.PER_UNIT)
assertNotNull(marketplacePurchase.getUnitCount());
assertThat(marketplacePurchase.getUnitCount(), notNullValue());
else
assertNull(marketplacePurchase.getUnitCount());
assertThat(marketplacePurchase.getUnitCount(), nullValue());
}
private void testMarketplacePendingChange(GHMarketplacePendingChange marketplacePendingChange) {
// Non-nullable fields
assertNotNull(marketplacePendingChange.getEffectiveDate());
assertThat(marketplacePendingChange.getEffectiveDate(), notNullValue());
testMarketplacePlan(marketplacePendingChange.getPlan());
// primitive fields
assertNotEquals(0L, marketplacePendingChange.getId());
assertThat(marketplacePendingChange.getId(), not(0L));
/* logical combination tests */
// Rationale: if price model is PER_UNIT then unit_count can't be null
if (marketplacePendingChange.getPlan().getPriceModel() == GHMarketplacePriceModel.PER_UNIT)
assertNotNull(marketplacePendingChange.getUnitCount());
assertThat(marketplacePendingChange.getUnitCount(), notNullValue());
else
assertNull(marketplacePendingChange.getUnitCount());
assertThat(marketplacePendingChange.getUnitCount(), nullValue());
}

View File

@@ -7,6 +7,9 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Date;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
/**
* @author Martin van Zijl
*/
@@ -45,12 +48,12 @@ public class GHMilestoneTest extends AbstractGitHubWireMockTest {
// Force reload.
milestone = repo.getMilestone(milestone.getNumber());
assertEquals(NEW_TITLE, milestone.getTitle());
assertEquals(NEW_DESCRIPTION, milestone.getDescription());
assertThat(milestone.getTitle(), equalTo(NEW_TITLE));
assertThat(milestone.getDescription(), equalTo(NEW_DESCRIPTION));
// The time is truncated when sent to the server, but still part of the returned value
// 07:00 midnight PDT
assertEquals(OUTPUT_DUE_DATE, milestone.getDueOn());
assertThat(milestone.getDueOn(), equalTo(OUTPUT_DUE_DATE));
}
@Test
@@ -62,12 +65,12 @@ public class GHMilestoneTest extends AbstractGitHubWireMockTest {
// set the milestone
issue.setMilestone(milestone);
issue = repo.getIssue(issue.getNumber()); // force reload
assertEquals(milestone.getNumber(), issue.getMilestone().getNumber());
assertThat(issue.getMilestone().getNumber(), equalTo(milestone.getNumber()));
// remove the milestone
issue.setMilestone(null);
issue = repo.getIssue(issue.getNumber()); // force reload
assertEquals(null, issue.getMilestone());
assertThat(issue.getMilestone(), equalTo(null));
}
@Test
@@ -80,12 +83,12 @@ public class GHMilestoneTest extends AbstractGitHubWireMockTest {
// set the milestone
p.setMilestone(milestone);
p = repo.getPullRequest(p.getNumber()); // force reload
assertEquals(milestone.getNumber(), p.getMilestone().getNumber());
assertThat(p.getMilestone().getNumber(), equalTo(milestone.getNumber()));
// remove the milestone
p.setMilestone(null);
p = repo.getPullRequest(p.getNumber()); // force reload
assertNull(p.getMilestone());
assertThat(p.getMilestone(), nullValue());
}
protected GHRepository getRepository() throws IOException {

View File

@@ -1,7 +1,6 @@
package org.kohsuke.github;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.kohsuke.github.GHOrganization.Permission;
@@ -42,7 +41,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
.team(org.getTeamByName("Core Developers"))
.private_(false)
.create();
Assert.assertNotNull(repository);
assertThat(repository, notNullValue());
}
@Test
@@ -56,8 +55,8 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
.team(org.getTeamByName("Core Developers"))
.autoInit(true)
.create();
Assert.assertNotNull(repository);
Assert.assertNotNull(repository.getReadme());
assertThat(repository, notNullValue());
assertThat(repository.getReadme(), notNullValue());
}
@Test
@@ -75,10 +74,10 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
.autoInit(true)
.isTemplate(true)
.create();
Assert.assertNotNull(repository);
assertThat(repository, notNullValue());
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 1));
Assert.assertNotNull(repository.getReadme());
assertThat(repository.getReadme(), notNullValue());
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 2));
// isTemplate() does not call populate() from create
@@ -107,8 +106,8 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
.owner(GITHUB_API_TEST_ORG)
.create();
Assert.assertNotNull(repository);
Assert.assertNotNull(repository.getReadme());
assertThat(repository, notNullValue());
assertThat(repository.getReadme(), notNullValue());
}
@@ -139,20 +138,21 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
List<GHUser> admins = org.listMembersWithFilter("all").toList();
assertNotNull(admins);
assertTrue(admins.size() >= 12); // In case more are added in the future
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("alexanderrtaylor")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("asthinasthi")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("farmdawgnation")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("halkeye")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("jberglund-BSFT")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke2")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("martinvanzijl")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("PauloMigAlmeida")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("Sage-Pierce")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")));
assertThat(admins, notNullValue());
// In case more are added in the future
assertThat(admins.size() >= 12, is(true));
assertThat(admins.stream().anyMatch(ghUser11 -> ghUser11.getLogin().equals("alexanderrtaylor")), is(true));
assertThat(admins.stream().anyMatch(ghUser10 -> ghUser10.getLogin().equals("asthinasthi")), is(true));
assertThat(admins.stream().anyMatch(ghUser9 -> ghUser9.getLogin().equals("bitwiseman")), is(true));
assertThat(admins.stream().anyMatch(ghUser8 -> ghUser8.getLogin().equals("farmdawgnation")), is(true));
assertThat(admins.stream().anyMatch(ghUser7 -> ghUser7.getLogin().equals("halkeye")), is(true));
assertThat(admins.stream().anyMatch(ghUser6 -> ghUser6.getLogin().equals("jberglund-BSFT")), is(true));
assertThat(admins.stream().anyMatch(ghUser5 -> ghUser5.getLogin().equals("kohsuke")), is(true));
assertThat(admins.stream().anyMatch(ghUser4 -> ghUser4.getLogin().equals("kohsuke2")), is(true));
assertThat(admins.stream().anyMatch(ghUser3 -> ghUser3.getLogin().equals("martinvanzijl")), is(true));
assertThat(admins.stream().anyMatch(ghUser2 -> ghUser2.getLogin().equals("PauloMigAlmeida")), is(true));
assertThat(admins.stream().anyMatch(ghUser1 -> ghUser1.getLogin().equals("Sage-Pierce")), is(true));
assertThat(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")), is(true));
}
@Test
@@ -161,20 +161,21 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
List<GHUser> admins = org.listMembersWithRole("admin").toList();
assertNotNull(admins);
assertTrue(admins.size() >= 12); // In case more are added in the future
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("alexanderrtaylor")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("asthinasthi")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("farmdawgnation")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("halkeye")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("jberglund-BSFT")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke2")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("martinvanzijl")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("PauloMigAlmeida")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("Sage-Pierce")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")));
assertThat(admins, notNullValue());
// In case more are added in the future
assertThat(admins.size() >= 12, is(true));
assertThat(admins.stream().anyMatch(ghUser11 -> ghUser11.getLogin().equals("alexanderrtaylor")), is(true));
assertThat(admins.stream().anyMatch(ghUser10 -> ghUser10.getLogin().equals("asthinasthi")), is(true));
assertThat(admins.stream().anyMatch(ghUser9 -> ghUser9.getLogin().equals("bitwiseman")), is(true));
assertThat(admins.stream().anyMatch(ghUser8 -> ghUser8.getLogin().equals("farmdawgnation")), is(true));
assertThat(admins.stream().anyMatch(ghUser7 -> ghUser7.getLogin().equals("halkeye")), is(true));
assertThat(admins.stream().anyMatch(ghUser6 -> ghUser6.getLogin().equals("jberglund-BSFT")), is(true));
assertThat(admins.stream().anyMatch(ghUser5 -> ghUser5.getLogin().equals("kohsuke")), is(true));
assertThat(admins.stream().anyMatch(ghUser4 -> ghUser4.getLogin().equals("kohsuke2")), is(true));
assertThat(admins.stream().anyMatch(ghUser3 -> ghUser3.getLogin().equals("martinvanzijl")), is(true));
assertThat(admins.stream().anyMatch(ghUser2 -> ghUser2.getLogin().equals("PauloMigAlmeida")), is(true));
assertThat(admins.stream().anyMatch(ghUser1 -> ghUser1.getLogin().equals("Sage-Pierce")), is(true));
assertThat(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")), is(true));
}
@Test
@@ -186,8 +187,8 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
// Create team with access to repository. Check access was granted.
GHTeam team = org.createTeam(TEAM_NAME_CREATE, GHOrganization.Permission.PUSH, repo);
Assert.assertTrue(team.getRepositories().containsKey(REPO_NAME));
assertEquals(Permission.PUSH.toString().toLowerCase(), team.getPermission());
assertThat(team.getRepositories().containsKey(REPO_NAME), is(true));
assertThat(team.getPermission(), equalTo(Permission.PUSH.toString().toLowerCase()));
}
@Test
@@ -200,8 +201,8 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
// Create team with no permission field. Verify that default permission is pull
GHTeam team = org.createTeam(TEAM_NAME_CREATE, repo);
Assert.assertTrue(team.getRepositories().containsKey(REPO_NAME));
assertEquals(DEFAULT_PERMISSION, team.getPermission());
assertThat(team.getRepositories().containsKey(REPO_NAME), is(true));
assertThat(team.getPermission(), equalTo(DEFAULT_PERMISSION));
}
@Test
@@ -209,7 +210,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam team = org.createTeam(TEAM_NAME_CREATE).privacy(GHTeam.Privacy.CLOSED).create();
assertEquals(GHTeam.Privacy.CLOSED, team.getPrivacy());
assertThat(team.getPrivacy(), equalTo(GHTeam.Privacy.CLOSED));
}
@Test
@@ -224,7 +225,7 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
.privacy(GHTeam.Privacy.CLOSED)
.parentTeamId(3617900)
.create();
assertEquals("Team description", team.getDescription());
assertEquals(GHTeam.Privacy.CLOSED, team.getPrivacy());
assertThat(team.getDescription(), equalTo("Team description"));
assertThat(team.getPrivacy(), equalTo(GHTeam.Privacy.CLOSED));
}
}

View File

@@ -4,6 +4,9 @@ import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
/**
* @author Martin van Zijl
*/
@@ -12,15 +15,15 @@ public class GHPersonTest extends AbstractGitHubWireMockTest {
public void testFieldsForOrganization() throws Exception {
GHRepository repo = getRepository();
GHUser owner = repo.getOwner();
assertEquals("Organization", owner.getType());
assertNotNull(owner.isSiteAdmin());
assertThat(owner.getType(), equalTo("Organization"));
assertThat(owner.isSiteAdmin(), notNullValue());
}
@Test
public void testFieldsForUser() throws Exception {
GHUser user = gitHub.getUser("kohsuke2");
assertEquals("User", user.getType());
assertNotNull(user.isSiteAdmin());
assertThat(user.getType(), equalTo("User"));
assertThat(user.isSiteAdmin(), notNullValue());
}
protected GHRepository getRepository() throws IOException {

View File

@@ -1,13 +1,14 @@
package org.kohsuke.github;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import static org.hamcrest.Matchers.*;
/**
* @author Gunnar Skjold
*/
@@ -27,24 +28,24 @@ public class GHProjectCardTest extends AbstractGitHubWireMockTest {
@Test
public void testCreatedCard() {
Assert.assertEquals("This is a card", card.getNote());
Assert.assertFalse(card.isArchived());
assertThat(card.getNote(), equalTo("This is a card"));
assertThat(card.isArchived(), is(false));
}
@Test
public void testEditCardNote() throws IOException {
card.setNote("New note");
card = gitHub.getProjectCard(card.getId());
Assert.assertEquals("New note", card.getNote());
Assert.assertFalse(card.isArchived());
assertThat(card.getNote(), equalTo("New note"));
assertThat(card.isArchived(), is(false));
}
@Test
public void testArchiveCard() throws IOException {
card.setArchived(true);
card = gitHub.getProjectCard(card.getId());
Assert.assertEquals("This is a card", card.getNote());
Assert.assertTrue(card.isArchived());
assertThat(card.getNote(), equalTo("This is a card"));
assertThat(card.isArchived(), is(true));
}
@Test
@@ -53,7 +54,7 @@ public class GHProjectCardTest extends AbstractGitHubWireMockTest {
try {
GHIssue issue = repo.createIssue("new-issue").body("With body").create();
GHProjectCard card = column.createCard(issue);
Assert.assertEquals(issue.getUrl(), card.getContentUrl());
assertThat(card.getContentUrl(), equalTo(issue.getUrl()));
} finally {
repo.delete();
}
@@ -64,7 +65,7 @@ public class GHProjectCardTest extends AbstractGitHubWireMockTest {
card.delete();
try {
card = gitHub.getProjectCard(card.getId());
Assert.assertNull(card);
assertThat(card, nullValue());
} catch (FileNotFoundException e) {
card = null;
}

View File

@@ -1,13 +1,15 @@
package org.kohsuke.github;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
/**
* @author Gunnar Skjold
*/
@@ -23,14 +25,14 @@ public class GHProjectColumnTest extends AbstractGitHubWireMockTest {
@Test
public void testCreatedColumn() {
Assert.assertEquals("column-one", column.getName());
assertThat(column.getName(), equalTo("column-one"));
}
@Test
public void testEditColumnName() throws IOException {
column.setName("new-name");
column = gitHub.getProjectColumn(column.getId());
Assert.assertEquals("new-name", column.getName());
assertThat(column.getName(), equalTo("new-name"));
}
@Test
@@ -38,7 +40,7 @@ public class GHProjectColumnTest extends AbstractGitHubWireMockTest {
column.delete();
try {
column = gitHub.getProjectColumn(column.getId());
Assert.assertNull(column);
assertThat(column, nullValue());
} catch (FileNotFoundException e) {
column = null;
}

View File

@@ -1,13 +1,14 @@
package org.kohsuke.github;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import static org.hamcrest.Matchers.*;
/**
* @author Gunnar Skjold
*/
@@ -21,37 +22,37 @@ public class GHProjectTest extends AbstractGitHubWireMockTest {
@Test
public void testCreatedProject() {
Assert.assertNotNull(project);
Assert.assertEquals("test-project", project.getName());
Assert.assertEquals("This is a test project", project.getBody());
Assert.assertEquals(GHProject.ProjectState.OPEN, project.getState());
assertThat(project, notNullValue());
assertThat(project.getName(), equalTo("test-project"));
assertThat(project.getBody(), equalTo("This is a test project"));
assertThat(project.getState(), equalTo(GHProject.ProjectState.OPEN));
}
@Test
public void testEditProjectName() throws IOException {
project.setName("new-name");
project = gitHub.getProject(project.getId());
Assert.assertEquals("new-name", project.getName());
Assert.assertEquals("This is a test project", project.getBody());
Assert.assertEquals(GHProject.ProjectState.OPEN, project.getState());
assertThat(project.getName(), equalTo("new-name"));
assertThat(project.getBody(), equalTo("This is a test project"));
assertThat(project.getState(), equalTo(GHProject.ProjectState.OPEN));
}
@Test
public void testEditProjectBody() throws IOException {
project.setBody("New body");
project = gitHub.getProject(project.getId());
Assert.assertEquals("test-project", project.getName());
Assert.assertEquals("New body", project.getBody());
Assert.assertEquals(GHProject.ProjectState.OPEN, project.getState());
assertThat(project.getName(), equalTo("test-project"));
assertThat(project.getBody(), equalTo("New body"));
assertThat(project.getState(), equalTo(GHProject.ProjectState.OPEN));
}
@Test
public void testEditProjectState() throws IOException {
project.setState(GHProject.ProjectState.CLOSED);
project = gitHub.getProject(project.getId());
Assert.assertEquals("test-project", project.getName());
Assert.assertEquals("This is a test project", project.getBody());
Assert.assertEquals(GHProject.ProjectState.CLOSED, project.getState());
assertThat(project.getName(), equalTo("test-project"));
assertThat(project.getBody(), equalTo("This is a test project"));
assertThat(project.getState(), equalTo(GHProject.ProjectState.CLOSED));
}
@Test
@@ -59,7 +60,7 @@ public class GHProjectTest extends AbstractGitHubWireMockTest {
project.delete();
try {
project = gitHub.getProject(project.getId());
Assert.assertNull(project);
assertThat(project, nullValue());
} catch (FileNotFoundException e) {
project = null;
}

View File

@@ -9,14 +9,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
/**
* @author Kohsuke Kawaguchi
@@ -41,7 +34,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
String name = "createPullRequest";
GHRepository repo = getRepository();
GHPullRequest p = repo.createPullRequest(name, "test/stable", "main", "## test");
assertEquals(name, p.getTitle());
assertThat(p.getTitle(), equalTo(name));
assertThat(p.canMaintainerModify(), is(false));
assertThat(p.isDraft(), is(false));
}
@@ -51,7 +44,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
String name = "createDraftPullRequest";
GHRepository repo = getRepository();
GHPullRequest p = repo.createPullRequest(name, "test/stable", "main", "## test", false, true);
assertEquals(name, p.getTitle());
assertThat(p.getTitle(), equalTo(name));
assertThat(p.canMaintainerModify(), is(false));
assertThat(p.isDraft(), is(true));
@@ -82,10 +75,10 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
String name = "closePullRequest";
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "main", "## test");
// System.out.println(p.getUrl());
assertEquals(name, p.getTitle());
assertEquals(GHIssueState.OPEN, getRepository().getPullRequest(p.getNumber()).getState());
assertThat(p.getTitle(), equalTo(name));
assertThat(getRepository().getPullRequest(p.getNumber()).getState(), equalTo(GHIssueState.OPEN));
p.close();
assertEquals(GHIssueState.CLOSED, getRepository().getPullRequest(p.getNumber()).getState());
assertThat(getRepository().getPullRequest(p.getNumber()).getState(), equalTo(GHIssueState.CLOSED));
}
@Test
@@ -107,9 +100,9 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
assertThat(review.getCommitId(), notNullValue());
draftReview.submit("Some review comment", GHPullRequestReviewEvent.COMMENT);
List<GHPullRequestReviewComment> comments = review.listReviewComments().toList();
assertEquals(1, comments.size());
assertThat(comments.size(), equalTo(1));
GHPullRequestReviewComment comment = comments.get(0);
assertEquals("Some niggle", comment.getBody());
assertThat(comment.getBody(), equalTo("Some niggle"));
draftReview = p.createReview().body("Some new review").comment("Some niggle", "README.md", 1).create();
draftReview.delete();
}
@@ -120,12 +113,12 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "main", "## test");
try {
// System.out.println(p.getUrl());
assertTrue(p.listReviewComments().toList().isEmpty());
assertThat(p.listReviewComments().toList().isEmpty(), is(true));
p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1);
List<GHPullRequestReviewComment> comments = p.listReviewComments().toList();
assertEquals(1, comments.size());
assertThat(comments.size(), equalTo(1));
GHPullRequestReviewComment comment = comments.get(0);
assertEquals("Sample review comment", comment.getBody());
assertThat(comment.getBody(), equalTo("Sample review comment"));
assertThat(comment.getInReplyToId(), equalTo(-1L));
assertThat(comment.getPath(), equalTo("README.md"));
assertThat(comment.getPosition(), equalTo(1));
@@ -148,12 +141,12 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
assertThat(reply.getInReplyToId(), equalTo(comment.getId()));
comments = p.listReviewComments().toList();
assertEquals(2, comments.size());
assertThat(comments.size(), equalTo(2));
comment.update("Updated review comment");
comments = p.listReviewComments().toList();
comment = comments.get(0);
assertEquals("Updated review comment", comment.getBody());
assertThat(comment.getBody(), equalTo("Updated review comment"));
comment.delete();
comments = p.listReviewComments().toList();
@@ -171,12 +164,12 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
String name = "testPullRequestReviewRequests";
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "main", "## test");
// System.out.println(p.getUrl());
assertTrue(p.getRequestedReviewers().isEmpty());
assertThat(p.getRequestedReviewers().isEmpty(), is(true));
GHUser kohsuke2 = gitHub.getUser("kohsuke2");
p.requestReviewers(Collections.singletonList(kohsuke2));
p.refresh();
assertFalse(p.getRequestedReviewers().isEmpty());
assertThat(p.getRequestedReviewers().isEmpty(), is(false));
}
@Test
@@ -184,7 +177,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
String name = "testPullRequestTeamReviewRequests";
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "main", "## test");
// System.out.println(p.getUrl());
assertTrue(p.getRequestedReviewers().isEmpty());
assertThat(p.getRequestedReviewers().isEmpty(), is(true));
GHOrganization testOrg = gitHub.getOrganization("hub4j-test-org");
GHTeam testTeam = testOrg.getTeamBySlug("dummy-team");
@@ -227,7 +220,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
// make sure commit exists
GHCommit commit = repo.getCommit(p.getMergeCommitSha());
assertNotNull(commit);
assertThat(commit, notNullValue());
assertThat("Asked for PR information", mockGitHub.getRequestCount() - baseRequestCount, equalTo(i + 1));
@@ -249,15 +242,15 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
GHPullRequest pullRequest = getRepository().createPullRequest(prName, "test/stable", "main", "## test");
assertEquals("Pull request base branch is supposed to be " + originalBaseBranch,
originalBaseBranch,
pullRequest.getBase().getRef());
assertThat("Pull request base branch is supposed to be " + originalBaseBranch,
pullRequest.getBase().getRef(),
equalTo(originalBaseBranch));
GHPullRequest responsePullRequest = pullRequest.setBaseBranch(newBaseBranch);
assertEquals("Pull request base branch is supposed to be " + newBaseBranch,
newBaseBranch,
responsePullRequest.getBase().getRef());
assertThat("Pull request base branch is supposed to be " + newBaseBranch,
responsePullRequest.getBase().getRef(),
equalTo(newBaseBranch));
}
@Test
@@ -268,9 +261,9 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
GHPullRequest pullRequest = getRepository().createPullRequest(prName, "test/stable", "main", "## test");
assertEquals("Pull request base branch is supposed to be " + originalBaseBranch,
originalBaseBranch,
pullRequest.getBase().getRef());
assertThat("Pull request base branch is supposed to be " + originalBaseBranch,
pullRequest.getBase().getRef(),
equalTo(originalBaseBranch));
try {
pullRequest.setBaseBranch(newBaseBranch);
@@ -298,9 +291,9 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
outdatedPullRequest.refresh();
} while (outdatedPullRequest.getMergeableState().equalsIgnoreCase("unknown"));
assertEquals("Pull request is supposed to be not up to date",
"behind",
outdatedPullRequest.getMergeableState());
assertThat("Pull request is supposed to be not up to date",
outdatedPullRequest.getMergeableState(),
equalTo("behind"));
outdatedRef.updateTo("f567328eb81270487864963b7d7446953353f2b5", true);
@@ -329,14 +322,14 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
outdatedPullRequest.refresh();
} while (outdatedPullRequest.getMergeableState().equalsIgnoreCase("unknown"));
assertEquals("Pull request is supposed to be not up to date",
"behind",
outdatedPullRequest.getMergeableState());
assertThat("Pull request is supposed to be not up to date",
outdatedPullRequest.getMergeableState(),
equalTo("behind"));
outdatedPullRequest.updateBranch();
outdatedPullRequest.refresh();
assertNotEquals("Pull request is supposed to be up to date", "behind", outdatedPullRequest.getMergeableState());
assertThat("Pull request is supposed to be up to date", outdatedPullRequest.getMergeableState(), not("behind"));
outdatedPullRequest.close();
}
@@ -392,9 +385,9 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
.base("main")
.list()
.toList();
assertNotNull(prs);
assertEquals(1, prs.size());
assertEquals("test/stable", prs.get(0).getHead().getRef());
assertThat(prs, notNullValue());
assertThat(prs.size(), equalTo(1));
assertThat(prs.get(0).getHead().getRef(), equalTo("test/stable"));
}
@Test
@@ -411,9 +404,9 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
.base("main")
.list()
.toList();
assertNotNull(prs);
assertEquals(1, prs.size());
assertEquals("test/stable", prs.get(0).getHead().getRef());
assertThat(prs, notNullValue());
assertThat(prs.size(), equalTo(1));
assertThat(prs.get(0).getHead().getRef(), equalTo("test/stable"));
}
@Test
@@ -424,12 +417,12 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
p.setLabels(label);
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
assertEquals(1, labels.size());
assertThat(labels.size(), equalTo(1));
GHLabel savedLabel = labels.iterator().next();
assertEquals(label, savedLabel.getName());
assertNotNull(savedLabel.getId());
assertNotNull(savedLabel.getNodeId());
assertFalse(savedLabel.isDefault());
assertThat(savedLabel.getName(), equalTo(label));
assertThat(savedLabel.getId(), notNullValue());
assertThat(savedLabel.getNodeId(), notNullValue());
assertThat(savedLabel.isDefault(), is(false));
}
@Test
@@ -441,7 +434,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
String addedLabel3 = "addLabels_label_name_3";
List<GHLabel> resultingLabels = p.addLabels(addedLabel1);
assertEquals(1, resultingLabels.size());
assertThat(resultingLabels.size(), equalTo(1));
GHLabel ghLabel = resultingLabels.get(0);
assertThat(ghLabel.getName(), equalTo(addedLabel1));
@@ -450,7 +443,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
// multiple labels can be added with one api call
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 1));
assertEquals(3, resultingLabels.size());
assertThat(resultingLabels.size(), equalTo(3));
assertThat(resultingLabels,
containsInAnyOrder(hasProperty("name", equalTo(addedLabel1)),
hasProperty("name", equalTo(addedLabel2)),
@@ -476,7 +469,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
Collection<GHLabel> labels = p1.addLabels(addedLabel1);
assertEquals(2, labels.size());
assertThat(labels.size(), equalTo(2));
assertThat(labels,
containsInAnyOrder(hasProperty("name", equalTo(addedLabel1)),
hasProperty("name", equalTo(addedLabel2))));
@@ -492,7 +485,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
p.setLabels(label1, label2, label3);
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
assertEquals(3, labels.size());
assertThat(labels.size(), equalTo(3));
GHLabel ghLabel3 = labels.stream().filter(label -> label3.equals(label.getName())).findFirst().get();
int requestCount = mockGitHub.getRequestCount();
@@ -500,8 +493,8 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
// each label deleted is a separate api call
assertThat(mockGitHub.getRequestCount(), equalTo(requestCount + 2));
assertEquals(1, resultingLabels.size());
assertEquals(label1, resultingLabels.get(0).getName());
assertThat(resultingLabels.size(), equalTo(1));
assertThat(resultingLabels.get(0).getName(), equalTo(label1));
// Removing some labels that are not present does not throw
// This is consistent with earlier behavior and with addLabels()
@@ -523,22 +516,22 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
GHMyself user = gitHub.getMyself();
p.assignTo(user);
assertEquals(user, getRepository().getPullRequest(p.getNumber()).getAssignee());
assertThat(getRepository().getPullRequest(p.getNumber()).getAssignee(), equalTo(user));
}
@Test
public void getUserTest() throws IOException {
GHPullRequest p = getRepository().createPullRequest("getUserTest", "test/stable", "main", "## test");
GHPullRequest prSingle = getRepository().getPullRequest(p.getNumber());
assertNotNull(prSingle.getUser().getRoot());
assertThat(prSingle.getUser().getRoot(), notNullValue());
prSingle.getMergeable();
assertNotNull(prSingle.getUser().getRoot());
assertThat(prSingle.getUser().getRoot(), notNullValue());
PagedIterable<GHPullRequest> ghPullRequests = getRepository().listPullRequests(GHIssueState.OPEN);
for (GHPullRequest pr : ghPullRequests) {
assertNotNull(pr.getUser().getRoot());
assertThat(pr.getUser().getRoot(), notNullValue());
pr.getMergeable();
assertNotNull(pr.getUser().getRoot());
assertThat(pr.getUser().getRoot(), notNullValue());
}
}

View File

@@ -6,6 +6,9 @@ import java.io.IOException;
import java.util.List;
import java.util.NoSuchElementException;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
public static int MAX_ITERATIONS = 3;
@@ -25,7 +28,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
// check the statistics are accurate
List<GHRepositoryStatistics.ContributorStats> list = stats.toList();
assertEquals(99, list.size());
assertThat(list.size(), equalTo(99));
// find a particular developer
// TODO: Add an accessor method for this instead of having use a loop.
@@ -33,22 +36,22 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
final String authorLogin = "kohsuke";
for (GHRepositoryStatistics.ContributorStats statsForAuthor : list) {
if (authorLogin.equals(statsForAuthor.getAuthor().getLogin())) {
assertEquals(715, statsForAuthor.getTotal());
assertEquals("kohsuke made 715 contributions over 494 weeks", statsForAuthor.toString());
assertThat(statsForAuthor.getTotal(), equalTo(715));
assertThat(statsForAuthor.toString(), equalTo("kohsuke made 715 contributions over 494 weeks"));
List<GHRepositoryStatistics.ContributorStats.Week> weeks = statsForAuthor.getWeeks();
assertEquals(494, weeks.size());
assertThat(weeks.size(), equalTo(494));
try {
// check a particular week
// TODO: Maybe add a convenience method to get the week
// containing a certain date (Java.Util.Date).
GHRepositoryStatistics.ContributorStats.Week week = statsForAuthor.getWeek(1541289600);
assertEquals(63, week.getNumberOfAdditions());
assertEquals(56, week.getNumberOfDeletions());
assertEquals(5, week.getNumberOfCommits());
assertEquals("Week starting 1541289600 - Additions: 63, Deletions: 56, Commits: 5",
week.toString());
assertThat(week.getNumberOfAdditions(), equalTo(63));
assertThat(week.getNumberOfDeletions(), equalTo(56));
assertThat(week.getNumberOfCommits(), equalTo(5));
assertThat(week.toString(),
equalTo("Week starting 1541289600 - Additions: 63, Deletions: 56, Commits: 5"));
} catch (NoSuchElementException e) {
fail("Did not find week 1546128000");
}
@@ -57,7 +60,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
}
}
assertTrue("Did not find author " + authorLogin, developerFound);
assertThat("Did not find author " + authorLogin, developerFound, is(true));
}
@Test
@@ -89,20 +92,20 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
Boolean foundWeek = false;
for (GHRepositoryStatistics.CommitActivity item : list) {
if (item.getWeek() == 1566691200) {
assertEquals(6, item.getTotal());
assertThat(item.getTotal(), equalTo(6));
List<Integer> days = item.getDays();
assertEquals(0L, (long) days.get(0));
assertEquals(0L, (long) days.get(1));
assertEquals(1L, (long) days.get(2));
assertEquals(0L, (long) days.get(3));
assertEquals(0L, (long) days.get(4));
assertEquals(1L, (long) days.get(5));
assertEquals(4L, (long) days.get(6));
assertThat((long) days.get(0), equalTo(0L));
assertThat((long) days.get(1), equalTo(0L));
assertThat((long) days.get(2), equalTo(1L));
assertThat((long) days.get(3), equalTo(0L));
assertThat((long) days.get(4), equalTo(0L));
assertThat((long) days.get(5), equalTo(1L));
assertThat((long) days.get(6), equalTo(4L));
foundWeek = true;
break;
}
}
assertTrue("Could not find week starting 1546128000", foundWeek);
assertThat("Could not find week starting 1546128000", foundWeek, is(true));
}
@Test
@@ -132,14 +135,14 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
Boolean foundWeek = false;
for (GHRepositoryStatistics.CodeFrequency item : stats) {
if (item.getWeekTimestamp() == 1535241600) {
assertEquals(185L, item.getAdditions());
assertEquals(-243L, item.getDeletions());
assertEquals("Week starting 1535241600 has 185 additions and 243 deletions", item.toString());
assertThat(item.getAdditions(), equalTo(185L));
assertThat(item.getDeletions(), equalTo(-243L));
assertThat(item.toString(), equalTo("Week starting 1535241600 has 185 additions and 243 deletions"));
foundWeek = true;
break;
}
}
assertTrue("Could not find week starting 1535241600", foundWeek);
assertThat("Could not find week starting 1535241600", foundWeek, is(true));
}
@Test
@@ -164,11 +167,11 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
// check the statistics are accurate
List<Integer> allCommits = stats.getAllCommits();
assertEquals(52, allCommits.size());
assertEquals(2, (int) allCommits.get(2));
assertThat(allCommits.size(), equalTo(52));
assertThat((int) allCommits.get(2), equalTo(2));
List<Integer> ownerCommits = stats.getOwnerCommits();
assertEquals(52, ownerCommits.size());
assertThat(ownerCommits.size(), equalTo(52));
// The values depend on who is running the test.
}
@@ -199,13 +202,13 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
if (item.getDayOfWeek() == 2 && item.getHourOfDay() == 10) {
// TODO: Make an easier access method. Perhaps wrap in an
// object and have a method such as GetCommits(1, 16).
assertEquals(16L, item.getNumberOfCommits());
assertEquals("Day 2 Hour 10: 16 commits", item.toString());
assertThat(item.getNumberOfCommits(), equalTo(16L));
assertThat(item.toString(), equalTo("Day 2 Hour 10: 16 commits"));
hourFound = true;
break;
}
}
assertTrue("Hour 10 for Day 2 not found.", hourFound);
assertThat("Hour 10 for Day 2 not found.", hourFound, is(true));
}
protected GHRepository getRepository() throws IOException {

View File

@@ -110,7 +110,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
.getCommitShortInfo()
.getVerification();
assertEquals(GPGVERIFY_ERROR, verification.getReason());
assertThat(verification.getReason(), equalTo(GPGVERIFY_ERROR));
}
@Test
@@ -127,7 +127,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
.getCommitShortInfo()
.getVerification();
assertEquals(UNKNOWN_SIGNATURE_TYPE, verification.getReason());
assertThat(verification.getReason(), equalTo(UNKNOWN_SIGNATURE_TYPE));
}
@Test
@@ -167,11 +167,11 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
@Test
public void subscription() throws Exception {
GHRepository r = getRepository();
assertNull(r.getSubscription());
assertThat(r.getSubscription(), nullValue());
GHSubscription s = r.subscribe(true, false);
try {
assertEquals(s.getRepository(), r);
assertThat(r, equalTo(s.getRepository()));
assertThat(s.isIgnored(), equalTo(false));
assertThat(s.isSubscribed(), equalTo(true));
assertThat(s.getRepositoryUrl().toString(), containsString("/repos/hub4j-test-org/github-api"));
@@ -183,7 +183,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
s.delete();
}
assertNull(r.getSubscription());
assertThat(r.getSubscription(), nullValue());
}
@Test
@@ -193,11 +193,11 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
String repoName = "test-repo-public";
GHRepository repo = gitHub.createRepository(repoName).private_(false).create();
try {
assertFalse(repo.isPrivate());
assertThat(repo.isPrivate(), is(false));
repo.setPrivate(true);
assertTrue(myself.getRepository(repoName).isPrivate());
assertThat(myself.getRepository(repoName).isPrivate(), is(true));
repo.setPrivate(false);
assertFalse(myself.getRepository(repoName).isPrivate());
assertThat(myself.getRepository(repoName).isPrivate(), is(false));
} finally {
repo.delete();
}
@@ -225,25 +225,25 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
.wiki(false)
.done();
assertTrue(updated.isAllowMergeCommit());
assertFalse(updated.isAllowRebaseMerge());
assertFalse(updated.isAllowSquashMerge());
assertTrue(updated.isDeleteBranchOnMerge());
assertTrue(updated.isPrivate());
assertFalse(updated.hasDownloads());
assertFalse(updated.hasIssues());
assertFalse(updated.hasProjects());
assertFalse(updated.hasWiki());
assertThat(updated.isAllowMergeCommit(), is(true));
assertThat(updated.isAllowRebaseMerge(), is(false));
assertThat(updated.isAllowSquashMerge(), is(false));
assertThat(updated.isDeleteBranchOnMerge(), is(true));
assertThat(updated.isPrivate(), is(true));
assertThat(updated.hasDownloads(), is(false));
assertThat(updated.hasIssues(), is(false));
assertThat(updated.hasProjects(), is(false));
assertThat(updated.hasWiki(), is(false));
assertEquals(homepage, updated.getHomepage());
assertEquals(description, updated.getDescription());
assertThat(updated.getHomepage(), equalTo(homepage));
assertThat(updated.getDescription(), equalTo(description));
// test the other merge option and making the repo public again
GHRepository redux = updated.update().allowMergeCommit(false).allowRebaseMerge(true).private_(false).done();
assertFalse(redux.isAllowMergeCommit());
assertTrue(redux.isAllowRebaseMerge());
assertFalse(redux.isPrivate());
assertThat(redux.isAllowMergeCommit(), is(false));
assertThat(redux.isAllowRebaseMerge(), is(true));
assertThat(redux.isPrivate(), is(false));
String updatedDescription = "updated using set()";
redux = redux.set().description(updatedDescription);
@@ -256,23 +256,23 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
snapshotNotAllowed();
final String repoName = "test-repo-visibility";
final GHRepository repo = getTempRepository(repoName);
assertEquals(Visibility.PUBLIC, repo.getVisibility());
assertThat(repo.getVisibility(), equalTo(Visibility.PUBLIC));
repo.setVisibility(Visibility.INTERNAL);
assertEquals(Visibility.INTERNAL,
gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility());
assertThat(gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility(),
equalTo(Visibility.INTERNAL));
repo.setVisibility(Visibility.PRIVATE);
assertEquals(Visibility.PRIVATE,
gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility());
assertThat(gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility(),
equalTo(Visibility.PRIVATE));
repo.setVisibility(Visibility.PUBLIC);
assertEquals(Visibility.PUBLIC,
gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility());
assertThat(gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility(),
equalTo(Visibility.PUBLIC));
// deliberately bogus response in snapshot
assertEquals(Visibility.UNKNOWN,
gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility());
assertThat(gitHub.getRepository(repo.getOwnerName() + "/" + repo.getName()).getVisibility(),
equalTo(Visibility.UNKNOWN));
}
@Test
@@ -283,7 +283,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
for (GHRepository.Contributor c : r.listContributors()) {
if (c.getLogin().equals("kohsuke")) {
assertTrue(c.getContributions() > 0);
assertThat(c.getContributions() > 0, is(true));
kohsuke = true;
}
if (i++ > 5) {
@@ -291,22 +291,22 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
}
}
assertTrue(kohsuke);
assertThat(kohsuke, is(true));
}
@Test
public void getPermission() throws Exception {
kohsuke();
GHRepository r = gitHub.getRepository("hub4j-test-org/test-permission");
assertEquals(GHPermissionType.ADMIN, r.getPermission("kohsuke"));
assertEquals(GHPermissionType.READ, r.getPermission("dude"));
assertThat(r.getPermission("kohsuke"), equalTo(GHPermissionType.ADMIN));
assertThat(r.getPermission("dude"), equalTo(GHPermissionType.READ));
r = gitHub.getOrganization("apache").getRepository("groovy");
try {
r.getPermission("jglick");
fail();
} catch (HttpException x) {
// x.printStackTrace(); // good
assertEquals(403, x.getResponseCode());
assertThat(x.getResponseCode(), equalTo(403));
}
if (false) {
@@ -326,7 +326,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
try {
// add the repository that have latest release
GHRelease release = gitHub.getRepository("kamontat/CheckIDNumber").getLatestRelease();
assertEquals("v3.0", release.getTagName());
assertThat(release.getTagName(), equalTo("v3.0"));
} catch (IOException e) {
e.printStackTrace();
fail();
@@ -347,7 +347,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
GHUser colabUser = collabs.byLogin("jimmysombrero");
assertEquals(colabUser.getName(), user.getName());
assertThat(user.getName(), equalTo(colabUser.getName()));
}
@Test
@@ -355,7 +355,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
try {
// add the repository that `NOT` have latest release
GHRelease release = gitHub.getRepository("kamontat/Java8Example").getLatestRelease();
assertNull(release);
assertThat(release, nullValue());
} catch (IOException e) {
e.printStackTrace();
fail();
@@ -365,32 +365,32 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
@Test
public void listReleases() throws IOException {
PagedIterable<GHRelease> releases = gitHub.getOrganization("github").getRepository("hub").listReleases();
assertTrue(releases.iterator().hasNext());
assertThat(releases.iterator().hasNext(), is(true));
}
@Test
public void getReleaseExists() throws IOException {
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getRelease(6839710);
assertEquals("v2.3.0-pre10", release.getTagName());
assertThat(release.getTagName(), equalTo("v2.3.0-pre10"));
}
@Test
public void getReleaseDoesNotExist() throws IOException {
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getRelease(Long.MAX_VALUE);
assertNull(release);
assertThat(release, nullValue());
}
@Test
public void getReleaseByTagNameExists() throws IOException {
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getReleaseByTagName("v2.3.0-pre10");
assertNotNull(release);
assertEquals("v2.3.0-pre10", release.getTagName());
assertThat(release, notNullValue());
assertThat(release.getTagName(), equalTo("v2.3.0-pre10"));
}
@Test
public void getReleaseByTagNameDoesNotExist() throws IOException {
GHRelease release = getRepository().getReleaseByTagName("foo-bar-baz");
assertNull(release);
assertThat(release, nullValue());
}
@Test
@@ -399,7 +399,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
String mainLanguage = r.getLanguage();
assertThat(mainLanguage, equalTo("Java"));
Map<String, Long> languages = r.listLanguages();
assertTrue(languages.containsKey(mainLanguage));
assertThat(languages.containsKey(mainLanguage), is(true));
assertThat(languages.get("Java"), greaterThan(100000L));
}
@@ -440,9 +440,9 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
.list();
GHRepository u = r.iterator().next();
// System.out.println(u.getName());
assertNotNull(u.getId());
assertEquals("Assembly", u.getLanguage());
assertTrue(r.getTotalCount() > 0);
assertThat(u.getId(), notNullValue());
assertThat(u.getLanguage(), equalTo("Assembly"));
assertThat(r.getTotalCount() > 0, is(true));
}
@Test // issue #162
@@ -454,23 +454,24 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
String content1 = content.getContent();
String content2 = r.getFileContent(content.getPath(), "gh-pages").getContent();
// System.out.println(content.getPath());
assertEquals(content1, content2);
assertThat(content2, equalTo(content1));
}
}
}
@Test
public void markDown() throws Exception {
assertEquals("<p><strong>Test日本語</strong></p>", IOUtils.toString(gitHub.renderMarkdown("**Test日本語**")).trim());
assertThat(IOUtils.toString(gitHub.renderMarkdown("**Test日本語**")).trim(),
equalTo("<p><strong>Test日本語</strong></p>"));
String actual = IOUtils.toString(
gitHub.getRepository("hub4j/github-api").renderMarkdown("@kohsuke to fix issue #1", MarkdownMode.GFM));
// System.out.println(actual);
assertTrue(actual.contains("href=\"https://github.com/kohsuke\""));
assertTrue(actual.contains("href=\"https://github.com/hub4j/github-api/pull/1\""));
assertTrue(actual.contains("class=\"user-mention\""));
assertTrue(actual.contains("class=\"issue-link "));
assertTrue(actual.contains("to fix issue"));
assertThat(actual.contains("href=\"https://github.com/kohsuke\""), is(true));
assertThat(actual.contains("href=\"https://github.com/hub4j/github-api/pull/1\""), is(true));
assertThat(actual.contains("class=\"user-mention\""), is(true));
assertThat(actual.contains("class=\"issue-link "), is(true));
assertThat(actual.contains("to fix issue"), is(true));
}
@Test
@@ -486,9 +487,9 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
r.allowRebaseMerge(false);
r = gitHub.getRepository(r.getFullName());
assertFalse(r.isAllowMergeCommit());
assertFalse(r.isAllowRebaseMerge());
assertTrue(r.isAllowSquashMerge());
assertThat(r.isAllowMergeCommit(), is(false));
assertThat(r.isAllowRebaseMerge(), is(false));
assertThat(r.isAllowSquashMerge(), is(true));
// flip the last value
r.allowMergeCommit(true);
@@ -496,15 +497,15 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
r.allowSquashMerge(false);
r = gitHub.getRepository(r.getFullName());
assertTrue(r.isAllowMergeCommit());
assertTrue(r.isAllowRebaseMerge());
assertFalse(r.isAllowSquashMerge());
assertThat(r.isAllowMergeCommit(), is(true));
assertThat(r.isAllowRebaseMerge(), is(true));
assertThat(r.isAllowSquashMerge(), is(false));
}
@Test
public void getDeleteBranchOnMerge() throws IOException {
GHRepository r = getRepository();
assertNotNull(r.isDeleteBranchOnMerge());
assertThat(r.isDeleteBranchOnMerge(), notNullValue());
}
@Test
@@ -515,13 +516,13 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
r.deleteBranchOnMerge(true);
r = gitHub.getRepository(r.getFullName());
assertTrue(r.isDeleteBranchOnMerge());
assertThat(r.isDeleteBranchOnMerge(), is(true));
// flip the last value
r.deleteBranchOnMerge(false);
r = gitHub.getRepository(r.getFullName());
assertFalse(r.isDeleteBranchOnMerge());
assertThat(r.isDeleteBranchOnMerge(), is(false));
}
@Test
@@ -556,7 +557,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
topics = new ArrayList<>();
repo.setTopics(topics);
assertTrue("Topics can be set to empty", repo.listTopics().isEmpty());
assertThat("Topics can be set to empty", repo.listTopics().isEmpty(), is(true));
}
@Test
@@ -733,7 +734,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
snapshotNotAllowed();
GHRepository repo = getTempRepository();
int watchersCount = repo.getWatchersCount();
assertEquals(10, watchersCount);
assertThat(watchersCount, equalTo(10));
}
@Test
@@ -741,7 +742,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
snapshotNotAllowed();
GHRepository repo = getTempRepository();
int stargazersCount = repo.getStargazersCount();
assertEquals(10, stargazersCount);
assertThat(stargazersCount, equalTo(10));
}
@Test

View File

@@ -7,8 +7,6 @@ import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
*
@@ -45,11 +43,11 @@ public class GHTagTest extends AbstractGitHubWireMockTest {
String tagType = "commit";
GHTagObject tag = repo.createTag(tagName, tagMessage, commitSha, tagType);
assertEquals(tagName, tag.getTag());
assertEquals(tagMessage, tag.getMessage());
assertEquals(commitSha, tag.getObject().getSha());
assertFalse(tag.getVerification().isVerified());
assertEquals(tag.getVerification().getReason(), GHVerification.Reason.UNSIGNED);
assertThat(tag.getTag(), equalTo(tagName));
assertThat(tag.getMessage(), equalTo(tagMessage));
assertThat(tag.getObject().getSha(), equalTo(commitSha));
assertThat(tag.getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.UNSIGNED, equalTo(tag.getVerification().getReason()));
assertThat(tag.getUrl(),
containsString("/repos/hub4j-test-org/github-api/git/tags/e7aa6d4afbaa48669f0bbe11ca3c4d787b2b153c"));
assertThat(tag.getOwner().getId(), equalTo(repo.getId()));
@@ -57,7 +55,7 @@ public class GHTagTest extends AbstractGitHubWireMockTest {
// Make a reference to the newly created tag.
GHRef ref = repo.createRef("refs/tags/" + tagName, tag.getSha());
assertNotNull(ref);
assertThat(ref, notNullValue());
}
protected GHRepository getRepository() throws IOException {

View File

@@ -4,6 +4,8 @@ import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo;
public class GHTeamBuilderTest extends AbstractGitHubWireMockTest {
@Test
@@ -23,10 +25,10 @@ public class GHTeamBuilderTest extends AbstractGitHubWireMockTest {
.parentTeamId(parentTeam.getId())
.create();
assertEquals(description, childTeam.getDescription());
assertEquals(childTeamSlug, childTeam.getName());
assertEquals(childTeamSlug, childTeam.getSlug());
assertEquals(GHTeam.Privacy.CLOSED, childTeam.getPrivacy());
assertThat(childTeam.getDescription(), equalTo(description));
assertThat(childTeam.getName(), equalTo(childTeamSlug));
assertThat(childTeam.getSlug(), equalTo(childTeamSlug));
assertThat(childTeam.getPrivacy(), equalTo(GHTeam.Privacy.CLOSED));
}
}

View File

@@ -7,7 +7,8 @@ import java.io.IOException;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
public class GHTeamTest extends AbstractGitHubWireMockTest {
@@ -23,7 +24,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
// Check that it was set correctly.
team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertEquals(description, team.getDescription());
assertThat(team.getDescription(), equalTo(description));
description += "Modified";
@@ -32,7 +33,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
// Check that it was set correctly.
team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertEquals(description, team.getDescription());
assertThat(team.getDescription(), equalTo(description));
}
@Test
@@ -43,7 +44,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
List<GHUser> admins = team.listMembers("admin").toList();
assertNotNull(admins);
assertThat(admins, notNullValue());
assertThat("One admin in dummy team", admins.size() == 1);
assertThat("Specific user in admin team",
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
@@ -71,7 +72,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
// Check that it was set correctly.
team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertEquals(privacy, team.getPrivacy());
assertThat(team.getPrivacy(), equalTo(privacy));
privacy = Privacy.SECRET;
@@ -80,7 +81,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
// Check that it was set correctly.
team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertEquals(privacy, team.getPrivacy());
assertThat(team.getPrivacy(), equalTo(privacy));
}
@Test
@@ -91,8 +92,8 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
GHTeam team = org.getTeamBySlug(teamSlug);
Set<GHTeam> result = team.listChildTeams().toSet();
assertEquals(1, result.size());
assertEquals("child-team-for-dummy", result.toArray(new GHTeam[]{})[0].getName());
assertThat(result.size(), equalTo(1));
assertThat(result.toArray(new GHTeam[]{})[0].getName(), equalTo("child-team-for-dummy"));
}
@Test
@@ -103,7 +104,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
GHTeam team = org.getTeamBySlug(teamSlug);
Set<GHTeam> result = team.listChildTeams().toSet();
assertEquals(0, result.size());
assertThat(result.size(), equalTo(0));
}
}

View File

@@ -10,7 +10,6 @@ import java.util.Arrays;
import java.util.Date;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
private static String REPO_NAME = "hub4j-test-org/GHTreeBuilderTest";
@@ -64,8 +63,8 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
updateTree();
assertEquals(CONTENT_SCRIPT.length(), getFileSize(PATH_SCRIPT));
assertEquals(CONTENT_README.length(), getFileSize(PATH_README));
assertThat(getFileSize(PATH_SCRIPT), equalTo(CONTENT_SCRIPT.length()));
assertThat(getFileSize(PATH_README), equalTo(CONTENT_README.length()));
}
@Test
@@ -78,8 +77,8 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
updateTree();
assertEquals((long) CONTENT_DATA1.length, getFileSize(PATH_DATA1));
assertEquals((long) CONTENT_DATA2.length, getFileSize(PATH_DATA2));
assertThat(getFileSize(PATH_DATA1), equalTo((long) CONTENT_DATA1.length));
assertThat(getFileSize(PATH_DATA2), equalTo((long) CONTENT_DATA2.length));
}
@Test
@@ -91,10 +90,10 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
GHCommit commit = updateTree();
assertEquals((long) CONTENT_SCRIPT.length(), getFileSize(PATH_SCRIPT));
assertEquals((long) CONTENT_README.length(), getFileSize(PATH_README));
assertEquals((long) CONTENT_DATA1.length, getFileSize(PATH_DATA1));
assertEquals((long) CONTENT_DATA2.length, getFileSize(PATH_DATA2));
assertThat(getFileSize(PATH_SCRIPT), equalTo((long) CONTENT_SCRIPT.length()));
assertThat(getFileSize(PATH_README), equalTo((long) CONTENT_README.length()));
assertThat(getFileSize(PATH_DATA1), equalTo((long) CONTENT_DATA1.length));
assertThat(getFileSize(PATH_DATA2), equalTo((long) CONTENT_DATA2.length));
assertThat(commit.getCommitShortInfo().getAuthor().getEmail(), equalTo("author@author.com"));
assertThat(commit.getCommitShortInfo().getCommitter().getEmail(), equalTo("committer@committer.com"));

View File

@@ -1,19 +1,22 @@
package org.kohsuke.github;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.util.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
public class GHUserTest extends AbstractGitHubWireMockTest {
@Test
public void listFollowsAndFollowers() throws IOException {
GHUser u = gitHub.getUser("rtyler");
assertNotEquals(count30(u.listFollowers()), count30(u.listFollows()));
assertThat(count30(u.listFollows()), not(count30(u.listFollowers())));
}
private Set<GHUser> count30(PagedIterable<GHUser> l) {
@@ -22,7 +25,7 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
for (int i = 0; i < 30 && itr.hasNext(); i++) {
users.add(itr.next());
}
assertEquals(30, users.size());
assertThat(users.size(), equalTo(30));
return users;
}
@@ -31,14 +34,14 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
GHUser u = gitHub.getUser("rtyler");
List<GHKey> ghKeys = new ArrayList<>(u.getKeys());
assertEquals(3, ghKeys.size());
assertThat(ghKeys.size(), equalTo(3));
Collections.sort(ghKeys, new Comparator<GHKey>() {
@Override
public int compare(GHKey ghKey, GHKey t1) {
return ghKey.getId() - t1.getId();
}
});
assertEquals(1066173, ghKeys.get(0).getId());
assertThat(ghKeys.get(0).getId(), equalTo(1066173));
assertThat(ghKeys.get(0).getTitle(), nullValue());
assertThat(ghKeys.get(0).getUrl(), nullValue());
assertThat(ghKeys.get(0).isVerified(), equalTo(false));
@@ -46,23 +49,20 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
containsString(
"title=<null>,id=1066173,key=ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAueiy12T5bvFhsc9YjfLc3aVIxgySd3gDxQWy/bletIoZL8omKmzocBYJ7F58U1asoyfWsy2ToTOY8jJp1eToXmbD6L5+xvHba0A7djYh9aQRrFam7doKQ0zp0ZSUF6+R1v0OM4nnWqK4n2ECIYd+Bdzrp+xA5+XlW3ZSNzlnW2BeWznzmgRMcp6wI+zQ9GMHWviR1cxpml5Z6wrxTZ0aX91btvnNPqoOGva976B6e6403FOEkkIFTk6CC1TFKwc/VjbqxYBg4kU0JhiTP+iEZibcQrYjWdYUgAotYbFVe5/DneHMLNsMPdeihba4PUwt62rXyNegenuCRmCntLcaFQ=="));
assertEquals(
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAueiy12T5bvFhsc9YjfLc3aVIxgySd3gDxQWy/bletIoZL8omKmzocBYJ7F58U1asoyfWsy2ToTOY8jJp1eToXmbD6L5+xvHba0A7djYh9aQRrFam7doKQ0zp0ZSUF6+R1v0OM4nnWqK4n2ECIYd+Bdzrp+xA5+XlW3ZSNzlnW2BeWznzmgRMcp6wI+zQ9GMHWviR1cxpml5Z6wrxTZ0aX91btvnNPqoOGva976B6e6403FOEkkIFTk6CC1TFKwc/VjbqxYBg4kU0JhiTP+iEZibcQrYjWdYUgAotYbFVe5/DneHMLNsMPdeihba4PUwt62rXyNegenuCRmCntLcaFQ==",
ghKeys.get(0).getKey());
assertEquals(28136459, ghKeys.get(1).getId());
assertThat(ghKeys.get(0).getKey(),
equalTo("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAueiy12T5bvFhsc9YjfLc3aVIxgySd3gDxQWy/bletIoZL8omKmzocBYJ7F58U1asoyfWsy2ToTOY8jJp1eToXmbD6L5+xvHba0A7djYh9aQRrFam7doKQ0zp0ZSUF6+R1v0OM4nnWqK4n2ECIYd+Bdzrp+xA5+XlW3ZSNzlnW2BeWznzmgRMcp6wI+zQ9GMHWviR1cxpml5Z6wrxTZ0aX91btvnNPqoOGva976B6e6403FOEkkIFTk6CC1TFKwc/VjbqxYBg4kU0JhiTP+iEZibcQrYjWdYUgAotYbFVe5/DneHMLNsMPdeihba4PUwt62rXyNegenuCRmCntLcaFQ=="));
assertThat(ghKeys.get(1).getId(), equalTo(28136459));
assertThat(ghKeys.get(1).getTitle(), nullValue());
assertThat(ghKeys.get(1).getUrl(), nullValue());
assertThat(ghKeys.get(1).isVerified(), equalTo(false));
assertEquals(
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTU0s5OKCC6VpKZGL9NJD4mNLY0AtujkVB1JkkuQ4OkMi2YGUHJtGhTbTwEVhNxpm0x2dM5KSzse6MLDYuGBW0qkE/VVuD9+9I73hbq461KqP0+WlupNh+Qc86kbiLBDv64+vWc+50mp1dbINpoM5xvaPYxgjnemydPv7vu5bhCHBugW7aN8VcLgfFgcp8vZCEanMtd3hIRjRU8v8Skk233ZGu1bXkG8iIOBQPabvEtZ0VDMg9pT3Q1R6lnnKqfCwHXd6zP6uAtejFSxvKRGKpu3OLGQMHwk7NlImVuhkVdaEFBq7pQtpOaGuP2eLKcN1wy5jsTYE+ZB6pvHCi2ecb",
ghKeys.get(1).getKey());
assertEquals(31452581, ghKeys.get(2).getId());
assertThat(ghKeys.get(1).getKey(),
equalTo("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTU0s5OKCC6VpKZGL9NJD4mNLY0AtujkVB1JkkuQ4OkMi2YGUHJtGhTbTwEVhNxpm0x2dM5KSzse6MLDYuGBW0qkE/VVuD9+9I73hbq461KqP0+WlupNh+Qc86kbiLBDv64+vWc+50mp1dbINpoM5xvaPYxgjnemydPv7vu5bhCHBugW7aN8VcLgfFgcp8vZCEanMtd3hIRjRU8v8Skk233ZGu1bXkG8iIOBQPabvEtZ0VDMg9pT3Q1R6lnnKqfCwHXd6zP6uAtejFSxvKRGKpu3OLGQMHwk7NlImVuhkVdaEFBq7pQtpOaGuP2eLKcN1wy5jsTYE+ZB6pvHCi2ecb"));
assertThat(ghKeys.get(2).getId(), equalTo(31452581));
assertThat(ghKeys.get(2).getTitle(), nullValue());
assertThat(ghKeys.get(2).getUrl(), nullValue());
assertThat(ghKeys.get(2).isVerified(), equalTo(false));
assertEquals(
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC3JhH2FZBDmHLjXTcBoV6tdcYKmsQ7sgu8k1RsUhwxGsXm65+Cuas6GcMVoA1DncKfJGQkulHDFiTxIROIBmedh9/otHWBlZ4HqYZ4MQ1A8W5quULkXwX/kF+UdRBUxFvjigibEbuHB+LARVxRRzFlPnTSE9rAfAv8OOEsb3lNUGT/IGhN8w1vwe8GclB90tgqN1RBDgrVqwLFwn5AfrW9kUIa2f2oT4RjYu1OrhKhVIIzfHADo85aD+s8wEhqwI96BCJG3qTWrypoHwBUoj1O6Ak5CGc1iKz9o8XyTMjudRt2ddCjfOtxsuwSlTbVtQXJGIpgKviX1sgh4pPvGh7BVAFP+mdAK4F+mEugDnuj47GO/K5KGGDRCL56kh9+h28l4q/+fZvp7DhtmSN2EzrVAdQFskF8yY/6Xit/aAvjeKm03DcjbylSXbG26EJefaLHlwYFq2mUFRMak25wuuCZS71GF3RC3Sl/bMoxBKRYkyfYtGafeaYTFNGn8Dbd+hfVUCz31ebI8cvmlQR5b5AbCre3T7HTVgw8FKbAxWRf1Fio56PnqHsj+sT1KVj255Zo1F8iD9GrgERSVAlkh5bY/CKszQ8ZSd01c9Qp2a47/gR7XAAbxhzGHP+cSOlrqDlJ24fbPtcpVsM0llqKUcxpmoOBFNboRmE1QqnSmAf9ww==",
ghKeys.get(2).getKey());
assertThat(ghKeys.get(2).getKey(),
equalTo("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC3JhH2FZBDmHLjXTcBoV6tdcYKmsQ7sgu8k1RsUhwxGsXm65+Cuas6GcMVoA1DncKfJGQkulHDFiTxIROIBmedh9/otHWBlZ4HqYZ4MQ1A8W5quULkXwX/kF+UdRBUxFvjigibEbuHB+LARVxRRzFlPnTSE9rAfAv8OOEsb3lNUGT/IGhN8w1vwe8GclB90tgqN1RBDgrVqwLFwn5AfrW9kUIa2f2oT4RjYu1OrhKhVIIzfHADo85aD+s8wEhqwI96BCJG3qTWrypoHwBUoj1O6Ak5CGc1iKz9o8XyTMjudRt2ddCjfOtxsuwSlTbVtQXJGIpgKviX1sgh4pPvGh7BVAFP+mdAK4F+mEugDnuj47GO/K5KGGDRCL56kh9+h28l4q/+fZvp7DhtmSN2EzrVAdQFskF8yY/6Xit/aAvjeKm03DcjbylSXbG26EJefaLHlwYFq2mUFRMak25wuuCZS71GF3RC3Sl/bMoxBKRYkyfYtGafeaYTFNGn8Dbd+hfVUCz31ebI8cvmlQR5b5AbCre3T7HTVgw8FKbAxWRf1Fio56PnqHsj+sT1KVj255Zo1F8iD9GrgERSVAlkh5bY/CKszQ8ZSd01c9Qp2a47/gR7XAAbxhzGHP+cSOlrqDlJ24fbPtcpVsM0llqKUcxpmoOBFNboRmE1QqnSmAf9ww=="));
}
@Test
@@ -71,11 +71,11 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
Iterator<GHRepository> itr = user.listRepositories().iterator();
int i = 0;
for (; i < 115; i++) {
assertTrue(itr.hasNext());
assertThat(itr.hasNext(), is(true));
GHRepository r = itr.next();
// System.out.println(r.getFullName());
assertNotNull(r.getUrl());
assertNotEquals(0L, r.getId());
assertThat(r.getUrl(), notNullValue());
assertThat(r.getId(), not(0L));
}
assertThat(i, equalTo(115));
@@ -87,11 +87,11 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
Iterator<GHRepository> itr = user.listRepositories().withPageSize(62).iterator();
int i = 0;
for (; i < 115; i++) {
assertTrue(itr.hasNext());
assertThat(itr.hasNext(), is(true));
GHRepository r = itr.next();
// System.out.println(r.getFullName());
assertNotNull(r.getUrl());
assertNotEquals(0L, r.getId());
assertThat(r.getUrl(), notNullValue());
assertThat(r.getId(), not(0L));
}
assertThat(i, equalTo(115));
@@ -108,7 +108,7 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
.create();
try {
Assert.assertNotNull(repository);
assertThat(repository, notNullValue());
GHUser ghUser = gitHub.getUser(login);
assertThat(ghUser.getTotalPrivateRepoCount().orElse(-1), greaterThan(0));
} finally {
@@ -120,8 +120,8 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
public void verifyBioAndHireable() throws IOException {
GHUser u = gitHub.getUser("Chew");
assertThat(u.getBio(), equalTo("I like to program things and I hope to program something cool one day :D"));
assertTrue(u.isHireable());
assertNotNull(u.getTwitterUsername());
assertThat(u.isHireable(), is(true));
assertThat(u.getTwitterUsername(), notNullValue());
assertThat(u.getBlog(), equalTo("https://chew.pw"));
assertThat(u.getCompany(), equalTo("@Memerator"));
assertThat(u.getFollowersCount(), equalTo(29));

View File

@@ -2,6 +2,8 @@ package org.kohsuke.github;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
/**
* @author Sourabh Sarvotham Parkala
*/
@@ -11,121 +13,126 @@ public class GHVerificationReasonTest extends AbstractGitHubWireMockTest {
public void testExpiredKey() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f01");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.EXPIRED_KEY);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.EXPIRED_KEY,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testNotSigningKey() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f02");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.NOT_SIGNING_KEY);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.NOT_SIGNING_KEY,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testGpgverifyError() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f03");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.GPGVERIFY_ERROR);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.GPGVERIFY_ERROR,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testGpgverifyUnavailable() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f04");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(),
GHVerification.Reason.GPGVERIFY_UNAVAILABLE);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.GPGVERIFY_UNAVAILABLE,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testUnsigned() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f05");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.UNSIGNED);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.UNSIGNED, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testUnknownSignatureType() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f06");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(),
GHVerification.Reason.UNKNOWN_SIGNATURE_TYPE);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.UNKNOWN_SIGNATURE_TYPE,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testNoUser() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f07");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.NO_USER);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.NO_USER, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testUnverifiedEmail() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f08");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.UNVERIFIED_EMAIL);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.UNVERIFIED_EMAIL,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testBadEmail() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f09");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.BAD_EMAIL);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.BAD_EMAIL, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testUnknownKey() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f10");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.UNKNOWN_KEY);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.UNKNOWN_KEY,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testMalformedSignature() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f11");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(),
GHVerification.Reason.MALFORMED_SIGNATURE);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.MALFORMED_SIGNATURE,
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testInvalid() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f12");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertFalse(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.INVALID);
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
assertThat(GHVerification.Reason.INVALID, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
}
@Test
public void testValid() throws Exception {
GHRepository r = gitHub.getRepository("hub4j/github-api");
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f13");
assertEquals(commit.getCommitShortInfo().getAuthor().getName(), "Sourabh Parkala");
assertTrue(commit.getCommitShortInfo().getVerification().isVerified());
assertEquals(commit.getCommitShortInfo().getVerification().getReason(), GHVerification.Reason.VALID);
assertNotNull(commit.getCommitShortInfo().getVerification().getPayload());
assertNotNull(commit.getCommitShortInfo().getVerification().getSignature());
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(true));
assertThat(GHVerification.Reason.VALID, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
assertThat(commit.getCommitShortInfo().getVerification().getPayload(), notNullValue());
assertThat(commit.getCommitShortInfo().getVerification().getSignature(), notNullValue());
}
}

View File

@@ -1,7 +1,6 @@
package org.kohsuke.github;
import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.kohsuke.github.GHWorkflowJob.Step;
@@ -20,11 +19,7 @@ import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
@@ -72,30 +67,30 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
latestPreexistingWorkflowRunId).orElseThrow(
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
assertEquals(workflow.getId(), workflowRun.getWorkflowId());
assertNotNull(workflowRun.getId());
assertNotNull(workflowRun.getNodeId());
assertEquals(REPO_NAME, workflowRun.getRepository().getFullName());
assertTrue(workflowRun.getUrl().getPath().contains("/actions/runs/"));
assertTrue(workflowRun.getHtmlUrl().getPath().contains("/actions/runs/"));
assertTrue(workflowRun.getJobsUrl().getPath().endsWith("/jobs"));
assertTrue(workflowRun.getLogsUrl().getPath().endsWith("/logs"));
assertTrue(workflowRun.getCheckSuiteUrl().getPath().contains("/check-suites/"));
assertTrue(workflowRun.getArtifactsUrl().getPath().endsWith("/artifacts"));
assertTrue(workflowRun.getCancelUrl().getPath().endsWith("/cancel"));
assertTrue(workflowRun.getRerunUrl().getPath().endsWith("/rerun"));
assertTrue(workflowRun.getWorkflowUrl().getPath().contains("/actions/workflows/"));
assertEquals(MAIN_BRANCH, workflowRun.getHeadBranch());
assertNotNull(workflowRun.getHeadCommit().getId());
assertNotNull(workflowRun.getHeadCommit().getTreeId());
assertNotNull(workflowRun.getHeadCommit().getMessage());
assertNotNull(workflowRun.getHeadCommit().getTimestamp());
assertNotNull(workflowRun.getHeadCommit().getAuthor().getEmail());
assertNotNull(workflowRun.getHeadCommit().getCommitter().getEmail());
assertEquals(GHEvent.WORKFLOW_DISPATCH, workflowRun.getEvent());
assertEquals(Status.COMPLETED, workflowRun.getStatus());
assertEquals(Conclusion.SUCCESS, workflowRun.getConclusion());
assertNotNull(workflowRun.getHeadSha());
assertThat(workflowRun.getWorkflowId(), equalTo(workflow.getId()));
assertThat(workflowRun.getId(), notNullValue());
assertThat(workflowRun.getNodeId(), notNullValue());
assertThat(workflowRun.getRepository().getFullName(), equalTo(REPO_NAME));
assertThat(workflowRun.getUrl().getPath().contains("/actions/runs/"), is(true));
assertThat(workflowRun.getHtmlUrl().getPath().contains("/actions/runs/"), is(true));
assertThat(workflowRun.getJobsUrl().getPath().endsWith("/jobs"), is(true));
assertThat(workflowRun.getLogsUrl().getPath().endsWith("/logs"), is(true));
assertThat(workflowRun.getCheckSuiteUrl().getPath().contains("/check-suites/"), is(true));
assertThat(workflowRun.getArtifactsUrl().getPath().endsWith("/artifacts"), is(true));
assertThat(workflowRun.getCancelUrl().getPath().endsWith("/cancel"), is(true));
assertThat(workflowRun.getRerunUrl().getPath().endsWith("/rerun"), is(true));
assertThat(workflowRun.getWorkflowUrl().getPath().contains("/actions/workflows/"), is(true));
assertThat(workflowRun.getHeadBranch(), equalTo(MAIN_BRANCH));
assertThat(workflowRun.getHeadCommit().getId(), notNullValue());
assertThat(workflowRun.getHeadCommit().getTreeId(), notNullValue());
assertThat(workflowRun.getHeadCommit().getMessage(), notNullValue());
assertThat(workflowRun.getHeadCommit().getTimestamp(), notNullValue());
assertThat(workflowRun.getHeadCommit().getAuthor().getEmail(), notNullValue());
assertThat(workflowRun.getHeadCommit().getCommitter().getEmail(), notNullValue());
assertThat(workflowRun.getEvent(), equalTo(GHEvent.WORKFLOW_DISPATCH));
assertThat(workflowRun.getStatus(), equalTo(Status.COMPLETED));
assertThat(workflowRun.getConclusion(), equalTo(Conclusion.SUCCESS));
assertThat(workflowRun.getHeadSha(), notNullValue());
}
@Test
@@ -119,7 +114,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
latestPreexistingWorkflowRunId).orElseThrow(
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
assertNotNull(workflowRun.getId());
assertThat(workflowRun.getId(), notNullValue());
workflowRun.cancel();
long cancelledWorkflowRunId = workflowRun.getId();
@@ -129,7 +124,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
// let's check that it has been properly cancelled
workflowRun = repo.getWorkflowRun(cancelledWorkflowRunId);
assertEquals(Conclusion.CANCELLED, workflowRun.getConclusion());
assertThat(workflowRun.getConclusion(), equalTo(Conclusion.CANCELLED));
// now let's rerun it
workflowRun.rerun();
@@ -162,13 +157,13 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
latestPreexistingWorkflowRunId).orElseThrow(
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
assertNotNull(workflowRunToDelete.getId());
assertThat(workflowRunToDelete.getId(), notNullValue());
workflowRunToDelete.delete();
try {
repo.getWorkflowRun(workflowRunToDelete.getId());
Assert.fail("The workflow " + workflowRunToDelete.getId() + " should have been deleted.");
fail("The workflow " + workflowRunToDelete.getId() + " should have been deleted.");
} catch (GHFileNotFoundException e) {
// success
}
@@ -194,11 +189,11 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
latestPreexistingWorkflowRunId).orElseThrow(
() -> new IllegalStateException("We must have a valid workflow run starting from here"));
assertEquals(workflow.getId(), workflowRun.getWorkflowId());
assertEquals(SECOND_BRANCH, workflowRun.getHeadBranch());
assertEquals(GHEvent.WORKFLOW_DISPATCH, workflowRun.getEvent());
assertEquals(Status.COMPLETED, workflowRun.getStatus());
assertEquals(Conclusion.SUCCESS, workflowRun.getConclusion());
assertThat(workflowRun.getWorkflowId(), equalTo(workflow.getId()));
assertThat(workflowRun.getHeadBranch(), equalTo(SECOND_BRANCH));
assertThat(workflowRun.getEvent(), equalTo(GHEvent.WORKFLOW_DISPATCH));
assertThat(workflowRun.getStatus(), equalTo(Status.COMPLETED));
assertThat(workflowRun.getConclusion(), equalTo(Conclusion.SUCCESS));
}
@Test
@@ -232,7 +227,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
try {
workflowRun.downloadLogs((is) -> "");
Assert.fail("Downloading logs should not be possible as they were deleted");
fail("Downloading logs should not be possible as they were deleted");
} catch (GHFileNotFoundException e) {
assertThat(e.getMessage(), containsString("Not Found"));
}
@@ -313,7 +308,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
try {
repo.getArtifact(artifact1.getId());
Assert.fail("Getting the artifact should fail as it was deleted");
fail("Getting the artifact should fail as it was deleted");
} catch (GHFileNotFoundException e) {
assertThat(e.getMessage(), containsString("Not Found"));
}
@@ -456,26 +451,26 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
}
private static void checkArtifactProperties(GHArtifact artifact, String artifactName) throws IOException {
assertNotNull(artifact.getId());
assertNotNull(artifact.getNodeId());
assertEquals(REPO_NAME, artifact.getRepository().getFullName());
assertThat(artifact.getId(), notNullValue());
assertThat(artifact.getNodeId(), notNullValue());
assertThat(artifact.getRepository().getFullName(), equalTo(REPO_NAME));
assertThat(artifact.getName(), is(artifactName));
assertThat(artifact.getArchiveDownloadUrl().getPath(), containsString("actions/artifacts"));
assertNotNull(artifact.getCreatedAt());
assertNotNull(artifact.getUpdatedAt());
assertNotNull(artifact.getExpiresAt());
assertThat(artifact.getCreatedAt(), notNullValue());
assertThat(artifact.getUpdatedAt(), notNullValue());
assertThat(artifact.getExpiresAt(), notNullValue());
assertThat(artifact.getSizeInBytes(), greaterThan(0L));
assertFalse(artifact.isExpired());
assertThat(artifact.isExpired(), is(false));
}
private static void checkJobProperties(long workflowRunId, GHWorkflowJob job, String jobName) throws IOException {
assertNotNull(job.getId());
assertNotNull(job.getNodeId());
assertEquals(REPO_NAME, job.getRepository().getFullName());
assertThat(job.getId(), notNullValue());
assertThat(job.getNodeId(), notNullValue());
assertThat(job.getRepository().getFullName(), equalTo(REPO_NAME));
assertThat(job.getName(), is(jobName));
assertNotNull(job.getStartedAt());
assertNotNull(job.getCompletedAt());
assertNotNull(job.getHeadSha());
assertThat(job.getStartedAt(), notNullValue());
assertThat(job.getCompletedAt(), notNullValue());
assertThat(job.getHeadSha(), notNullValue());
assertThat(job.getStatus(), is(Status.COMPLETED));
assertThat(job.getConclusion(), is(Conclusion.SUCCESS));
assertThat(job.getRunId(), is(workflowRunId));
@@ -500,7 +495,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
assertThat(step.getNumber(), is(number));
assertThat(step.getStatus(), is(Status.COMPLETED));
assertThat(step.getConclusion(), is(Conclusion.SUCCESS));
assertNotNull(step.getStartedAt());
assertNotNull(step.getCompletedAt());
assertThat(step.getStartedAt(), notNullValue());
assertThat(step.getCompletedAt(), notNullValue());
}
}

View File

@@ -12,6 +12,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.hamcrest.Matchers.equalTo;
public class GHWorkflowTest extends AbstractGitHubWireMockTest {
@@ -42,35 +43,36 @@ public class GHWorkflowTest extends AbstractGitHubWireMockTest {
public void testBasicInformation() throws IOException {
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
assertEquals("test-workflow", workflow.getName());
assertEquals(REPO_NAME, workflow.getRepository().getFullName());
assertEquals(".github/workflows/test-workflow.yml", workflow.getPath());
assertEquals("active", workflow.getState());
assertEquals("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859", workflow.getUrl().getPath());
assertEquals("/hub4j-test-org/GHWorkflowTest/blob/main/.github/workflows/test-workflow.yml",
workflow.getHtmlUrl().getPath());
assertEquals("/hub4j-test-org/GHWorkflowTest/workflows/test-workflow/badge.svg",
workflow.getBadgeUrl().getPath());
assertThat(workflow.getName(), equalTo("test-workflow"));
assertThat(workflow.getRepository().getFullName(), equalTo(REPO_NAME));
assertThat(workflow.getPath(), equalTo(".github/workflows/test-workflow.yml"));
assertThat(workflow.getState(), equalTo("active"));
assertThat(workflow.getUrl().getPath(),
equalTo("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859"));
assertThat(workflow.getHtmlUrl().getPath(),
equalTo("/hub4j-test-org/GHWorkflowTest/blob/main/.github/workflows/test-workflow.yml"));
assertThat(workflow.getBadgeUrl().getPath(),
equalTo("/hub4j-test-org/GHWorkflowTest/workflows/test-workflow/badge.svg"));
GHWorkflow workflowById = repo.getWorkflow(workflow.getId());
assertEquals(workflow.getNodeId(), workflowById.getNodeId());
assertThat(workflowById.getNodeId(), equalTo(workflow.getNodeId()));
}
@Test
public void testDisableEnable() throws IOException {
GHWorkflow workflow = repo.getWorkflow("test-workflow.yml");
assertEquals("active", workflow.getState());
assertThat(workflow.getState(), equalTo("active"));
workflow.disable();
workflow = repo.getWorkflow("test-workflow.yml");
assertEquals("disabled_manually", workflow.getState());
assertThat(workflow.getState(), equalTo("disabled_manually"));
workflow.enable();
workflow = repo.getWorkflow("test-workflow.yml");
assertEquals("active", workflow.getState());
assertThat(workflow.getState(), equalTo("active"));
}
@Test
@@ -94,15 +96,16 @@ public class GHWorkflowTest extends AbstractGitHubWireMockTest {
List<GHWorkflow> workflows = repo.listWorkflows().toList();
GHWorkflow workflow = workflows.get(0);
assertEquals(6817859L, workflow.getId());
assertEquals("MDg6V29ya2Zsb3c2ODE3ODU5", workflow.getNodeId());
assertEquals("test-workflow", workflow.getName());
assertEquals(".github/workflows/test-workflow.yml", workflow.getPath());
assertEquals("active", workflow.getState());
assertEquals("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859", workflow.getUrl().getPath());
assertEquals("/hub4j-test-org/GHWorkflowTest/blob/main/.github/workflows/test-workflow.yml",
workflow.getHtmlUrl().getPath());
assertEquals("/hub4j-test-org/GHWorkflowTest/workflows/test-workflow/badge.svg",
workflow.getBadgeUrl().getPath());
assertThat(workflow.getId(), equalTo(6817859L));
assertThat(workflow.getNodeId(), equalTo("MDg6V29ya2Zsb3c2ODE3ODU5"));
assertThat(workflow.getName(), equalTo("test-workflow"));
assertThat(workflow.getPath(), equalTo(".github/workflows/test-workflow.yml"));
assertThat(workflow.getState(), equalTo("active"));
assertThat(workflow.getUrl().getPath(),
equalTo("/repos/hub4j-test-org/GHWorkflowTest/actions/workflows/6817859"));
assertThat(workflow.getHtmlUrl().getPath(),
equalTo("/hub4j-test-org/GHWorkflowTest/blob/main/.github/workflows/test-workflow.yml"));
assertThat(workflow.getBadgeUrl().getPath(),
equalTo("/hub4j-test-org/GHWorkflowTest/workflows/test-workflow/badge.svg"));
}
}

View File

@@ -24,37 +24,36 @@ public class GitHubConnectionTest extends AbstractGitHubWireMockTest {
@Test
public void testOffline() throws Exception {
GitHub hub = GitHub.offline();
assertEquals("https://api.github.invalid/test",
GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString());
assertTrue(hub.isAnonymous());
assertThat(GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString(),
equalTo("https://api.github.invalid/test"));
assertThat(hub.isAnonymous(), is(true));
try {
hub.getRateLimit();
fail("Offline instance should always fail");
} catch (IOException e) {
assertEquals("Offline", e.getMessage());
assertThat(e.getMessage(), equalTo("Offline"));
}
}
@Test
public void testGitHubServerWithHttp() throws Exception {
GitHub hub = GitHub.connectToEnterprise("http://enterprise.kohsuke.org/api/v3", "bogus", "bogus");
assertEquals("http://enterprise.kohsuke.org/api/v3/test",
GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString());
assertThat(GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString(),
equalTo("http://enterprise.kohsuke.org/api/v3/test"));
}
@Test
public void testGitHubServerWithHttps() throws Exception {
GitHub hub = GitHub.connectToEnterprise("https://enterprise.kohsuke.org/api/v3", "bogus", "bogus");
assertEquals("https://enterprise.kohsuke.org/api/v3/test",
GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString());
assertThat(GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString(),
equalTo("https://enterprise.kohsuke.org/api/v3/test"));
}
@Test
public void testGitHubServerWithoutServer() throws Exception {
GitHub hub = GitHub.connectUsingPassword("kohsuke", "bogus");
assertEquals("https://api.github.com/test",
GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString());
assertThat(GitHubRequest.getApiURL(hub.getClient().getApiUrl(), "/test").toString(),
equalTo("https://api.github.com/test"));
}
@Test
@@ -149,8 +148,8 @@ public class GitHubConnectionTest extends AbstractGitHubWireMockTest {
// test authorization header is set as in the RFC6749
GitHub github = builder.build();
// change this to get a request
assertEquals("token bogus app token", github.getClient().getEncodedAuthorization());
assertEquals("", github.getClient().login);
assertThat(github.getClient().getEncodedAuthorization(), equalTo("token bogus app token"));
assertThat(github.getClient().login, equalTo(""));
}
@Test

View File

@@ -13,6 +13,7 @@ import java.util.TimeZone;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.fail;
@@ -139,8 +140,8 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
assertThat(rateLimit_none, equalTo(rateLimit_core));
assertThat(rateLimit_none, not(sameInstance(rateLimit_core)));
assertTrue(rateLimit_none.hashCode() == rateLimit_core.hashCode());
assertTrue(rateLimit_none.equals(rateLimit_core));
assertThat(rateLimit_none.hashCode() == rateLimit_core.hashCode(), is(true));
assertThat(rateLimit_none.equals(rateLimit_core), is(true));
assertThat(rateLimit_none, not(equalTo(rateLimit_search)));

View File

@@ -8,8 +8,11 @@ import java.io.IOException;
import java.util.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.kohsuke.github.GHMarketplaceAccountType.ORGANIZATION;
/**
@@ -69,19 +72,19 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
PagedSearchIterable<GHUser> r = gitHub.searchUsers().q("tom").repos(">42").followers(">1000").list();
GHUser u = r.iterator().next();
// System.out.println(u.getName());
assertNotNull(u.getId());
assertTrue(r.getTotalCount() > 0);
assertThat(u.getId(), notNullValue());
assertThat(r.getTotalCount() > 0, is(true));
}
@Test
public void testListAllRepositories() throws Exception {
Iterator<GHRepository> itr = gitHub.listAllPublicRepositories().iterator();
for (int i = 0; i < 115; i++) {
assertTrue(itr.hasNext());
assertThat(itr.hasNext(), is(true));
GHRepository r = itr.next();
// System.out.println(r.getFullName());
assertNotNull(r.getUrl());
assertNotEquals(0L, r.getId());
assertThat(r.getUrl(), notNullValue());
assertThat(r.getId(), not(0L));
}
// ensure the iterator throws as expected
@@ -106,10 +109,10 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
GHContent c = r.iterator().next();
// System.out.println(c.getName());
assertNotNull(c.getDownloadUrl());
assertNotNull(c.getOwner());
assertEquals("jquery/jquery", c.getOwner().getFullName());
assertTrue(r.getTotalCount() > 5);
assertThat(c.getDownloadUrl(), notNullValue());
assertThat(c.getOwner(), notNullValue());
assertThat(c.getOwner().getFullName(), equalTo("jquery/jquery"));
assertThat(r.getTotalCount() > 5, is(true));
PagedSearchIterable<GHContent> r2 = gitHub.searchContent()
.q("addClass")
@@ -161,20 +164,20 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
PagedIterable<GHAuthorization> list = gitHub.listMyAuthorizations();
for (GHAuthorization auth : list) {
assertNotNull(auth.getAppName());
assertThat(auth.getAppName(), notNullValue());
}
}
@Test
public void getMeta() throws IOException {
GHMeta meta = gitHub.getMeta();
assertTrue(meta.isVerifiablePasswordAuthentication());
assertEquals(19, meta.getApi().size());
assertEquals(19, meta.getGit().size());
assertEquals(3, meta.getHooks().size());
assertEquals(6, meta.getImporter().size());
assertEquals(6, meta.getPages().size());
assertEquals(19, meta.getWeb().size());
assertThat(meta.isVerifiablePasswordAuthentication(), is(true));
assertThat(meta.getApi().size(), equalTo(19));
assertThat(meta.getGit().size(), equalTo(19));
assertThat(meta.getHooks().size(), equalTo(3));
assertThat(meta.getImporter().size(), equalTo(6));
assertThat(meta.getPages().size(), equalTo(6));
assertThat(meta.getWeb().size(), equalTo(19));
// Also test examples here
Class[] examples = new Class[]{ ReadOnlyObjects.GHMetaPublic.class, ReadOnlyObjects.GHMetaPackage.class,
@@ -185,58 +188,58 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
ReadOnlyObjects.GHMetaExample metaExample = gitHub.createRequest()
.withUrlPath("/meta")
.fetch((Class<ReadOnlyObjects.GHMetaExample>) metaClass);
assertTrue(metaExample.isVerifiablePasswordAuthentication());
assertEquals(19, metaExample.getApi().size());
assertEquals(19, metaExample.getGit().size());
assertEquals(3, metaExample.getHooks().size());
assertEquals(6, metaExample.getImporter().size());
assertEquals(6, metaExample.getPages().size());
assertEquals(19, metaExample.getWeb().size());
assertThat(metaExample.isVerifiablePasswordAuthentication(), is(true));
assertThat(metaExample.getApi().size(), equalTo(19));
assertThat(metaExample.getGit().size(), equalTo(19));
assertThat(metaExample.getHooks().size(), equalTo(3));
assertThat(metaExample.getImporter().size(), equalTo(6));
assertThat(metaExample.getPages().size(), equalTo(6));
assertThat(metaExample.getWeb().size(), equalTo(19));
}
}
@Test
public void getMyMarketplacePurchases() throws IOException {
List<GHMarketplaceUserPurchase> userPurchases = gitHub.getMyMarketplacePurchases().toList();
assertEquals(2, userPurchases.size());
assertThat(userPurchases.size(), equalTo(2));
for (GHMarketplaceUserPurchase userPurchase : userPurchases) {
assertFalse(userPurchase.isOnFreeTrial());
assertNull(userPurchase.getFreeTrialEndsOn());
assertEquals("monthly", userPurchase.getBillingCycle());
assertThat(userPurchase.isOnFreeTrial(), is(false));
assertThat(userPurchase.getFreeTrialEndsOn(), nullValue());
assertThat(userPurchase.getBillingCycle(), equalTo("monthly"));
GHMarketplacePlan plan = userPurchase.getPlan();
// GHMarketplacePlan - Non-nullable fields
assertNotNull(plan.getUrl());
assertNotNull(plan.getAccountsUrl());
assertNotNull(plan.getName());
assertNotNull(plan.getDescription());
assertNotNull(plan.getPriceModel());
assertNotNull(plan.getState());
assertThat(plan.getUrl(), notNullValue());
assertThat(plan.getAccountsUrl(), notNullValue());
assertThat(plan.getName(), notNullValue());
assertThat(plan.getDescription(), notNullValue());
assertThat(plan.getPriceModel(), notNullValue());
assertThat(plan.getState(), notNullValue());
// GHMarketplacePlan - primitive fields
assertNotEquals(0L, plan.getId());
assertNotEquals(0L, plan.getNumber());
assertTrue(plan.getMonthlyPriceInCents() >= 0);
assertThat(plan.getId(), not(0L));
assertThat(plan.getNumber(), not(0L));
assertThat(plan.getMonthlyPriceInCents() >= 0, is(true));
// GHMarketplacePlan - list
assertEquals(2, plan.getBullets().size());
assertThat(plan.getBullets().size(), equalTo(2));
GHMarketplaceAccount account = userPurchase.getAccount();
// GHMarketplaceAccount - Non-nullable fields
assertNotNull(account.getLogin());
assertNotNull(account.getUrl());
assertNotNull(account.getType());
assertThat(account.getLogin(), notNullValue());
assertThat(account.getUrl(), notNullValue());
assertThat(account.getType(), notNullValue());
// GHMarketplaceAccount - primitive fields
assertNotEquals(0L, account.getId());
assertThat(account.getId(), not(0L));
/* logical combination tests */
// Rationale: organization_billing_email is only set when account type is ORGANIZATION.
if (account.getType() == ORGANIZATION)
assertNotNull(account.getOrganizationBillingEmail());
assertThat(account.getOrganizationBillingEmail(), notNullValue());
else
assertNull(account.getOrganizationBillingEmail());
assertThat(account.getOrganizationBillingEmail(), nullValue());
}
}

View File

@@ -7,8 +7,6 @@ import java.util.Arrays;
import java.util.List;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Kevin Harrington mad.hephaestus@gmail.com
@@ -17,7 +15,7 @@ public class Github2faTest extends AbstractGitHubWireMockTest {
@Test
public void test2faToken() throws IOException {
assertFalse("Test only valid when not proxying", mockGitHub.isUseProxy());
assertThat("Test only valid when not proxying", mockGitHub.isUseProxy(), is(false));
List<String> asList = Arrays
.asList("repo", "gist", "write:packages", "read:packages", "delete:packages", "user", "delete_repo");
@@ -35,7 +33,7 @@ public class Github2faTest extends AbstractGitHubWireMockTest {
assertThat(token, notNullValue());
for (int i = 0; i < asList.size(); i++) {
assertTrue(token.getScopes().get(i).contentEquals(asList.get(i)));
assertThat(token.getScopes().get(i).contentEquals(asList.get(i)), is(true));
}
assertThat(token.getToken(), equalTo("63042a99d88bf138e6d6cf5788e0dc4e7a5d7309"));

View File

@@ -1,6 +1,7 @@
package org.kohsuke.github;
import org.apache.commons.lang3.SystemUtils;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Test;
@@ -11,6 +12,8 @@ import java.io.PrintWriter;
import java.util.List;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.Is.is;
public class LifecycleTest extends AbstractGitHubWireMockTest {
@@ -22,7 +25,7 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
// GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHRepository repository = getTempRepository();
assertTrue(repository.getReleases().isEmpty());
assertThat(repository.getReleases().isEmpty(), Matchers.is(true));
GHMilestone milestone = repository.createMilestone("Initial Release", "first one");
GHIssue issue = repository.createIssue("Test Issue")
@@ -45,22 +48,22 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
private void updateAsset(GHRelease release, GHAsset asset) throws IOException {
asset.setLabel("test label");
assertEquals("test label", release.getAssets().get(0).getLabel());
assertThat(release.getAssets().get(0).getLabel(), equalTo("test label"));
}
private void deleteAsset(GHRelease release, GHAsset asset) throws IOException {
asset.delete();
assertEquals(0, release.getAssets().size());
assertThat(release.getAssets().size(), equalTo(0));
}
private GHAsset uploadAsset(GHRelease release) throws IOException {
GHAsset asset = release.uploadAsset(new File("LICENSE.txt"), "application/text");
assertNotNull(asset);
assertThat(asset, notNullValue());
List<GHAsset> cachedAssets = release.assets();
assertEquals(0, cachedAssets.size());
assertThat(cachedAssets.size(), equalTo(0));
List<GHAsset> assets = release.getAssets();
assertEquals(1, assets.size());
assertEquals("LICENSE.txt", assets.get(0).getName());
assertThat(assets.size(), equalTo(1));
assertThat(assets.get(0).getName(), equalTo("LICENSE.txt"));
assertThat(assets.get(0).getSize(), equalTo(1104L));
assertThat(assets.get(0).getContentType(), equalTo("application/text"));
assertThat(assets.get(0).getState(), equalTo("uploaded"));
@@ -78,9 +81,9 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
.body("How exciting! To be able to programmatically create releases is a dream come true!")
.create();
List<GHRelease> releases = repository.getReleases();
assertEquals(1, releases.size());
assertThat(releases.size(), equalTo(1));
GHRelease release = releases.get(0);
assertEquals("Test Release", release.getName());
assertThat(release.getName(), equalTo("Test Release"));
assertThat(release.getBody(), startsWith("How exciting!"));
assertThat(release.getOwner(), sameInstance(repository));
assertThat(release.getZipballUrl(),

View File

@@ -1,6 +1,6 @@
package org.kohsuke.github;
import org.junit.Assert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.kohsuke.github.GHRepositoryTraffic.DailyInfo;
@@ -14,24 +14,24 @@ public class RepositoryTrafficTest extends AbstractGitHubWireMockTest {
@SuppressWarnings("unchecked")
private <T extends GHRepositoryTraffic> void checkResponse(T expected, T actual) {
Assert.assertEquals(expected.getCount(), actual.getCount());
Assert.assertEquals(expected.getUniques(), actual.getUniques());
assertThat(actual.getCount(), Matchers.equalTo(expected.getCount()));
assertThat(actual.getUniques(), Matchers.equalTo(expected.getUniques()));
List<? extends DailyInfo> expectedList = expected.getDailyInfo();
List<? extends DailyInfo> actualList = actual.getDailyInfo();
Iterator<? extends DailyInfo> expectedIt;
Iterator<? extends DailyInfo> actualIt;
Assert.assertEquals(expectedList.size(), actualList.size());
assertThat(actualList.size(), Matchers.equalTo(expectedList.size()));
expectedIt = expectedList.iterator();
actualIt = actualList.iterator();
while (expectedIt.hasNext() && actualIt.hasNext()) {
DailyInfo expectedDailyInfo = expectedIt.next();
DailyInfo actualDailyInfo = actualIt.next();
Assert.assertEquals(expectedDailyInfo.getCount(), actualDailyInfo.getCount());
Assert.assertEquals(expectedDailyInfo.getUniques(), actualDailyInfo.getUniques());
Assert.assertEquals(expectedDailyInfo.getTimestamp(), actualDailyInfo.getTimestamp());
assertThat(actualDailyInfo.getCount(), Matchers.equalTo(expectedDailyInfo.getCount()));
assertThat(actualDailyInfo.getUniques(), Matchers.equalTo(expectedDailyInfo.getUniques()));
assertThat(actualDailyInfo.getTimestamp(), Matchers.equalTo(expectedDailyInfo.getTimestamp()));
}
}
@@ -100,12 +100,12 @@ public class RepositoryTrafficTest extends AbstractGitHubWireMockTest {
GHRepository repo = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository(repositoryName);
try {
repo.getViewTraffic();
Assert.fail(errorMsg);
fail(errorMsg);
} catch (HttpException ex) {
}
try {
repo.getCloneTraffic();
Assert.fail(errorMsg);
fail(errorMsg);
} catch (HttpException ex) {
}
}

View File

@@ -97,7 +97,7 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
try {
gitHub.checkApiUrlValidity();
} catch (IOException ioe) {
assertTrue(ioe.getMessage().contains("private mode enabled"));
assertThat(ioe.getMessage().contains("private mode enabled"), is(true));
}
Thread.sleep(100);
}
@@ -127,8 +127,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
}
String capturedLog = getTestCapturedLog();
assertTrue(capturedLog.contains("will try 2 more time"));
assertTrue(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(true));
assertThat(capturedLog.contains("will try 1 more time"), is(true));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 6));
}
@@ -156,8 +156,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
}
String capturedLog = getTestCapturedLog();
assertTrue(capturedLog.contains("will try 2 more time"));
assertTrue(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(true));
assertThat(capturedLog.contains("will try 1 more time"), is(true));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 6));
}
@@ -206,8 +206,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
GHBranch branch = repo.getBranch("test/timeout");
assertThat(branch, notNullValue());
String capturedLog = getTestCapturedLog();
assertTrue(capturedLog.contains("will try 2 more time"));
assertTrue(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(true));
assertThat(capturedLog.contains("will try 1 more time"), is(true));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 6));
}
@@ -232,8 +232,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
assertThat(e.getCause(), instanceOf(IOException.class));
assertThat(e.getCause().getMessage(), is("Custom"));
String capturedLog = getTestCapturedLog();
assertFalse(capturedLog.contains("will try 2 more time"));
assertFalse(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(false));
assertThat(capturedLog.contains("will try 1 more time"), is(false));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount));
}
@@ -253,8 +253,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
assertThat(e, instanceOf(FileNotFoundException.class));
assertThat(e.getMessage(), is("Custom"));
String capturedLog = getTestCapturedLog();
assertFalse(capturedLog.contains("will try 2 more time"));
assertFalse(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(false));
assertThat(capturedLog.contains("will try 1 more time"), is(false));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount));
}
}
@@ -279,8 +279,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
assertThat(e.getCause(), instanceOf(IOException.class));
assertThat(e.getCause().getMessage(), is("Custom"));
String capturedLog = getTestCapturedLog();
assertFalse(capturedLog.contains("will try 2 more time"));
assertFalse(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(false));
assertThat(capturedLog.contains("will try 1 more time"), is(false));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1));
}
@@ -297,8 +297,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
assertThat(e.getCause(), instanceOf(FileNotFoundException.class));
assertThat(e.getCause().getMessage(), containsString("hub4j-test-org-missing"));
String capturedLog = getTestCapturedLog();
assertFalse(capturedLog.contains("will try 2 more time"));
assertFalse(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(false));
assertThat(capturedLog.contains("will try 1 more time"), is(false));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1));
}
@@ -313,8 +313,8 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
.fetchHttpStatusCode(),
equalTo(404));
String capturedLog = getTestCapturedLog();
assertFalse(capturedLog.contains("will try 2 more time"));
assertFalse(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(false));
assertThat(capturedLog.contains("will try 1 more time"), is(false));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1));
}
@@ -373,16 +373,16 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
baseRequestCount = this.mockGitHub.getRequestCount();
assertThat(this.gitHub.getOrganization(GITHUB_API_TEST_ORG), is(notNullValue()));
String capturedLog = getTestCapturedLog();
assertTrue(capturedLog.contains("will try 2 more time"));
assertTrue(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(true));
assertThat(capturedLog.contains("will try 1 more time"), is(true));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + expectedRequestCount));
resetTestCapturedLog();
baseRequestCount = this.mockGitHub.getRequestCount();
this.gitHub.createRequest().withUrlPath("/orgs/" + GITHUB_API_TEST_ORG).send();
capturedLog = getTestCapturedLog();
assertTrue(capturedLog.contains("will try 2 more time"));
assertTrue(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(true));
assertThat(capturedLog.contains("will try 1 more time"), is(true));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + expectedRequestCount));
}
@@ -399,13 +399,13 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
equalTo(200));
String capturedLog = getTestCapturedLog();
if (expectedRequestCount > 0) {
assertTrue(capturedLog.contains("will try 2 more time"));
assertTrue(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(true));
assertThat(capturedLog.contains("will try 1 more time"), is(true));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + expectedRequestCount));
} else {
// Success without retries
assertFalse(capturedLog.contains("will try 2 more time"));
assertFalse(capturedLog.contains("will try 1 more time"));
assertThat(capturedLog.contains("will try 2 more time"), is(false));
assertThat(capturedLog.contains("will try 1 more time"), is(false));
assertThat(this.mockGitHub.getRequestCount(), equalTo(baseRequestCount + 1));
}
}

View File

@@ -4,10 +4,7 @@ import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
@@ -133,7 +130,7 @@ public class WireMockStatusReporterTest extends AbstractGitHubWireMockTest {
assumeTrue("Test only valid when Snapshotting (-Dtest.github.takeSnapshot to enable)",
mockGitHub.isTakeSnapshot());
assertTrue("When taking a snapshot, proxy should automatically be enabled", mockGitHub.isUseProxy());
assertThat("When taking a snapshot, proxy should automatically be enabled", mockGitHub.isUseProxy(), is(true));
}
@Ignore("Not implemented yet")