mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Streamline assertThat calls using appropriate matchers
This commit is contained in:
@@ -7,7 +7,10 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.kohsuke.github.junit.GitHubWireMockRule;
|
||||
import wiremock.com.github.jknack.handlebars.Helper;
|
||||
import wiremock.com.github.jknack.handlebars.Options;
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@@ -138,7 +137,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
GHIssue i = repository.getIssue(4);
|
||||
List<GHIssueComment> v = i.getComments();
|
||||
// System.out.println(v);
|
||||
assertThat(v.isEmpty(), is(true));
|
||||
assertThat(v, is(empty()));
|
||||
|
||||
i = repository.getIssue(3);
|
||||
v = i.getComments();
|
||||
@@ -151,7 +150,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(v.get(0).getParent().getNumber(), equalTo(3));
|
||||
assertThat(v.get(0).getParent().getId(), equalTo(6863845L));
|
||||
assertThat(v.get(0).getUser().getLogin(), equalTo("kohsuke"));
|
||||
assertThat(v.get(0).listReactions().toList().size(), equalTo(0));
|
||||
assertThat(v.get(0).listReactions().toList(), is(empty()));
|
||||
|
||||
assertThat(v.get(1).getHtmlUrl().toString(),
|
||||
equalTo("https://github.com/kohsuke/test/issues/3#issuecomment-8547251"));
|
||||
@@ -196,7 +195,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(deployment.getId(), notNullValue());
|
||||
List<GHDeployment> deployments = repository.listDeployments(null, "main", null, "unittest").toList();
|
||||
assertThat(deployments, notNullValue());
|
||||
assertThat(Iterables.isEmpty(deployments), is(false));
|
||||
assertThat(deployments, is(not(emptyIterable())));
|
||||
GHDeployment unitTestDeployment = deployments.get(0);
|
||||
assertThat(unitTestDeployment.getEnvironment(), equalTo("unittest"));
|
||||
assertThat(unitTestDeployment.getOriginalEnvironment(), equalTo("unittest"));
|
||||
@@ -248,7 +247,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
.getRepository("github-api")
|
||||
.getIssues(GHIssueState.CLOSED);
|
||||
// prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues
|
||||
assertThat(closedIssues.size() > 150, is(true));
|
||||
assertThat(closedIssues.size(), greaterThan(150));
|
||||
String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(closedIssues.get(0));
|
||||
}
|
||||
|
||||
@@ -268,7 +267,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
x++;
|
||||
}
|
||||
|
||||
assertThat(x > 150, is(true));
|
||||
assertThat(x, greaterThan(150));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -279,7 +278,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
public void testMyOrganizations() throws IOException {
|
||||
Map<String, GHOrganization> org = gitHub.getMyOrganizations();
|
||||
assertThat(org.keySet().contains(null), is(false));
|
||||
assertThat(org.containsKey(null), is(false));
|
||||
// System.out.println(org);
|
||||
}
|
||||
|
||||
@@ -300,8 +299,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
for (GHTeam team : teamsPerOrg.getValue()) {
|
||||
String teamName = team.getName();
|
||||
assertThat("Team " + teamName + " in organization " + organizationName + " does not contain myself",
|
||||
shouldBelongToTeam(organizationName, teamName),
|
||||
is(true));
|
||||
shouldBelongToTeam(organizationName, teamName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,7 +311,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
user.login = "kohsuke";
|
||||
|
||||
Map<String, GHOrganization> orgs = gitHub.getUserPublicOrganizations(user);
|
||||
assertThat(orgs.isEmpty(), is(false));
|
||||
assertThat(orgs.size(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -323,7 +321,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
user.login = "bitwiseman";
|
||||
|
||||
Map<String, GHOrganization> orgs = gitHub.getUserPublicOrganizations(user);
|
||||
assertThat(orgs.isEmpty(), is(true));
|
||||
assertThat(orgs.size(), equalTo(0));
|
||||
}
|
||||
|
||||
private boolean shouldBelongToTeam(String organizationName, String teamName) throws IOException {
|
||||
@@ -383,7 +381,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
PagedIterable<GHPullRequest> i = r.listPullRequests(GHIssueState.CLOSED);
|
||||
List<GHPullRequest> prs = i.toList();
|
||||
assertThat(prs, notNullValue());
|
||||
assertThat(prs.size() > 0, is(true));
|
||||
assertThat(prs, is(not(empty())));
|
||||
}
|
||||
|
||||
@Ignore("Needs mocking check")
|
||||
@@ -404,14 +402,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(me, notNullValue());
|
||||
assertThat(gitHub.getUser("bitwiseman"), notNullValue());
|
||||
PagedIterable<GHRepository> ghRepositories = me.listRepositories();
|
||||
assertThat(ghRepositories.iterator().hasNext(), is(true));
|
||||
assertThat(ghRepositories, is(not(emptyIterable())));
|
||||
}
|
||||
|
||||
@Ignore("Needs mocking check")
|
||||
@Test
|
||||
public void testPublicKeys() throws Exception {
|
||||
List<GHKey> keys = gitHub.getMyself().getPublicKeys();
|
||||
assertThat(keys.isEmpty(), is(false));
|
||||
assertThat(keys, is(not(empty())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -450,7 +448,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(t.getName(), notNullValue());
|
||||
sz++;
|
||||
}
|
||||
assertThat(sz < 100, is(true));
|
||||
assertThat(sz, lessThan(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -875,7 +873,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
// System.out.println(u.getLogin());
|
||||
all.add(u);
|
||||
}
|
||||
assertThat(all.isEmpty(), is(false));
|
||||
assertThat(all, is(not(empty())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -886,10 +884,10 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
.author("kohsuke")
|
||||
.sort(GHCommitSearchBuilder.Sort.COMMITTER_DATE)
|
||||
.list();
|
||||
assertThat(r.getTotalCount() > 0, is(true));
|
||||
assertThat(r.getTotalCount(), greaterThan(0));
|
||||
|
||||
GHCommit firstCommit = r.iterator().next();
|
||||
assertThat(firstCommit.getFiles().size() > 0, is(true));
|
||||
assertThat(firstCommit.getFiles(), is(not(empty())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -899,7 +897,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
.isOpen()
|
||||
.sort(GHIssueSearchBuilder.Sort.UPDATED)
|
||||
.list();
|
||||
assertThat(r.getTotalCount() > 0, is(true));
|
||||
assertThat(r.getTotalCount(), greaterThan(0));
|
||||
for (GHIssue issue : r) {
|
||||
assertThat(issue.getTitle(), notNullValue());
|
||||
PagedIterable<GHIssueComment> comments = issue.listComments();
|
||||
@@ -963,14 +961,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
for (GHLabel l : lst) {
|
||||
assertThat(l.getUrl(), containsString(l.getName().replace(" ", "%20")));
|
||||
}
|
||||
assertThat(lst.size() > 5, is(true));
|
||||
assertThat(lst.size(), greaterThan(5));
|
||||
GHLabel e = r.getLabel("enhancement");
|
||||
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));
|
||||
assertThat(e.getColor(), matchesPattern("[0-9a-fA-F]{6}"));
|
||||
|
||||
GHLabel t = null;
|
||||
GHLabel t2 = null;
|
||||
|
||||
@@ -9,8 +9,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -84,7 +83,7 @@ public class CommitTest extends AbstractGitHubWireMockTest {
|
||||
.list()
|
||||
.toList();
|
||||
|
||||
assertThat(commits.size(), equalTo(0));
|
||||
assertThat(commits, is(empty()));
|
||||
|
||||
commits = gitHub.getUser("jenkinsci")
|
||||
.getRepository("jenkins")
|
||||
|
||||
@@ -5,8 +5,7 @@ import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class GHAppInstallationTest extends AbstractGHAppInstallationTest {
|
||||
|
||||
@@ -17,8 +16,8 @@ public class GHAppInstallationTest extends AbstractGHAppInstallationTest {
|
||||
List<GHRepository> repositories = appInstallation.listRepositories().toList();
|
||||
|
||||
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));
|
||||
assertThat(repositories.stream().map(GHRepository::getName).toArray(),
|
||||
arrayContainingInAnyOrder("empty", "test-readme"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -26,8 +25,7 @@ public class GHAppInstallationTest extends AbstractGHAppInstallationTest {
|
||||
GHAppInstallation appInstallation = getAppInstallationWithTokenApp2();
|
||||
|
||||
assertThat("App does not have permissions and should have 0 repositories",
|
||||
appInstallation.listRepositories().toList().isEmpty(),
|
||||
is(true));
|
||||
appInstallation.listRepositories().toList().isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
|
||||
RequiredStatusChecks statusChecks = protection.getRequiredStatusChecks();
|
||||
assertThat(statusChecks, notNullValue());
|
||||
assertThat(statusChecks.isRequiresBranchUpToDate(), is(true));
|
||||
assertThat(statusChecks.getContexts().contains("test-status-check"), is(true));
|
||||
assertThat(statusChecks.getContexts(), contains("test-status-check"));
|
||||
|
||||
RequiredReviews requiredReviews = protection.getRequiredReviews();
|
||||
assertThat(requiredReviews, notNullValue());
|
||||
@@ -110,7 +110,7 @@ public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
|
||||
GHBranchProtection protection = branch.enableProtection().enable();
|
||||
GHBranchProtection protectionTest = repo.getBranch(BRANCH).getProtection();
|
||||
Boolean condition = protectionTest instanceof GHBranchProtection;
|
||||
assertThat(condition, is(true));
|
||||
assertThat(protectionTest, instanceOf(GHBranchProtection.class));
|
||||
assertThat(repo.getBranch(BRANCH).isProtected(), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,7 @@ import java.io.InputStreamReader;
|
||||
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;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Integration test for {@link GHContent}.
|
||||
@@ -71,14 +66,14 @@ public class GHContentIntegrationTest extends AbstractGitHubWireMockTest {
|
||||
GHContent content = repo.getFileContent("ghcontent-ro/an-empty-file");
|
||||
|
||||
assertThat(content.isFile(), is(true));
|
||||
assertThat(content.getContent(), equalTo(""));
|
||||
assertThat(content.getContent(), is(emptyString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDirectoryContent() throws Exception {
|
||||
List<GHContent> entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries");
|
||||
|
||||
assertThat(entries.size() == 3, is(true));
|
||||
assertThat(entries.size(), equalTo(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +81,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");
|
||||
|
||||
assertThat(entries.get(0).getUrl().endsWith("?ref=main"), is(true));
|
||||
assertThat(entries.get(0).getUrl(), endsWith("?ref=main"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static java.lang.Boolean.TRUE;
|
||||
import static org.hamcrest.Matchers.aMapWithSize;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
@@ -314,7 +313,7 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(event.getPullRequest().getBase().getLabel(), is("trilogy-group:3.10"));
|
||||
assertThat(event.getPullRequest().getBase().getSha(), is("7a735f17d686c6a1fc7df5b9d395e5863868f364"));
|
||||
assertThat(event.getPullRequest().isMerged(), is(false));
|
||||
assertThat(event.getPullRequest().getMergeable(), is(TRUE));
|
||||
assertThat(event.getPullRequest().getMergeable(), is(true));
|
||||
assertThat(event.getPullRequest().getMergeableState(), is("draft"));
|
||||
assertThat(event.getPullRequest().getMergedBy(), nullValue());
|
||||
assertThat(event.getPullRequest().getCommentsCount(), is(1));
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -102,10 +100,10 @@ public class GHGistTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(gist.getOwner().getLogin(), equalTo("rtyler"));
|
||||
|
||||
gist.star();
|
||||
assertThat(gist.isStarred(), Matchers.is(true));
|
||||
assertThat(gist.isStarred(), is(true));
|
||||
|
||||
gist.unstar();
|
||||
assertThat(gist.isStarred(), Matchers.is(false));
|
||||
assertThat(gist.isStarred(), is(false));
|
||||
|
||||
GHGist newGist = gist.fork();
|
||||
|
||||
@@ -127,7 +125,7 @@ public class GHGistTest extends AbstractGitHubWireMockTest {
|
||||
public void gistFile() throws Exception {
|
||||
GHGist gist = gitHub.getGist("9903708");
|
||||
|
||||
assertThat(gist.isPublic(), Matchers.is(true));
|
||||
assertThat(gist.isPublic(), is(true));
|
||||
assertThat(gist.getId(), equalTo(9903708L));
|
||||
assertThat(gist.getGistId(), equalTo("9903708"));
|
||||
|
||||
@@ -136,7 +134,6 @@ public class GHGistTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
assertThat(f.getType(), equalTo("text/markdown"));
|
||||
assertThat(f.getLanguage(), equalTo("Markdown"));
|
||||
assertThat(f.getContent().contains("### Keybase proof"), Matchers.is(true));
|
||||
assertThat(f.getContent(), notNullValue());
|
||||
assertThat(f.getContent(), containsString("### Keybase proof"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* @author Martin van Zijl
|
||||
@@ -54,17 +53,17 @@ public class GHGistUpdaterTest extends AbstractGitHubWireMockTest {
|
||||
Map<String, GHGistFile> files = updatedGist.getFiles();
|
||||
|
||||
// Check that the unmodified file stays intact.
|
||||
assertThat(files.containsKey("unmodified.txt"), is(true));
|
||||
assertThat(files.get("unmodified.txt"), is(notNullValue()));
|
||||
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"));
|
||||
|
||||
assertThat(files.containsKey("new-file.txt"), is(true));
|
||||
assertThat(files.get("new-file.txt"), is(notNullValue()));
|
||||
assertThat(files.get("new-file.txt").getContent(), equalTo("Added by updater"));
|
||||
|
||||
assertThat(files.containsKey("rename-me.py"), is(false));
|
||||
assertThat(files.containsKey("renamed.py"), is(true));
|
||||
assertThat(files.get("renamed.py"), is(notNullValue()));
|
||||
assertThat(files.get("renamed.py").getContent(), equalTo("print 'hello'"));
|
||||
|
||||
assertThat(files.get("update-me.txt").getContent(), equalTo("Content updated by API"));
|
||||
|
||||
@@ -43,7 +43,7 @@ public class GHIssueEventTest extends AbstractGitHubWireMockTest {
|
||||
public void testRepositoryEvents() throws Exception {
|
||||
GHRepository repo = getRepository();
|
||||
List<GHIssueEvent> list = repo.listIssueEvents().toList();
|
||||
assertThat(list.size() > 0, is(true));
|
||||
assertThat(list, is(not(empty())));
|
||||
|
||||
int i = 0;
|
||||
for (GHIssueEvent event : list) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
public void listLicenses() throws IOException {
|
||||
Iterable<GHLicense> licenses = gitHub.listLicenses();
|
||||
assertThat(licenses.iterator().hasNext(), is(true));
|
||||
assertThat(licenses, is(not(emptyIterable())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
PagedIterable<GHLicense> licenses = gitHub.listLicenses();
|
||||
for (GHLicense lic : licenses) {
|
||||
if (lic.getKey().equals("mit")) {
|
||||
assertThat(lic.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")), is(true));
|
||||
assertThat(lic.getUrl(), equalTo(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -84,8 +84,8 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
license.getHtmlUrl(),
|
||||
equalTo(new URL("http://choosealicense.com/licenses/mit/")));
|
||||
assertThat(license.getBody(), startsWith("MIT License\n" + "\n" + "Copyright (c) [year] [fullname]\n\n"));
|
||||
assertThat(license.getForbidden().size(), equalTo(0));
|
||||
assertThat(license.getPermitted().size(), equalTo(0));
|
||||
assertThat(license.getForbidden(), is(empty()));
|
||||
assertThat(license.getPermitted(), is(empty()));
|
||||
assertThat(license.getImplementation(),
|
||||
equalTo("Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders."));
|
||||
assertThat(license.getCategory(), nullValue());
|
||||
@@ -106,11 +106,11 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
GHRepository repo = gitHub.getRepository("hub4j/github-api");
|
||||
GHLicense license = repo.getLicense();
|
||||
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 key is correct", license.getKey(), equalTo("mit"));
|
||||
assertThat("The name is correct", license.getName(), equalTo("MIT License"));
|
||||
assertThat("The URL is correct",
|
||||
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")),
|
||||
is(true));
|
||||
license.getUrl(),
|
||||
equalTo(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,11 +124,11 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
GHRepository repo = gitHub.getRepository("atom/atom");
|
||||
GHLicense license = repo.getLicense();
|
||||
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 key is correct", license.getKey(), equalTo("mit"));
|
||||
assertThat("The name is correct", license.getName(), equalTo("MIT License"));
|
||||
assertThat("The URL is correct",
|
||||
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")),
|
||||
is(true));
|
||||
license.getUrl(),
|
||||
equalTo(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,11 +142,11 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
GHRepository repo = gitHub.getRepository("pomes/pomes");
|
||||
GHLicense license = repo.getLicense();
|
||||
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 key is correct", license.getKey(), equalTo("apache-2.0"));
|
||||
assertThat("The name is correct", license.getName(), equalTo("Apache License 2.0"));
|
||||
assertThat("The URL is correct",
|
||||
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/apache-2.0")),
|
||||
is(true));
|
||||
license.getUrl(),
|
||||
equalTo(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/apache-2.0")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,14 +175,14 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
GHRepository repo = gitHub.getRepository("hub4j/github-api");
|
||||
GHLicense license = repo.getLicense();
|
||||
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 key is correct", license.getKey(), equalTo("mit"));
|
||||
assertThat("The name is correct", license.getName(), equalTo("MIT License"));
|
||||
assertThat("The URL is correct",
|
||||
license.getUrl().equals(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")),
|
||||
is(true));
|
||||
license.getUrl(),
|
||||
equalTo(new URL(mockGitHub.apiServer().baseUrl() + "/licenses/mit")));
|
||||
assertThat("The HTML URL is correct",
|
||||
license.getHtmlUrl().equals(new URL("http://choosealicense.com/licenses/mit/")),
|
||||
is(true));
|
||||
license.getHtmlUrl(),
|
||||
equalTo(new URL("http://choosealicense.com/licenses/mit/")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,12 +197,12 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
|
||||
GHRepository repo = gitHub.getRepository("pomes/pomes");
|
||||
GHContent content = repo.getLicenseContent();
|
||||
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));
|
||||
assertThat("The type is 'file'", content.getType(), equalTo("file"));
|
||||
assertThat("The license file is 'LICENSE'", content.getName(), equalTo("LICENSE"));
|
||||
|
||||
if (content.getEncoding().equals("base64")) {
|
||||
String licenseText = new String(IOUtils.toByteArray(content.read()));
|
||||
assertThat("The license appears to be an Apache License", licenseText.contains("Apache License"), is(true));
|
||||
assertThat("The license appears to be an Apache License", licenseText.contains("Apache License"));
|
||||
} else {
|
||||
fail("Expected the license to be Base64 encoded but instead it was " + content.getEncoding());
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
|
||||
// primitive fields
|
||||
assertThat(plan.getId(), not(0L));
|
||||
assertThat(plan.getNumber(), not(0L));
|
||||
assertThat(plan.getMonthlyPriceInCents() >= 0, is(true));
|
||||
assertThat(plan.getMonthlyPriceInCents(), greaterThanOrEqualTo(0L));
|
||||
|
||||
// list
|
||||
assertThat(plan.getBullets().size(), equalTo(2));
|
||||
|
||||
@@ -70,7 +70,7 @@ public class GHMilestoneTest extends AbstractGitHubWireMockTest {
|
||||
// remove the milestone
|
||||
issue.setMilestone(null);
|
||||
issue = repo.getIssue(issue.getNumber()); // force reload
|
||||
assertThat(issue.getMilestone(), equalTo(null));
|
||||
assertThat(issue.getMilestone(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.kohsuke.github.GHOrganization.Permission;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@@ -140,19 +141,20 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
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));
|
||||
assertThat(admins.size(), greaterThanOrEqualTo(12));
|
||||
assertThat(admins.stream().map(GHUser::getLogin).collect(Collectors.toList()),
|
||||
hasItems("alexanderrtaylor",
|
||||
"asthinasthi",
|
||||
"bitwiseman",
|
||||
"farmdawgnation",
|
||||
"halkeye",
|
||||
"jberglund-BSFT",
|
||||
"kohsuke",
|
||||
"kohsuke2",
|
||||
"martinvanzijl",
|
||||
"PauloMigAlmeida",
|
||||
"Sage-Pierce",
|
||||
"timja"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,19 +165,20 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
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));
|
||||
assertThat(admins.size(), greaterThanOrEqualTo(12));
|
||||
assertThat(admins.stream().map(GHUser::getLogin).collect(Collectors.toList()),
|
||||
hasItems("alexanderrtaylor",
|
||||
"asthinasthi",
|
||||
"bitwiseman",
|
||||
"farmdawgnation",
|
||||
"halkeye",
|
||||
"jberglund-BSFT",
|
||||
"kohsuke",
|
||||
"kohsuke2",
|
||||
"martinvanzijl",
|
||||
"PauloMigAlmeida",
|
||||
"Sage-Pierce",
|
||||
"timja"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -113,7 +113,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "main", "## test");
|
||||
try {
|
||||
// System.out.println(p.getUrl());
|
||||
assertThat(p.listReviewComments().toList().isEmpty(), is(true));
|
||||
assertThat(p.listReviewComments().toList(), is(empty()));
|
||||
p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1);
|
||||
List<GHPullRequestReviewComment> comments = p.listReviewComments().toList();
|
||||
assertThat(comments.size(), equalTo(1));
|
||||
@@ -129,7 +129,7 @@ public class GHPullRequestTest extends AbstractGitHubWireMockTest {
|
||||
containsString("hub4j-test-org/github-api/pull/" + p.getNumber()));
|
||||
|
||||
List<GHReaction> reactions = comment.listReactions().toList();
|
||||
assertThat(reactions.size(), equalTo(0));
|
||||
assertThat(reactions, is(empty()));
|
||||
|
||||
GHReaction reaction = comment.createReaction(ReactionContent.CONFUSED);
|
||||
assertThat(reaction.getContent(), equalTo(ReactionContent.CONFUSED));
|
||||
@@ -164,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());
|
||||
assertThat(p.getRequestedReviewers().isEmpty(), is(true));
|
||||
assertThat(p.getRequestedReviewers(), is(empty()));
|
||||
|
||||
GHUser kohsuke2 = gitHub.getUser("kohsuke2");
|
||||
p.requestReviewers(Collections.singletonList(kohsuke2));
|
||||
p.refresh();
|
||||
assertThat(p.getRequestedReviewers().isEmpty(), is(false));
|
||||
assertThat(p.getRequestedReviewers(), is(not(empty())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,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());
|
||||
assertThat(p.getRequestedReviewers().isEmpty(), is(true));
|
||||
assertThat(p.getRequestedReviewers(), is(empty()));
|
||||
|
||||
GHOrganization testOrg = gitHub.getOrganization("hub4j-test-org");
|
||||
GHTeam testTeam = testOrg.getTeamBySlug("dummy-team");
|
||||
|
||||
@@ -493,7 +493,7 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
|
||||
// This time, rateLimit() should find an expired record and get a new one.
|
||||
Thread.sleep(2500);
|
||||
|
||||
assertThat("Header instance has expired", gitHub.lastRateLimit().isExpired(), is(true));
|
||||
assertThat("Header instance has expired", gitHub.lastRateLimit().isExpired());
|
||||
|
||||
assertThat("rateLimit() will ask server when cached instance has expired",
|
||||
gitHub.rateLimit(),
|
||||
|
||||
@@ -7,7 +7,6 @@ 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 {
|
||||
|
||||
@@ -60,7 +59,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertThat("Did not find author " + authorLogin, developerFound, is(true));
|
||||
assertThat("Did not find author " + authorLogin, developerFound);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +104,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat("Could not find week starting 1546128000", foundWeek, is(true));
|
||||
assertThat("Could not find week starting 1546128000", foundWeek);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,7 +141,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat("Could not find week starting 1535241600", foundWeek, is(true));
|
||||
assertThat("Could not find week starting 1535241600", foundWeek);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,7 +207,7 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat("Hour 10 for Day 2 not found.", hourFound, is(true));
|
||||
assertThat("Hour 10 for Day 2 not found.", hourFound);
|
||||
}
|
||||
|
||||
protected GHRepository getRepository() throws IOException {
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
@@ -133,7 +134,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
public void listStargazers() throws IOException {
|
||||
GHRepository repository = getRepository();
|
||||
assertThat(repository.listStargazers2().toList(), empty());
|
||||
assertThat(repository.listStargazers2().toList(), is(empty()));
|
||||
|
||||
repository = gitHub.getOrganization("hub4j").getRepository("github-api");
|
||||
Iterable<GHStargazer> stargazers = repository.listStargazers2();
|
||||
@@ -283,7 +284,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
for (GHRepository.Contributor c : r.listContributors()) {
|
||||
if (c.getLogin().equals("kohsuke")) {
|
||||
assertThat(c.getContributions() > 0, is(true));
|
||||
assertThat(c.getContributions(), greaterThan(0));
|
||||
kohsuke = true;
|
||||
}
|
||||
if (i++ > 5) {
|
||||
@@ -365,7 +366,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
public void listReleases() throws IOException {
|
||||
PagedIterable<GHRelease> releases = gitHub.getOrganization("github").getRepository("hub").listReleases();
|
||||
assertThat(releases.iterator().hasNext(), is(true));
|
||||
assertThat(releases, is(not(emptyIterable())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -418,17 +419,17 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
.listCommitComments("499d91f9f846b0087b2a20cf3648b49dc9c2eeef")
|
||||
.toList();
|
||||
|
||||
assertThat("Two comments present", commitComments.size() == 2);
|
||||
assertThat("Comment text found", commitComments.stream().anyMatch(it -> it.body.equals("comment 1")));
|
||||
assertThat("Comment text found", commitComments.stream().anyMatch(it -> it.body.equals("comment 2")));
|
||||
assertThat("Two comments present", commitComments.size(), equalTo(2));
|
||||
assertThat("Comment text found",
|
||||
commitComments.stream().map(GHCommitComment::getBody).collect(Collectors.toList()),
|
||||
containsInAnyOrder("comment 1", "comment 2"));
|
||||
}
|
||||
|
||||
@Test // Issue #261
|
||||
public void listEmptyContributors() throws IOException {
|
||||
for (GHRepository.Contributor c : gitHub.getRepository(GITHUB_API_TEST_ORG + "/empty").listContributors()) {
|
||||
// System.out.println(c);
|
||||
fail("This list should be empty, but should return a valid empty iterable.");
|
||||
}
|
||||
assertThat("This list should be empty, but should return a valid empty iterable.",
|
||||
gitHub.getRepository(GITHUB_API_TEST_ORG + "/empty").listContributors(),
|
||||
is(emptyIterable()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -442,7 +443,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
// System.out.println(u.getName());
|
||||
assertThat(u.getId(), notNullValue());
|
||||
assertThat(u.getLanguage(), equalTo("Assembly"));
|
||||
assertThat(r.getTotalCount() > 0, is(true));
|
||||
assertThat(r.getTotalCount(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test // issue #162
|
||||
@@ -467,11 +468,11 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
String actual = IOUtils.toString(
|
||||
gitHub.getRepository("hub4j/github-api").renderMarkdown("@kohsuke to fix issue #1", MarkdownMode.GFM));
|
||||
// System.out.println(actual);
|
||||
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));
|
||||
assertThat(actual, containsString("href=\"https://github.com/kohsuke\""));
|
||||
assertThat(actual, containsString("href=\"https://github.com/hub4j/github-api/pull/1\""));
|
||||
assertThat(actual, containsString("class=\"user-mention\""));
|
||||
assertThat(actual, containsString("class=\"issue-link "));
|
||||
assertThat(actual, containsString("to fix issue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -557,7 +558,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
topics = new ArrayList<>();
|
||||
repo.setTopics(topics);
|
||||
assertThat("Topics can be set to empty", repo.listTopics().isEmpty(), is(true));
|
||||
assertThat("Topics can be set to empty", repo.listTopics(), is(empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -571,7 +572,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
public void getPostCommitHooks() throws Exception {
|
||||
GHRepository repo = getRepository(gitHub);
|
||||
Set<URL> postcommitHooks = repo.getPostCommitHooks();
|
||||
assertThat(postcommitHooks.size(), equalTo(0));
|
||||
assertThat(postcommitHooks, is(empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -718,7 +719,7 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
|
||||
GHRepository repo = getTempRepository();
|
||||
List<GHTag> refs = repo.listTags().toList();
|
||||
assertThat(refs, notNullValue());
|
||||
assertThat(refs.size(), equalTo(0));
|
||||
assertThat(refs, is(empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,8 +7,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class GHTeamTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
@@ -45,7 +44,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
|
||||
List<GHUser> admins = team.listMembers("admin").toList();
|
||||
|
||||
assertThat(admins, notNullValue());
|
||||
assertThat("One admin in dummy team", admins.size() == 1);
|
||||
assertThat("One admin in dummy team", admins.size(), equalTo(1));
|
||||
assertThat("Specific user in admin team",
|
||||
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
|
||||
}
|
||||
@@ -104,7 +103,7 @@ public class GHTeamTest extends AbstractGitHubWireMockTest {
|
||||
GHTeam team = org.getTeamBySlug(teamSlug);
|
||||
Set<GHTeam> result = team.listChildTeams().toSet();
|
||||
|
||||
assertThat(result.size(), equalTo(0));
|
||||
assertThat(result, is(empty()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,125 +13,125 @@ public class GHVerificationReasonTest extends AbstractGitHubWireMockTest {
|
||||
public void testExpiredKey() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f01");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.EXPIRED_KEY,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.EXPIRED_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotSigningKey() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f02");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.NOT_SIGNING_KEY,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.NOT_SIGNING_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGpgverifyError() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f03");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.GPGVERIFY_ERROR,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.GPGVERIFY_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGpgverifyUnavailable() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f04");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.GPGVERIFY_UNAVAILABLE,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.GPGVERIFY_UNAVAILABLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsigned() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f05");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.UNSIGNED, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(), equalTo(GHVerification.Reason.UNSIGNED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownSignatureType() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f06");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.UNKNOWN_SIGNATURE_TYPE,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.UNKNOWN_SIGNATURE_TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoUser() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f07");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.NO_USER, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(), equalTo(GHVerification.Reason.NO_USER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnverifiedEmail() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f08");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.UNVERIFIED_EMAIL,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.UNVERIFIED_EMAIL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadEmail() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f09");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.BAD_EMAIL, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(), equalTo(GHVerification.Reason.BAD_EMAIL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownKey() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f10");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.UNKNOWN_KEY,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.UNKNOWN_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMalformedSignature() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f11");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.MALFORMED_SIGNATURE,
|
||||
equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(),
|
||||
equalTo(GHVerification.Reason.MALFORMED_SIGNATURE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalid() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f12");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
|
||||
assertThat(GHVerification.Reason.INVALID, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(), equalTo(GHVerification.Reason.INVALID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValid() throws Exception {
|
||||
GHRepository r = gitHub.getRepository("hub4j/github-api");
|
||||
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f13");
|
||||
assertThat("Sourabh Parkala", equalTo(commit.getCommitShortInfo().getAuthor().getName()));
|
||||
assertThat(commit.getCommitShortInfo().getAuthor().getName(), equalTo("Sourabh Parkala"));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(true));
|
||||
assertThat(GHVerification.Reason.VALID, equalTo(commit.getCommitShortInfo().getVerification().getReason()));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getReason(), equalTo(GHVerification.Reason.VALID));
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getPayload(), notNullValue());
|
||||
assertThat(commit.getCommitShortInfo().getVerification().getSignature(), notNullValue());
|
||||
}
|
||||
|
||||
@@ -71,15 +71,15 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
|
||||
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.getUrl().getPath(), containsString("/actions/runs/"));
|
||||
assertThat(workflowRun.getHtmlUrl().getPath(), containsString("/actions/runs/"));
|
||||
assertThat(workflowRun.getJobsUrl().getPath(), endsWith("/jobs"));
|
||||
assertThat(workflowRun.getLogsUrl().getPath(), endsWith("/logs"));
|
||||
assertThat(workflowRun.getCheckSuiteUrl().getPath(), containsString("/check-suites/"));
|
||||
assertThat(workflowRun.getArtifactsUrl().getPath(), endsWith("/artifacts"));
|
||||
assertThat(workflowRun.getCancelUrl().getPath(), endsWith("/cancel"));
|
||||
assertThat(workflowRun.getRerunUrl().getPath(), endsWith("/rerun"));
|
||||
assertThat(workflowRun.getWorkflowUrl().getPath(), containsString("/actions/workflows/"));
|
||||
assertThat(workflowRun.getHeadBranch(), equalTo(MAIN_BRANCH));
|
||||
assertThat(workflowRun.getHeadCommit().getId(), notNullValue());
|
||||
assertThat(workflowRun.getHeadCommit().getTreeId(), notNullValue());
|
||||
|
||||
@@ -143,13 +143,13 @@ public class GitHubConnectionTest extends AbstractGitHubWireMockTest {
|
||||
GitHubBuilder builder = new GitHubBuilder().withAppInstallationToken("bogus app token");
|
||||
assertThat(builder.authorizationProvider, instanceOf(UserAuthorizationProvider.class));
|
||||
assertThat(builder.authorizationProvider.getEncodedAuthorization(), equalTo("token bogus app token"));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), equalTo(""));
|
||||
assertThat(((UserAuthorizationProvider) builder.authorizationProvider).getLogin(), is(emptyString()));
|
||||
|
||||
// test authorization header is set as in the RFC6749
|
||||
GitHub github = builder.build();
|
||||
// change this to get a request
|
||||
assertThat(github.getClient().getEncodedAuthorization(), equalTo("token bogus app token"));
|
||||
assertThat(github.getClient().login, equalTo(""));
|
||||
assertThat(github.getClient().login, is(emptyString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -13,7 +13,6 @@ 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;
|
||||
@@ -140,8 +139,8 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
assertThat(rateLimit_none, equalTo(rateLimit_core));
|
||||
assertThat(rateLimit_none, not(sameInstance(rateLimit_core)));
|
||||
assertThat(rateLimit_none.hashCode() == rateLimit_core.hashCode(), is(true));
|
||||
assertThat(rateLimit_none.equals(rateLimit_core), is(true));
|
||||
assertThat(rateLimit_none.hashCode(), equalTo(rateLimit_core.hashCode()));
|
||||
assertThat(rateLimit_none, equalTo(rateLimit_core));
|
||||
|
||||
assertThat(rateLimit_none, not(equalTo(rateLimit_search)));
|
||||
|
||||
|
||||
@@ -7,12 +7,7 @@ import org.kohsuke.github.example.dataobject.ReadOnlyObjects;
|
||||
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.hamcrest.Matchers.*;
|
||||
import static org.kohsuke.github.GHMarketplaceAccountType.ORGANIZATION;
|
||||
|
||||
/**
|
||||
@@ -73,7 +68,7 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
|
||||
GHUser u = r.iterator().next();
|
||||
// System.out.println(u.getName());
|
||||
assertThat(u.getId(), notNullValue());
|
||||
assertThat(r.getTotalCount() > 0, is(true));
|
||||
assertThat(r.getTotalCount(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,7 +107,7 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
|
||||
assertThat(c.getDownloadUrl(), notNullValue());
|
||||
assertThat(c.getOwner(), notNullValue());
|
||||
assertThat(c.getOwner().getFullName(), equalTo("jquery/jquery"));
|
||||
assertThat(r.getTotalCount() > 5, is(true));
|
||||
assertThat(r.getTotalCount(), greaterThan(5));
|
||||
|
||||
PagedSearchIterable<GHContent> r2 = gitHub.searchContent()
|
||||
.q("addClass")
|
||||
@@ -220,7 +215,7 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
|
||||
// GHMarketplacePlan - primitive fields
|
||||
assertThat(plan.getId(), not(0L));
|
||||
assertThat(plan.getNumber(), not(0L));
|
||||
assertThat(plan.getMonthlyPriceInCents() >= 0, is(true));
|
||||
assertThat(plan.getMonthlyPriceInCents(), greaterThanOrEqualTo(0L));
|
||||
|
||||
// GHMarketplacePlan - list
|
||||
assertThat(plan.getBullets().size(), equalTo(2));
|
||||
@@ -264,13 +259,11 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
|
||||
// getResponseHeaderFields is deprecated but we'll use it for testing.
|
||||
assertThat(org.getResponseHeaderFields(), notNullValue());
|
||||
|
||||
// Header field names must be case-insensitive
|
||||
assertThat(org.getResponseHeaderFields().containsKey("CacHe-ContrOl"), is(true));
|
||||
|
||||
// The KeySet from header fields should also be case-insensitive
|
||||
assertThat(org.getResponseHeaderFields().keySet().contains("CacHe-ControL"), is(true));
|
||||
assertThat(org.getResponseHeaderFields().keySet().contains("CacHe-ControL"), is(true));
|
||||
assertThat("Header field names must be case-insensitive",
|
||||
org.getResponseHeaderFields().containsKey("CacHe-ContrOl"));
|
||||
|
||||
assertThat("KeySet from header fields should also be case-insensitive",
|
||||
org.getResponseHeaderFields().keySet().contains("CacHe-ControL"));
|
||||
assertThat(org.getResponseHeaderFields().get("cachE-cOntrol").get(0), is("private, max-age=60, s-maxage=60"));
|
||||
|
||||
// GitHub has started changing their headers to all lowercase.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,10 +10,7 @@ import java.io.IOException;
|
||||
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;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class LifecycleTest extends AbstractGitHubWireMockTest {
|
||||
@Test
|
||||
@@ -25,7 +21,7 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
|
||||
// GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
|
||||
|
||||
GHRepository repository = getTempRepository();
|
||||
assertThat(repository.getReleases().isEmpty(), Matchers.is(true));
|
||||
assertThat(repository.getReleases(), is(empty()));
|
||||
|
||||
GHMilestone milestone = repository.createMilestone("Initial Release", "first one");
|
||||
GHIssue issue = repository.createIssue("Test Issue")
|
||||
@@ -53,14 +49,14 @@ public class LifecycleTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
private void deleteAsset(GHRelease release, GHAsset asset) throws IOException {
|
||||
asset.delete();
|
||||
assertThat(release.getAssets().size(), equalTo(0));
|
||||
assertThat(release.getAssets(), is(empty()));
|
||||
}
|
||||
|
||||
private GHAsset uploadAsset(GHRelease release) throws IOException {
|
||||
GHAsset asset = release.uploadAsset(new File("LICENSE.txt"), "application/text");
|
||||
assertThat(asset, notNullValue());
|
||||
List<GHAsset> cachedAssets = release.assets();
|
||||
assertThat(cachedAssets.size(), equalTo(0));
|
||||
assertThat(cachedAssets, is(empty()));
|
||||
List<GHAsset> assets = release.getAssets();
|
||||
assertThat(assets.size(), equalTo(1));
|
||||
assertThat(assets.get(0).getName(), equalTo("LICENSE.txt"));
|
||||
|
||||
@@ -97,7 +97,7 @@ public class RequesterRetryTest extends AbstractGitHubWireMockTest {
|
||||
try {
|
||||
gitHub.checkApiUrlValidity();
|
||||
} catch (IOException ioe) {
|
||||
assertThat(ioe.getMessage().contains("private mode enabled"), is(true));
|
||||
assertThat(ioe.getMessage(), containsString("private mode enabled"));
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class WireMockStatusReporterTest extends AbstractGitHubWireMockTest {
|
||||
assumeTrue("Test only valid when Snapshotting (-Dtest.github.takeSnapshot to enable)",
|
||||
mockGitHub.isTakeSnapshot());
|
||||
|
||||
assertThat("When taking a snapshot, proxy should automatically be enabled", mockGitHub.isUseProxy(), is(true));
|
||||
assertThat("When taking a snapshot, proxy should automatically be enabled", mockGitHub.isUseProxy());
|
||||
}
|
||||
|
||||
@Ignore("Not implemented yet")
|
||||
|
||||
Reference in New Issue
Block a user