mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Do not inherit from Assert
This commit is contained in:
@@ -4,14 +4,10 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
||||
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
|
||||
import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.HandlebarsCurrentDateHelper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hamcrest.StringDescription;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.*;
|
||||
import org.kohsuke.github.junit.GitHubWireMockRule;
|
||||
import wiremock.com.github.jknack.handlebars.Helper;
|
||||
import wiremock.com.github.jknack.handlebars.Options;
|
||||
@@ -21,13 +17,14 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
* @author Liam Newman
|
||||
*/
|
||||
public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
public abstract class AbstractGitHubWireMockTest {
|
||||
|
||||
private final GitHubBuilder githubBuilder = createGitHubBuilder();
|
||||
|
||||
@@ -255,52 +252,79 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
return mockGitHub.isTestWithOrg() ? GITHUB_API_TEST_ORG : gitHub.getMyself().getLogin();
|
||||
}
|
||||
|
||||
public static void fail() {
|
||||
Assert.fail();
|
||||
}
|
||||
public static void fail(String reason) {
|
||||
Assert.fail(reason);
|
||||
}
|
||||
|
||||
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
|
||||
assertThat("", actual, matcher);
|
||||
MatcherAssert.assertThat("", actual, matcher);
|
||||
}
|
||||
|
||||
public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {
|
||||
if (!matcher.matches(actual)) {
|
||||
Description description = new StringDescription();
|
||||
description.appendText(reason)
|
||||
.appendText(System.lineSeparator())
|
||||
.appendText("Expected: ")
|
||||
.appendDescriptionOf(matcher)
|
||||
.appendText(System.lineSeparator())
|
||||
.appendText(" but: ");
|
||||
matcher.describeMismatch(actual, description);
|
||||
throw new AssertionError(description.toString());
|
||||
}
|
||||
MatcherAssert.assertThat(reason, actual, matcher);
|
||||
}
|
||||
|
||||
public static void assertThat(String reason, boolean assertion) {
|
||||
if (!assertion) {
|
||||
throw new AssertionError(reason);
|
||||
}
|
||||
MatcherAssert.assertThat(reason, assertion);
|
||||
}
|
||||
|
||||
public static void assertEquals(Object expected, Object actual) {
|
||||
assertThat(actual, Matchers.equalTo(expected));
|
||||
assertThat(actual, equalTo(expected));
|
||||
}
|
||||
|
||||
public static void assertEquals(String reason, Object expected, Object actual) {
|
||||
assertThat(reason, actual, equalTo(expected));
|
||||
}
|
||||
|
||||
public static void assertNotEquals(Object expected, Object actual) {
|
||||
assertThat(actual, Matchers.not(expected));
|
||||
assertThat(actual, not(expected));
|
||||
}
|
||||
|
||||
public static void assertNotEquals(String reason, Object expected, Object actual) {
|
||||
assertThat(reason, actual, not(expected));
|
||||
}
|
||||
|
||||
public static void assertNotNull(Object actual) {
|
||||
assertThat(actual, Matchers.notNullValue());
|
||||
assertThat(actual, notNullValue());
|
||||
}
|
||||
|
||||
public static void assertNotNull(String reason, Object actual) {
|
||||
assertThat(reason, actual, notNullValue());
|
||||
}
|
||||
|
||||
public static void assertNull(Object actual) {
|
||||
assertThat(actual, Matchers.nullValue());
|
||||
assertThat(actual, nullValue());
|
||||
}
|
||||
|
||||
public static void assertNull(String message, Object actual) {
|
||||
assertThat(message, actual, nullValue());
|
||||
}
|
||||
|
||||
public static void assertSame(Object expected, Object actual) {
|
||||
assertThat(actual, sameInstance(expected));
|
||||
}
|
||||
|
||||
public static void assertSame(String message, Object expected, Object actual) {
|
||||
Assert.assertSame(message, expected, actual);
|
||||
}
|
||||
|
||||
public static void assertTrue(Boolean condition) {
|
||||
assertThat(condition, Matchers.is(true));
|
||||
assertThat(condition, is(true));
|
||||
}
|
||||
|
||||
public static void assertTrue(String reason, Boolean condition) {
|
||||
assertThat(reason, condition, is(true));
|
||||
}
|
||||
|
||||
public static void assertFalse(Boolean condition) {
|
||||
assertThat(condition, Matchers.is(false));
|
||||
assertThat(condition, is(false));
|
||||
}
|
||||
|
||||
public static void assertFalse(String reason, Boolean condition) {
|
||||
assertThat(reason, condition, is(false));
|
||||
}
|
||||
|
||||
protected static class TemplatingHelper {
|
||||
|
||||
@@ -966,7 +966,7 @@ public class AppTest extends AbstractGitHubWireMockTest {
|
||||
GHLabel e = r.getLabel("enhancement");
|
||||
assertEquals("enhancement", e.getName());
|
||||
assertNotNull(e.getUrl());
|
||||
assertEquals(177339106, e.getId());
|
||||
assertEquals(177339106L, e.getId());
|
||||
assertEquals("MDU6TGFiZWwxNzczMzkxMDY=", e.getNodeId());
|
||||
assertTrue(e.isDefault());
|
||||
assertTrue(Pattern.matches("[0-9a-fA-F]{6}", e.getColor()));
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.create();
|
||||
assertEquals(Status.COMPLETED, checkRun.getStatus());
|
||||
assertEquals(1, checkRun.getOutput().getAnnotationsCount());
|
||||
assertEquals(1424883286, checkRun.getId());
|
||||
assertEquals(1424883286L, checkRun.getId());
|
||||
assertEquals("Hello Text!", checkRun.getOutput().getText());
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
assertEquals("Lots of stuff here »", checkRun.getOutput().getSummary());
|
||||
assertEquals(101, checkRun.getOutput().getAnnotationsCount());
|
||||
assertEquals("Hello Text!", checkRun.getOutput().getText());
|
||||
assertEquals(1424883599, checkRun.getId());
|
||||
assertEquals(1424883599L, checkRun.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,7 +97,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.create();
|
||||
assertEquals(Status.COMPLETED, checkRun.getStatus());
|
||||
assertEquals(0, checkRun.getOutput().getAnnotationsCount());
|
||||
assertEquals(1424883957, checkRun.getId());
|
||||
assertEquals(1424883957L, checkRun.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +108,7 @@ public class GHCheckRunBuilderTest extends AbstractGHAppInstallationTest {
|
||||
.create();
|
||||
assertEquals(Status.IN_PROGRESS, checkRun.getStatus());
|
||||
assertNull(checkRun.getConclusion());
|
||||
assertEquals(1424883451, checkRun.getId());
|
||||
assertEquals(1424883451L, checkRun.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@ public class GHDeploymentTest extends AbstractGitHubWireMockTest {
|
||||
final GHRepository repo = getRepository();
|
||||
final GHDeployment deployment = repo.getDeployment(178653229);
|
||||
assertNotNull(deployment);
|
||||
assertEquals(178653229, deployment.getId());
|
||||
assertEquals(178653229L, deployment.getId());
|
||||
assertEquals("production", deployment.getEnvironment());
|
||||
assertEquals("custom", deployment.getPayload());
|
||||
assertEquals("custom", deployment.getPayloadObject());
|
||||
@@ -33,7 +33,7 @@ public class GHDeploymentTest extends AbstractGitHubWireMockTest {
|
||||
final GHRepository repo = getRepository();
|
||||
final GHDeployment deployment = repo.getDeployment(178653229);
|
||||
assertNotNull(deployment);
|
||||
assertEquals(178653229, deployment.getId());
|
||||
assertEquals(178653229L, deployment.getId());
|
||||
assertEquals("production", deployment.getEnvironment());
|
||||
assertEquals("main", deployment.getRef());
|
||||
assertEquals("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353", deployment.getSha());
|
||||
|
||||
@@ -91,13 +91,13 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
if (item.getWeek() == 1566691200) {
|
||||
assertEquals(6, item.getTotal());
|
||||
List<Integer> days = item.getDays();
|
||||
assertEquals(0, (long) days.get(0));
|
||||
assertEquals(0, (long) days.get(1));
|
||||
assertEquals(1, (long) days.get(2));
|
||||
assertEquals(0, (long) days.get(3));
|
||||
assertEquals(0, (long) days.get(4));
|
||||
assertEquals(1, (long) days.get(5));
|
||||
assertEquals(4, (long) days.get(6));
|
||||
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));
|
||||
foundWeek = true;
|
||||
break;
|
||||
}
|
||||
@@ -132,8 +132,8 @@ public class GHRepositoryStatisticsTest extends AbstractGitHubWireMockTest {
|
||||
Boolean foundWeek = false;
|
||||
for (GHRepositoryStatistics.CodeFrequency item : stats) {
|
||||
if (item.getWeekTimestamp() == 1535241600) {
|
||||
assertEquals(185, item.getAdditions());
|
||||
assertEquals(-243, item.getDeletions());
|
||||
assertEquals(185L, item.getAdditions());
|
||||
assertEquals(-243L, item.getDeletions());
|
||||
assertEquals("Week starting 1535241600 has 185 additions and 243 deletions", item.toString());
|
||||
foundWeek = true;
|
||||
break;
|
||||
@@ -199,7 +199,7 @@ 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(16, item.getNumberOfCommits());
|
||||
assertEquals(16L, item.getNumberOfCommits());
|
||||
assertEquals("Day 2 Hour 10: 16 commits", item.toString());
|
||||
hourFound = true;
|
||||
break;
|
||||
|
||||
@@ -78,8 +78,8 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
updateTree();
|
||||
|
||||
assertEquals(CONTENT_DATA1.length, getFileSize(PATH_DATA1));
|
||||
assertEquals(CONTENT_DATA2.length, getFileSize(PATH_DATA2));
|
||||
assertEquals((long) CONTENT_DATA1.length, getFileSize(PATH_DATA1));
|
||||
assertEquals((long) CONTENT_DATA2.length, getFileSize(PATH_DATA2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,10 +91,10 @@ public class GHTreeBuilderTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
GHCommit commit = updateTree();
|
||||
|
||||
assertEquals(CONTENT_SCRIPT.length(), getFileSize(PATH_SCRIPT));
|
||||
assertEquals(CONTENT_README.length(), getFileSize(PATH_README));
|
||||
assertEquals(CONTENT_DATA1.length, getFileSize(PATH_DATA1));
|
||||
assertEquals(CONTENT_DATA2.length, getFileSize(PATH_DATA2));
|
||||
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(commit.getCommitShortInfo().getAuthor().getEmail(), equalTo("author@author.com"));
|
||||
assertThat(commit.getCommitShortInfo().getCommitter().getEmail(), equalTo("committer@committer.com"));
|
||||
|
||||
Reference in New Issue
Block a user