Skip to content

Commit

Permalink
Implement two separate builders for PullRequest and Repository, resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Huginn committed Mar 25, 2024
1 parent 06702bd commit b4f8d35
Show file tree
Hide file tree
Showing 24 changed files with 570 additions and 398 deletions.
20 changes: 10 additions & 10 deletions src/test/java/io/xstefank/wildfly/bot/PRAppendingMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.quarkus.test.junit.QuarkusTest;
import io.xstefank.wildfly.bot.model.RuntimeConstants;
import io.xstefank.wildfly.bot.utils.Action;
import io.xstefank.wildfly.bot.utils.MockedContext;
import io.xstefank.wildfly.bot.utils.MockedGHPullRequest;
import io.xstefank.wildfly.bot.utils.PullRequestJson;
import io.xstefank.wildfly.bot.utils.TestConstants;
import io.xstefank.wildfly.bot.utils.Util;
Expand Down Expand Up @@ -37,7 +37,7 @@ public class PRAppendingMessageTest {

PullRequestJson pullRequestJson;

MockedContext mockedContext;
MockedGHPullRequest mockedContext;

@Test
public void testEmptyBodyAppendMessage() throws IOException {
Expand All @@ -47,7 +47,7 @@ public void testEmptyBodyAppendMessage() throws IOException {
.description(null)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00000 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
.when().payloadFromString(pullRequestJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> {
Expand All @@ -74,7 +74,7 @@ public void testNonEmptyBodyAppendMessage() throws IOException {
.description(body)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00000 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
.when().payloadFromString(pullRequestJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> {
Expand All @@ -94,7 +94,7 @@ public void testEmptyBodyAppendMessageMultipleLinks() throws IOException {
.description(null)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00002 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
.when().payloadFromString(pullRequestJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> {
Expand All @@ -121,7 +121,7 @@ public void testNonEmptyBodyAppendMessageMultipleLinks() throws IOException {
.description(body)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00002 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
.when().payloadFromString(pullRequestJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> {
Expand All @@ -142,7 +142,7 @@ public void testEmptyBodyAppendMessageMultipleDifferentLinks() throws IOExceptio
.description(null)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00002 commit")
.commit("WFLY-00003 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down Expand Up @@ -172,7 +172,7 @@ public void testNonEmptyBodyAppendMessageMultipleDifferentLinks() throws IOExcep
.description(body)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00002 commit")
.commit("WFLY-00003 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down Expand Up @@ -205,7 +205,7 @@ public void testBodyContainingSomeJirasAppendMessageMultipleDifferentLinks() thr
.description(body)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00002 commit")
.commit("WFLY-00003 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down Expand Up @@ -239,7 +239,7 @@ public void testBodyContainingAllJirasAppendMessageMultipleDifferentLinks() thro
.description(body)
.build();

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00002 commit")
.commit("WFLY-00003 commit");
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;
import io.xstefank.wildfly.bot.utils.MockedContext;
import io.xstefank.wildfly.bot.utils.Mockable;
import io.xstefank.wildfly.bot.utils.MockedGHPullRequest;
import io.xstefank.wildfly.bot.utils.PullRequestJson;
import io.xstefank.wildfly.bot.utils.TestConstants;
import io.xstefank.wildfly.bot.utils.Util;
Expand All @@ -29,7 +30,7 @@ public class PRAutomaticLabelingTest {

private String wildflyConfigFile;
private static PullRequestJson pullRequestJson;
private MockedContext mockedContext;
private Mockable mockedContext;

@BeforeAll
static void setupTests() throws IOException {
Expand All @@ -40,8 +41,8 @@ static void setupTests() throws IOException {

@Test
public void testNotApplyAndRemoveRebaseThisLabel() throws IOException {
mockedContext = MockedContext.builder(pullRequestJson.id())
.prLabels(LABEL_NEEDS_REBASE, LABEL_FIX_ME);
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.labels(LABEL_NEEDS_REBASE, LABEL_FIX_ME);
wildflyConfigFile = """
wildfly:
rules:
Expand Down Expand Up @@ -69,7 +70,7 @@ public void testApplyRebaseThisLabel() throws IOException {
- id: "Label rule"
title: WFLY
""";
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.mergeable(Boolean.FALSE);
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
.when().payloadFromString(pullRequestJson.jsonString())
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/io/xstefank/wildfly/bot/PRChecksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;
import io.xstefank.wildfly.bot.utils.MockedContext;
import io.xstefank.wildfly.bot.utils.Mockable;
import io.xstefank.wildfly.bot.utils.MockedGHPullRequest;
import io.xstefank.wildfly.bot.utils.PullRequestJson;
import io.xstefank.wildfly.bot.utils.Util;
import org.junit.jupiter.api.Test;
Expand All @@ -29,7 +30,7 @@ public class PRChecksTest {

private static String wildflyConfigFile;
private static PullRequestJson pullRequestJson;
private MockedContext mockedContext;
private Mockable mockedContext;

@Test
void testNoConfigFile() throws IOException {
Expand All @@ -45,7 +46,7 @@ void testNoConfigFile() throws IOException {
.title(INVALID_TITLE)
.description(INVALID_DESCRIPTION)
.build();
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);

given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down Expand Up @@ -108,7 +109,7 @@ void testAllChecksFail() throws IOException {
.title(INVALID_TITLE)
.description(INVALID_DESCRIPTION)
.build();
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);

given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down
17 changes: 9 additions & 8 deletions src/test/java/io/xstefank/wildfly/bot/PRCommitCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;
import io.xstefank.wildfly.bot.utils.MockedContext;
import io.xstefank.wildfly.bot.utils.Mockable;
import io.xstefank.wildfly.bot.utils.MockedGHPullRequest;
import io.xstefank.wildfly.bot.utils.PullRequestJson;
import io.xstefank.wildfly.bot.utils.Util;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class PRCommitCheckTest {

private static String wildflyConfigFile;
private static PullRequestJson pullRequestJson;
private MockedContext mockedContext;
private Mockable mockedContext;

@BeforeAll
static void setUpGitHubJson() throws IOException {
Expand All @@ -47,7 +48,7 @@ void testFailedCommitCheck() throws IOException {
commit:
enabled: true
""";
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
.when().payloadFromString(pullRequestJson.jsonString())
Expand All @@ -67,7 +68,7 @@ void testFailedCommitCheckCommitConfigNull() throws IOException {
format:
commit:
""";
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);

given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand Down Expand Up @@ -112,7 +113,7 @@ void testSuccessfulMultilinedCommitCheck() throws IOException {
enabled: true
""";

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("""
WFLY-18341 Restore incorrectly updated copyright dates in Jipijapa
Expand Down Expand Up @@ -155,7 +156,7 @@ void testDisabledCommitCheck() throws IOException {
commit:
enabled: false
""";
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);

given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand All @@ -176,7 +177,7 @@ public void testOverridingCommitMessage() throws IOException {
message: "Lorem ipsum dolor sit amet"
""";

mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);

given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext))
Expand All @@ -196,7 +197,7 @@ public void testDisableGlobalFormatCheck() throws IOException {
format:
enabled: false
""";
mockedContext = MockedContext.builder(pullRequestJson.id())
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit(INVALID_COMMIT_MESSAGE);
given().github(mocks -> Util.mockRepo(mocks, wildflyConfigFile, pullRequestJson))
.when().payloadFromString(pullRequestJson.jsonString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;
import io.xstefank.wildfly.bot.model.RuntimeConstants;
import io.xstefank.wildfly.bot.utils.MockedContext;
import io.xstefank.wildfly.bot.utils.MockedGHPullRequest;
import io.xstefank.wildfly.bot.utils.PullRequestJson;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -59,8 +59,8 @@ void testUpdateIncorrectlyIndentedFile() throws IOException {
- [email protected]""",
"UTF-8"));

MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mock(mocks);
})
.when().payloadFromString(pullRequestJson.jsonString())
Expand Down Expand Up @@ -99,8 +99,8 @@ void testUpdateToCorrectFile() throws IOException {
- [email protected]""",
"UTF-8"));

MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mock(mocks);
})
.when().payloadFromString(pullRequestJson.jsonString())
Expand Down Expand Up @@ -137,8 +137,8 @@ void testUpdateWithIncorrectRulesFile() throws IOException {
- [email protected]""",
"UTF-8"));

MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mock(mocks);
})
.when().payloadFromString(pullRequestJson.jsonString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;
import io.xstefank.wildfly.bot.model.RuntimeConstants;
import io.xstefank.wildfly.bot.utils.MockedContext;
import io.xstefank.wildfly.bot.utils.Mockable;
import io.xstefank.wildfly.bot.utils.MockedGHPullRequest;
import io.xstefank.wildfly.bot.utils.MockedGHRepository;
import io.xstefank.wildfly.bot.utils.PullRequestJson;
import io.xstefank.wildfly.bot.utils.TestConstants;
import org.apache.commons.io.IOUtils;
Expand All @@ -27,7 +29,7 @@
public class PRDirectoriesVerificationTest {

private static PullRequestJson pullRequestJson;
private MockedContext mockedContext;
private Mockable mockedContext;

@BeforeAll
public static void setupTests() throws IOException {
Expand All @@ -37,9 +39,10 @@ public static void setupTests() throws IOException {

@Test
public void existingDirectoryTest() throws IOException {
mockedContext = MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
.repoDirectories("src");
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mockNext(MockedGHRepository.builder())
.directories("src");
given().github(mocks -> {
mockedContext.mock(mocks);
GHRepository repo = mocks.repository(TestConstants.TEST_REPO);
Expand All @@ -66,8 +69,8 @@ public void existingDirectoryTest() throws IOException {

@Test
public void nonExistingDirectoryTest() throws IOException {
mockedContext = MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml");
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml");
given().github(mocks -> {
mockedContext.mock(mocks);
GHRepository repo = mocks.repository(TestConstants.TEST_REPO);
Expand Down Expand Up @@ -96,9 +99,10 @@ public void nonExistingDirectoryTest() throws IOException {

@Test
public void existingFileTest() throws IOException {
mockedContext = MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
.repoFiles("pom.xml");
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mockNext(MockedGHRepository.builder())
.files("pom.xml");
given().github(mocks -> {
mockedContext.mock(mocks);
GHRepository repo = mocks.repository(TestConstants.TEST_REPO);
Expand All @@ -123,9 +127,10 @@ public void existingFileTest() throws IOException {

@Test
public void oneExistingSubdirectoryTest() throws IOException {
mockedContext = MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
.repoDirectories("src", "src/main", "src/main/java");
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mockNext(MockedGHRepository.builder())
.directories("src", "src/main", "src/main/java");
given().github(mocks -> {
mockedContext.mock(mocks);
GHRepository repo = mocks.repository(TestConstants.TEST_REPO);
Expand Down Expand Up @@ -155,10 +160,11 @@ public void oneExistingSubdirectoryTest() throws IOException {

@Test
public void oneExistingFileInSubdirectoryTest() throws IOException {
mockedContext = MockedContext.builder(pullRequestJson.id())
.prFiles(".github/wildfly-bot.yml")
.repoDirectories("src", "src/main", "src/main/java")
.repoFiles("src/main/resources/application.properties");
mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.files(".github/wildfly-bot.yml")
.mockNext(MockedGHRepository.builder())
.directories("src", "src/main", "src/main/java")
.files("src/main/resources/application.properties");
given().github(mocks -> {
mockedContext.mock(mocks);
GHRepository repo = mocks.repository(TestConstants.TEST_REPO);
Expand Down
Loading

0 comments on commit b4f8d35

Please sign in to comment.