diff --git a/src/main/java/io/jenkins/plugins/analysis/core/quality/QualityGate.java b/src/main/java/io/jenkins/plugins/analysis/core/quality/QualityGate.java index 264c740b..b680769c 100644 --- a/src/main/java/io/jenkins/plugins/analysis/core/quality/QualityGate.java +++ b/src/main/java/io/jenkins/plugins/analysis/core/quality/QualityGate.java @@ -223,71 +223,71 @@ public Result getOverallResult() { return Result.SUCCESS; } - public Collection getEvaluations(final AnalysisResult issues, final Thresholds thresholds) { + public Collection getEvaluations(final AnalysisResult result, final QualityGate thresholds) { List messages = new ArrayList<>(); - if (!totalFailed.isTotalReached()) { + if (totalFailed.isTotalReached()) { messages.add(String.format("FAILURE -> Total number of issues: %d - Quality Gate: %d", - issues.getTotalSize(), thresholds.failedTotalAll)); + result.getTotalSize(), thresholds.getTotalFailedThreshold().getTotalThreshold())); } - if (!totalFailed.isHighReached()) { + if (totalFailed.isHighReached()) { messages.add(String.format("FAILURE -> Number of high priority issues: %d - Quality Gate: %d", - issues.getTotalHighPrioritySize(), thresholds.failedTotalHigh)); + result.getTotalHighPrioritySize(), thresholds.getTotalFailedThreshold().getHighThreshold())); } - if (!totalFailed.isNormalReached()) { + if (totalFailed.isNormalReached()) { messages.add(String.format("FAILURE -> Number of normal priority issues: %d - Quality Gate: %d", - issues.getTotalNormalPrioritySize(), thresholds.failedTotalNormal)); + result.getTotalNormalPrioritySize(), thresholds.getTotalFailedThreshold().getNormalThreshold())); } - if (!totalFailed.isLowReached()) { + if (totalFailed.isLowReached()) { messages.add(String.format("FAILURE -> Number of low priority issues: %d - Quality Gate: %d", - issues.getTotalLowPrioritySize(), thresholds.failedTotalLow)); + result.getTotalLowPrioritySize(), thresholds.getTotalFailedThreshold().getLowThreshold())); } - if (!totalUnstable.isTotalReached()) { + if (totalUnstable.isTotalReached()) { messages.add(String.format("UNSTABLE -> Total number of issues: %d - Quality Gate: %d", - issues.getTotalSize(), thresholds.unstableTotalAll)); + result.getTotalSize(), thresholds.getTotalUnstableThreshold().getTotalThreshold())); } - if (!totalUnstable.isHighReached()) { + if (totalUnstable.isHighReached()) { messages.add(String.format("UNSTABLE -> Number of high priority issues: %d - Quality Gate: %d", - issues.getTotalHighPrioritySize(), thresholds.unstableTotalHigh)); + result.getTotalHighPrioritySize(), thresholds.getTotalUnstableThreshold().getHighThreshold())); } - if (!totalUnstable.isNormalReached()) { + if (totalUnstable.isNormalReached()) { messages.add(String.format("UNSTABLE -> Number of normal priority issues: %d - Quality Gate: %d", - issues.getTotalNormalPrioritySize(), thresholds.unstableTotalNormal)); + result.getTotalNormalPrioritySize(), thresholds.getTotalUnstableThreshold().getNormalThreshold())); } - if (!totalUnstable.isLowReached()) { + if (totalUnstable.isLowReached()) { messages.add(String.format("UNSTABLE -> Number of low priority issues: %d - Quality Gate: %d", - issues.getTotalLowPrioritySize(), thresholds.unstableTotalLow)); + result.getTotalLowPrioritySize(), thresholds.getTotalUnstableThreshold().getLowThreshold())); } - if (!newFailed.isTotalReached()) { + if (newFailed.isTotalReached()) { messages.add(String.format("FAILURE -> Number of new issues: %d - Quality Gate: %d", - issues.getNewSize(), thresholds.failedNewAll)); + result.getNewSize(), thresholds.getNewFailedThreshold().getTotalThreshold())); } - if (!newFailed.isHighReached()) { + if (newFailed.isHighReached()) { messages.add(String.format("FAILURE -> Number of new high priority issues: %d - Quality Gate: %d", - issues.getNewHighPrioritySize(), thresholds.failedNewHigh)); + result.getNewHighPrioritySize(), thresholds.getNewFailedThreshold().getHighThreshold())); } - if (!newFailed.isNormalReached()) { + if (newFailed.isNormalReached()) { messages.add(String.format("FAILURE -> Number of new normal priority issues: %d - Quality Gate: %d", - issues.getNewNormalPrioritySize(), thresholds.failedNewNormal)); + result.getNewNormalPrioritySize(), thresholds.getNewFailedThreshold().getNormalThreshold())); } - if (!newFailed.isLowReached()) { + if (newFailed.isLowReached()) { messages.add(String.format("FAILURE -> Number of new low priority issues: %d - Quality Gate: %d", - issues.getNewLowPrioritySize(), thresholds.failedNewLow)); + result.getNewLowPrioritySize(), thresholds.getNewFailedThreshold().getLowThreshold())); } - if (!newUnstable.isTotalReached()) { + if (newUnstable.isTotalReached()) { messages.add(String.format("UNSTABLE -> New number of new issues: %d - Quality Gate: %d", - issues.getNewSize(), thresholds.unstableNewAll)); + result.getNewSize(), thresholds.getNewUnstableThreshold().getTotalThreshold())); } - if (!newUnstable.isHighReached()) { + if (newUnstable.isHighReached()) { messages.add(String.format("UNSTABLE -> Number of new high priority issues: %d - Quality Gate: %d", - issues.getNewHighPrioritySize(), thresholds.unstableNewHigh)); + result.getNewHighPrioritySize(), thresholds.getNewUnstableThreshold().getHighThreshold())); } - if (!newUnstable.isNormalReached()) { + if (newUnstable.isNormalReached()) { messages.add(String.format("UNSTABLE -> Number of new normal priority issues: %d - Quality Gate: %d", - issues.getNewNormalPrioritySize(), thresholds.unstableNewNormal)); + result.getNewNormalPrioritySize(), thresholds.getNewUnstableThreshold().getNormalThreshold())); } - if (!newUnstable.isLowReached()) { + if (newUnstable.isLowReached()) { messages.add(String.format("UNSTABLE -> Number of new low priority issues: %d - Quality Gate: %d", - issues.getNewLowPrioritySize(), thresholds.unstableNewLow)); + result.getNewLowPrioritySize(), thresholds.getNewUnstableThreshold().getLowThreshold())); } return messages; } diff --git a/src/main/java/io/jenkins/plugins/analysis/core/quality/ThresholdSet.java b/src/main/java/io/jenkins/plugins/analysis/core/quality/ThresholdSet.java index d98511e7..381c69e6 100644 --- a/src/main/java/io/jenkins/plugins/analysis/core/quality/ThresholdSet.java +++ b/src/main/java/io/jenkins/plugins/analysis/core/quality/ThresholdSet.java @@ -27,7 +27,7 @@ public boolean isTotalThresholdReached(final int toCheck) { return isSingleThresholdReached(getTotalThreshold(), toCheck); } - private int getTotalThreshold() { + int getTotalThreshold() { return totalThreshold; } @@ -35,7 +35,7 @@ public boolean isHighThresholdReached(final int toCheck) { return isSingleThresholdReached(getHighThreshold(), toCheck); } - private int getHighThreshold() { + int getHighThreshold() { return highThreshold; } @@ -43,7 +43,7 @@ public boolean isNormalThresholdReached(final int toCheck) { return isSingleThresholdReached(getNormalThreshold(), toCheck); } - private int getNormalThreshold() { + int getNormalThreshold() { return normalThreshold; } @@ -51,7 +51,7 @@ public boolean isLowThresholdReached(final int toCheck) { return isSingleThresholdReached(getLowThreshold(), toCheck); } - private int getLowThreshold() { + int getLowThreshold() { return lowThreshold; } diff --git a/src/test/java/io/jenkins/plugins/analysis/core/quality/QualityGateTest.java b/src/test/java/io/jenkins/plugins/analysis/core/quality/QualityGateTest.java index 67a138cf..d9d0654e 100644 --- a/src/test/java/io/jenkins/plugins/analysis/core/quality/QualityGateTest.java +++ b/src/test/java/io/jenkins/plugins/analysis/core/quality/QualityGateTest.java @@ -6,16 +6,18 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import edu.hm.hafner.util.SerializableTest; import io.jenkins.plugins.analysis.core.model.AnalysisResult; -import static io.jenkins.plugins.analysis.core.model.Assertions.*; import io.jenkins.plugins.analysis.core.quality.QualityGate.QualityGateBuilder; import io.jenkins.plugins.analysis.core.quality.QualityGate.QualityGateResult; import io.jenkins.plugins.analysis.core.quality.ThresholdSet.ThresholdSetBuilder; + +import static io.jenkins.plugins.analysis.core.model.Assertions.*; import static org.mockito.Mockito.*; import hudson.model.Result; +import edu.hm.hafner.util.SerializableTest; + /** * Tests the class {@link QualityGate QualityGate}. These Tests were created while developing the class QualityGate. * @@ -126,6 +128,7 @@ void shouldBeSuccessWhenNoThresholdIsSetApiDemonstration() { QualityGateResult qualityGateResult = qualityGate.evaluate(run); assertThat(qualityGateResult).hasOverallResult(Result.SUCCESS); + assertThat(qualityGateResult.getEvaluations(mock(AnalysisResult.class), qualityGate)).isEmpty(); } @Test