diff --git a/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java b/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java index 0c112a6..f25845b 100644 --- a/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java +++ b/src/test/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTest.java @@ -104,14 +104,14 @@ void test1() throws Exception { @Test @DisplayName("Good quality freestyle build") void test2() throws Exception { - testWithGoodQualityCode(this::createFreestyleJob, false); + testWithGoodQualityCode(this::createFreestyleJob, false, null); } @Test @DisplayName("Bad then good quality freestyle build") void test3() throws Exception { - testWithBadQualityCode(this::createFreestyleJob); - testWithGoodQualityCode(this::createFreestyleJob, true); + GerritChange change = testWithBadQualityCode(this::createFreestyleJob); + testWithGoodQualityCode(this::createFreestyleJob, true, change); } @Test @@ -123,17 +123,17 @@ void test4() throws Exception { @Test @DisplayName("Good quality pipeline build") void test5() throws Exception { - testWithGoodQualityCode(this::createPipelineJob, false); + testWithGoodQualityCode(this::createPipelineJob, false, null); } @Test @DisplayName("Bad then good quality pipeline build") void test6() throws Exception { - testWithBadQualityCode(this::createPipelineJob); - testWithGoodQualityCode(this::createFreestyleJob, true); + GerritChange change = testWithBadQualityCode(this::createPipelineJob); + testWithGoodQualityCode(this::createFreestyleJob, true, change); } - private void testWithBadQualityCode(JobFactory jobFactory) throws Exception { + private GerritChange testWithBadQualityCode(JobFactory jobFactory) throws Exception { git.addAndCommitFile( "src/main/java/org/example/Foo.java", "package org.example; public class Foo { public Foo() {} }"); @@ -150,9 +150,12 @@ private void testWithBadQualityCode(JobFactory jobFactory) throws Exception { .map(commentInfo -> commentInfo.message) .filteredOn(message -> message.contains("S1186")) .hasSize(1); + + return change; } - private void testWithGoodQualityCode(JobFactory jobFactory, boolean amend) throws Exception { + private void testWithGoodQualityCode( + JobFactory jobFactory, boolean amend, GerritChange previousChange) throws Exception { git.addAndCommitFile( "src/main/java/org/example/Foo.java", "package org.example; public interface Foo {}", @@ -167,6 +170,9 @@ private void testWithGoodQualityCode(JobFactory jobFactory, boolean amend) throw .map(approvalInfo -> approvalInfo.value) .containsExactly(1); assertThat(change.listComments()).isEmpty(); + if (previousChange != null) { + assertThat(previousChange.changeNumericId()).isEqualTo(change.changeNumericId()); + } } @SuppressWarnings("rawtypes")