diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-17 09:57:25 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-17 16:01:23 +0200 |
commit | c3bbc26c6afe29087df952cbd10ad7df8ab99847 (patch) | |
tree | 82b8423af84475ff1fee761e325b6c6c34217fa0 | |
parent | bbc867b6feb420a387ab1423f3befa9934b22934 (diff) | |
download | sonarqube-c3bbc26c6afe29087df952cbd10ad7df8ab99847.tar.gz sonarqube-c3bbc26c6afe29087df952cbd10ad7df8ab99847.zip |
Add Optional<Measure> getNewRawMeasure(int componentRef, String metricKey) in MeasureRepositoryRule
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java index ac3c6f110f9..b1e30387e1b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryRule.java @@ -26,6 +26,7 @@ import com.google.common.collect.SetMultimap; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -133,6 +134,18 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe return getNewRawMeasures(componentProvider.getByRef(componentRef)); } + public Optional<Measure> getNewRawMeasure(int componentRef, String metricKey) { + checkAndInitProvidersState(); + + Set<Measure> measures = getNewRawMeasures(componentProvider.getByRef(componentRef)).get(metricKey); + if (measures.isEmpty()) { + return Optional.absent(); + } else if (measures.size() != 1) { + throw new IllegalArgumentException(String.format("There is more than one measure on metric '%s' for component '%s'", metricKey, componentRef)); + } + return Optional.of(measures.iterator().next()); + } + public SetMultimap<String, Measure> getNewRawMeasures(Component component) { checkAndInitProvidersState(); |