From d3d37fd058244c9afa344dbd3fa97ad925a47b6e Mon Sep 17 00:00:00 2001 From: Michael Tughan Date: Thu, 5 Sep 2024 12:20:48 -0400 Subject: [PATCH] Check if the same change was updated --- .../PullRequestAnalysisTest.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) 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 06e6acc..c24202b 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 @@ -113,14 +113,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 @@ -132,17 +132,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() {} }"); @@ -159,15 +159,22 @@ 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 {}", amend); GerritChange change = git.createGerritChangeForMaster(); + if (previousChange != null) { + assertThat(previousChange.changeNumericId()).isEqualTo(change.changeNumericId()); + } + triggerAndAssertSuccess(jobFactory.build(change)); ChangeInfo changeDetail = change.getDetail();