diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2024-10-14 17:49:56 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-15 20:03:06 +0000 |
commit | 551e96829a078a50a9667dce591f977a6525aa88 (patch) | |
tree | c6f8dac73a52e7b97b90c842bde7f5ea743d1915 | |
parent | c6168aa2917eeef83c3383c7eddf35e84394b499 (diff) | |
download | sonarqube-551e96829a078a50a9667dce591f977a6525aa88.tar.gz sonarqube-551e96829a078a50a9667dce591f977a6525aa88.zip |
NO-JIRA Break circular dependency between Metric and Measure
17 files changed, 149 insertions, 132 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java index 30484ebcca7..23792ad9969 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplIT.java @@ -240,7 +240,7 @@ public class MeasureRepositoryImplIT { @UseDataProvider("measures") public void update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE(Measure measure) { for (Metric.MetricType metricType : Metric.MetricType.values()) { - if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == Measure.ValueType.NO_VALUE) { + if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == ValueType.NO_VALUE) { continue; } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImpl.java index 4a760f3bc71..1512c005239 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImpl.java @@ -27,16 +27,16 @@ import org.sonar.api.ce.measure.Measure; import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; import static java.util.Objects.requireNonNull; -import static org.sonar.ce.task.projectanalysis.measure.Measure.ValueType.BOOLEAN; -import static org.sonar.ce.task.projectanalysis.measure.Measure.ValueType.DOUBLE; -import static org.sonar.ce.task.projectanalysis.measure.Measure.ValueType.INT; -import static org.sonar.ce.task.projectanalysis.measure.Measure.ValueType.LONG; -import static org.sonar.ce.task.projectanalysis.measure.Measure.ValueType.STRING; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.BOOLEAN; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.DOUBLE; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.INT; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.LONG; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.STRING; @Immutable public class MeasureImpl implements Measure { - private static final EnumSet<org.sonar.ce.task.projectanalysis.measure.Measure.ValueType> ALLOWED_VALUE_TYPES = EnumSet.of(INT, LONG, DOUBLE, STRING, BOOLEAN); + private static final EnumSet<org.sonar.ce.task.projectanalysis.measure.ValueType> ALLOWED_VALUE_TYPES = EnumSet.of(INT, LONG, DOUBLE, STRING, BOOLEAN); private final org.sonar.ce.task.projectanalysis.measure.Measure measure; @@ -75,7 +75,7 @@ public class MeasureImpl implements Measure { return measure.getBooleanValue(); } - private void checkValueType(org.sonar.ce.task.projectanalysis.measure.Measure.ValueType expected) { + private void checkValueType(org.sonar.ce.task.projectanalysis.measure.ValueType expected) { if (measure.getValueType() != expected) { throw new IllegalStateException(format("Value can not be converted to %s because current value type is a %s", expected.toString().toLowerCase(Locale.US), diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java index 55dde3a31a4..7de048c0471 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java @@ -21,6 +21,7 @@ package org.sonar.ce.task.projectanalysis.formula.coverage; import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext; import org.sonar.ce.task.projectanalysis.measure.Measure; +import org.sonar.ce.task.projectanalysis.measure.ValueType; import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder; @@ -38,10 +39,10 @@ public final class CoverageUtils { static long getLongMeasureValue(CounterInitializationContext counterContext, String metricKey) { Measure measure = counterContext.getMeasure(metricKey).orElse(DEFAULT_MEASURE_LONG); - if (measure.getValueType() == Measure.ValueType.NO_VALUE) { + if (measure.getValueType() == ValueType.NO_VALUE) { return 0L; } - if (measure.getValueType() == Measure.ValueType.INT) { + if (measure.getValueType() == ValueType.INT) { return measure.getIntValue(); } return measure.getLongValue(); @@ -49,7 +50,7 @@ public final class CoverageUtils { static int getIntMeasureValue(CounterInitializationContext counterContext, String metricKey) { Measure measure = counterContext.getMeasure(metricKey).orElse(DEFAULT_MEASURE_INT); - if (measure.getValueType() == Measure.ValueType.NO_VALUE) { + if (measure.getValueType() == ValueType.NO_VALUE) { return 0; } return measure.getIntValue(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java index 1d55b26bb7c..a5652fd77de 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java @@ -25,7 +25,7 @@ import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.metric.Metric; import static java.util.Objects.requireNonNull; -import static org.sonar.ce.task.projectanalysis.measure.Measure.ValueType.NO_VALUE; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.NO_VALUE; public class BestValueOptimization implements Predicate<Measure> { private final Metric metric; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java index bbc5c0643e2..1b414e337c5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java @@ -94,7 +94,7 @@ public final class MapBasedRawMeasureRepository<T> implements MeasureRepository private static void checkValueTypeConsistency(Metric metric, Measure measure) { checkArgument( - measure.getValueType() == Measure.ValueType.NO_VALUE || measure.getValueType() == metric.getType().getValueType(), + measure.getValueType() == ValueType.NO_VALUE || measure.getValueType() == metric.getType().getValueType(), "Measure's ValueType (%s) is not consistent with the Metric's ValueType (%s)", measure.getValueType(), metric.getType().getValueType()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java index ac3b8c090ef..14155830c3a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java @@ -34,13 +34,16 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.toLevel; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.BOOLEAN; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.DOUBLE; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.INT; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.LEVEL; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.LONG; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.NO_VALUE; +import static org.sonar.ce.task.projectanalysis.measure.ValueType.STRING; public interface Measure { - enum ValueType { - NO_VALUE, BOOLEAN, INT, LONG, DOUBLE, STRING, LEVEL - } - enum Level { OK("Passed"), ERROR("Failed"), @@ -80,51 +83,51 @@ public interface Measure { ValueType getValueType(); /** - * The value of this measure as a boolean if the type is {@link Measure.ValueType#BOOLEAN}. + * The value of this measure as a boolean if the type is {@link ValueType#BOOLEAN}. * - * @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#BOOLEAN} + * @throws IllegalStateException if the value type of the measure is not {@link ValueType#BOOLEAN} */ boolean getBooleanValue(); /** - * The value of this measure as a int if the type is {@link Measure.ValueType#INT}. + * The value of this measure as a int if the type is {@link ValueType#INT}. * - * @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#INT} + * @throws IllegalStateException if the value type of the measure is not {@link ValueType#INT} */ int getIntValue(); /** - * The value of this measure as a long if the type is {@link Measure.ValueType#LONG}. + * The value of this measure as a long if the type is {@link ValueType#LONG}. * - * @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#LONG} + * @throws IllegalStateException if the value type of the measure is not {@link ValueType#LONG} */ long getLongValue(); /** - * The value of this measure as a double if the type is {@link Measure.ValueType#DOUBLE}. + * The value of this measure as a double if the type is {@link ValueType#DOUBLE}. * - * @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#DOUBLE} + * @throws IllegalStateException if the value type of the measure is not {@link ValueType#DOUBLE} */ double getDoubleValue(); /** - * The value of this measure as a String if the type is {@link Measure.ValueType#STRING}. + * The value of this measure as a String if the type is {@link ValueType#STRING}. * - * @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#STRING} + * @throws IllegalStateException if the value type of the measure is not {@link ValueType#STRING} */ String getStringValue(); /** - * The value of this measure as a Level if the type is {@link Measure.ValueType#LEVEL}. + * The value of this measure as a Level if the type is {@link ValueType#LEVEL}. * - * @throws IllegalStateException if the value type of the measure is not {@link Measure.ValueType#LEVEL} + * @throws IllegalStateException if the value type of the measure is not {@link ValueType#LEVEL} */ Level getLevelValue(); /** * The data of this measure if it exists. * <p> - * If the measure type is {@link Measure.ValueType#STRING}, the value returned by this function is the same as {@link #getStringValue()}. + * If the measure type is {@link ValueType#STRING}, the value returned by this function is the same as {@link #getStringValue()}. * </p> */ String getData(); @@ -143,7 +146,7 @@ public interface Measure { QualityGateStatus getQualityGateStatus(); default boolean isEmpty() { - return getValueType() == ValueType.NO_VALUE && getData() == null; + return getValueType() == NO_VALUE && getData() == null; } static NewMeasureBuilder newMeasureBuilder() { @@ -180,37 +183,37 @@ public interface Measure { @Override public boolean getBooleanValue() { - checkValueType(ValueType.BOOLEAN, valueType); + checkValueType(BOOLEAN, valueType); return value != null && value.intValue() == 1; } @Override public int getIntValue() { - checkValueType(ValueType.INT, valueType); + checkValueType(INT, valueType); return value.intValue(); } @Override public long getLongValue() { - checkValueType(ValueType.LONG, valueType); + checkValueType(LONG, valueType); return value.longValue(); } @Override public double getDoubleValue() { - checkValueType(ValueType.DOUBLE, valueType); + checkValueType(DOUBLE, valueType); return value; } @Override public String getStringValue() { - checkValueType(ValueType.STRING, valueType); + checkValueType(STRING, valueType); return data; } @Override public Level getLevelValue() { - checkValueType(ValueType.LEVEL, valueType); + checkValueType(LEVEL, valueType); return dataLevel; } @@ -269,25 +272,25 @@ public interface Measure { @Override public boolean getBooleanValue() { - MeasureImpl.checkValueType(ValueType.BOOLEAN, valueType); + MeasureImpl.checkValueType(BOOLEAN, valueType); return value != null && value.intValue() == 1; } @Override public int getIntValue() { - MeasureImpl.checkValueType(ValueType.INT, valueType); + MeasureImpl.checkValueType(INT, valueType); return value.intValue(); } @Override public long getLongValue() { - MeasureImpl.checkValueType(ValueType.LONG, valueType); + MeasureImpl.checkValueType(LONG, valueType); return value.longValue(); } @Override public double getDoubleValue() { - MeasureImpl.checkValueType(ValueType.DOUBLE, valueType); + MeasureImpl.checkValueType(DOUBLE, valueType); return value; } @@ -343,7 +346,7 @@ public interface Measure { class NoValueMeasureImpl implements Measure { @Override public ValueType getValueType() { - return ValueType.NO_VALUE; + return NO_VALUE; } @Override @@ -394,7 +397,7 @@ public interface Measure { @Override public String toString() { return toStringHelper(this) - .add("valueType", ValueType.NO_VALUE) + .add("valueType", NO_VALUE) .toString(); } } @@ -408,7 +411,7 @@ public interface Measure { } public Measure create(boolean value, @Nullable String data) { - return createInternal(ValueType.BOOLEAN, value ? 1.0D : 0.0D, data); + return createInternal(BOOLEAN, value ? 1.0D : 0.0D, data); } public Measure create(boolean value) { @@ -416,7 +419,7 @@ public interface Measure { } public Measure create(int value, @Nullable String data) { - return createInternal(ValueType.INT, value, data); + return createInternal(INT, value, data); } public Measure create(int value) { @@ -424,7 +427,7 @@ public interface Measure { } public Measure create(long value, @Nullable String data) { - return createInternal(ValueType.LONG, value, data); + return createInternal(LONG, value, data); } public Measure create(long value) { @@ -434,7 +437,7 @@ public interface Measure { public Measure create(double value, int decimalScale, @Nullable String data) { checkArgument(!Double.isNaN(value), "NaN is not allowed as a Measure value"); double scaledValue = scale(value, decimalScale); - return createInternal(ValueType.DOUBLE, scaledValue, data); + return createInternal(DOUBLE, scaledValue, data); } private Measure createInternal(ValueType type, double value, @Nullable String data) { @@ -454,11 +457,11 @@ public interface Measure { } public Measure create(String value) { - return new MeasureImpl(ValueType.STRING, null, requireNonNull(value), null, qualityGateStatus); + return new MeasureImpl(STRING, null, requireNonNull(value), null, qualityGateStatus); } public Measure create(Level level) { - return new MeasureImpl(ValueType.LEVEL, null, null, requireNonNull(level), qualityGateStatus); + return new MeasureImpl(LEVEL, null, null, requireNonNull(level), qualityGateStatus); } public Measure create(Metric metric, @Nullable Object value) { @@ -481,7 +484,7 @@ public interface Measure { if (qualityGateStatus == null) { return new NoValueMeasureImpl(); } - return new MeasureImpl(ValueType.NO_VALUE, null, null, null, qualityGateStatus); + return new MeasureImpl(NO_VALUE, null, null, null, qualityGateStatus); } private static double scale(double value, int decimalScale) { @@ -513,26 +516,14 @@ public interface Measure { } public Measure create() { - Double value; - switch (source.getValueType()) { - case DOUBLE: - value = source.getDoubleValue(); - break; - case INT: - value = (double) source.getIntValue(); - break; - case LONG: - value = (double) source.getLongValue(); - break; - case BOOLEAN: - value = source.getBooleanValue() ? 1.0 : 0.0; - break; - case NO_VALUE: - default: - value = null; - break; - } - Level level = source.getValueType() == ValueType.LEVEL ? source.getLevelValue() : null; + Double value = switch (source.getValueType()) { + case DOUBLE -> source.getDoubleValue(); + case INT -> (double) source.getIntValue(); + case LONG -> (double) source.getLongValue(); + case BOOLEAN -> source.getBooleanValue() ? 1.0 : 0.0; + default -> null; + }; + Level level = source.getValueType() == LEVEL ? source.getLevelValue() : null; QualityGateStatus status = source.hasQualityGateStatus() ? source.getQualityGateStatus() : qualityGateStatus; return new MeasureImpl(source.getValueType(), value, source.getData(), level, status); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/ValueType.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/ValueType.java new file mode 100644 index 00000000000..7e21f65a8b5 --- /dev/null +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/ValueType.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.ce.task.projectanalysis.measure; + +public enum ValueType { + NO_VALUE, BOOLEAN, INT, LONG, DOUBLE, STRING, LEVEL +} diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java index 0a3397eb155..8119afee7d1 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java @@ -20,7 +20,7 @@ package org.sonar.ce.task.projectanalysis.metric; import javax.annotation.CheckForNull; -import org.sonar.ce.task.projectanalysis.measure.Measure.ValueType; +import org.sonar.ce.task.projectanalysis.measure.ValueType; public interface Metric { /** diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java index 672e4e513ea..21db980c1f5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java @@ -21,7 +21,7 @@ package org.sonar.ce.task.projectanalysis.metric; import java.util.function.Function; import javax.annotation.Nonnull; -import org.sonar.ce.task.projectanalysis.measure.Measure; +import org.sonar.ce.task.projectanalysis.measure.ValueType; import org.sonar.ce.task.projectanalysis.util.cache.DoubleCache; import org.sonar.db.metric.MetricDto; @@ -37,7 +37,7 @@ public enum MetricDtoToMetric implements Function<MetricDto, Metric> { public Metric apply(@Nonnull MetricDto metricDto) { Metric.MetricType metricType = Metric.MetricType.valueOf(metricDto.getValueType()); Integer decimalScale = null; - if (metricType.getValueType() == Measure.ValueType.DOUBLE) { + if (metricType.getValueType() == ValueType.DOUBLE) { decimalScale = firstNonNull(metricDto.getDecimalScale(), DEFAULT_DECIMAL_SCALE); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java index 89d94bcd37a..e8164b141a3 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java @@ -23,7 +23,7 @@ import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.sonar.ce.task.projectanalysis.measure.Measure; +import org.sonar.ce.task.projectanalysis.measure.ValueType; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.toStringHelper; @@ -54,7 +54,7 @@ public final class MetricImpl implements Metric { this.key = checkNotNull(key); this.name = checkNotNull(name); this.type = checkNotNull(type); - if (type.getValueType() == Measure.ValueType.DOUBLE) { + if (type.getValueType() == ValueType.DOUBLE) { this.decimalScale = firstNonNull(decimalScale, org.sonar.api.measures.Metric.DEFAULT_DECIMAL_SCALE); } else { this.decimalScale = decimalScale; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java index 5429d26887e..1aabeca0ff9 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java @@ -40,6 +40,7 @@ import org.sonar.ce.task.projectanalysis.measure.BestValueOptimization; import org.sonar.ce.task.projectanalysis.measure.Measure; import org.sonar.ce.task.projectanalysis.measure.MeasureRepository; import org.sonar.ce.task.projectanalysis.measure.MeasureToMeasureDto; +import org.sonar.ce.task.projectanalysis.measure.ValueType; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricRepository; import org.sonar.ce.task.step.ComputationStep; @@ -66,7 +67,7 @@ public class PersistMeasuresStep implements ComputationStep { // 50 mb private static final int MAX_TRANSACTION_SIZE = 50_000_000; private static final Predicate<Measure> NON_EMPTY_MEASURE = measure -> - measure.getValueType() != Measure.ValueType.NO_VALUE || measure.getData() != null; + measure.getValueType() != ValueType.NO_VALUE || measure.getData() != null; private final DbClient dbClient; private final MetricRepository metricRepository; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java index e5a460157f3..e975fbffcd5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java @@ -38,6 +38,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.ce.task.projectanalysis.measure.Measure; import org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry; import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule; +import org.sonar.ce.task.projectanalysis.measure.ValueType; import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.core.issue.DefaultIssue; import org.sonar.db.rule.RuleTesting; @@ -536,7 +537,7 @@ class IssueCounterTest { private void assertIntValue(Component componentRef, MapEntry<String, Integer>... entries) { assertThat(measureRepository.getRawMeasures(componentRef).entrySet() .stream() - .filter(e -> e.getValue().getValueType() == Measure.ValueType.INT) + .filter(e -> e.getValue().getValueType() == ValueType.INT) .map(e -> entry(e.getKey(), e.getValue().getIntValue()))) .contains(entries); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java index fa7d18321f4..1e5a181f54d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java @@ -35,7 +35,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.sonar.ce.task.projectanalysis.measure.BatchMeasureToMeasure.*; +import static org.sonar.ce.task.projectanalysis.measure.BatchMeasureToMeasure.toMeasure; @RunWith(DataProviderRunner.class) public class BatchMeasureToMeasureTest { @@ -71,7 +71,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_BATCH_MEASURE, SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -79,7 +79,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue("trololo")).build(), SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -87,7 +87,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue("waRn")).build(), SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -101,7 +101,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue(expectedQualityGateStatus.name())).build(), SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LEVEL); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LEVEL); assertThat(measure.get().getLevelValue()).isEqualTo(expectedQualityGateStatus); } @@ -114,7 +114,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(batchMeasure, SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LEVEL); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LEVEL); assertThat(measure.get().getLevelValue()).isEqualTo(Measure.Level.OK); } @@ -141,7 +141,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_BATCH_MEASURE, SOME_INT_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -153,7 +153,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(batchMeasure, SOME_INT_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.INT); assertThat(measure.get().getIntValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); } @@ -163,7 +163,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_BATCH_MEASURE, SOME_LONG_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -171,7 +171,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(ScannerReport.Measure.newBuilder().setLongValue(LongValue.newBuilder().setValue(15L)).build(), SOME_LONG_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LONG); assertThat(measure.get().getLongValue()).isEqualTo(15); } @@ -184,7 +184,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(batchMeasure, SOME_LONG_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LONG); assertThat(measure.get().getLongValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); } @@ -194,7 +194,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_BATCH_MEASURE, SOME_DOUBLE_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -206,7 +206,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(batchMeasure, SOME_DOUBLE_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.DOUBLE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.DOUBLE); assertThat(measure.get().getDoubleValue()).isEqualTo(10.6395d); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); } @@ -216,7 +216,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_BATCH_MEASURE, SOME_BOOLEAN_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -229,7 +229,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(ScannerReport.Measure.newBuilder().setBooleanValue(BoolValue.newBuilder().setValue(expected)).build(), SOME_BOOLEAN_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isEqualTo(expected); } @@ -241,7 +241,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(batchMeasure, SOME_BOOLEAN_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isTrue(); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); } @@ -251,7 +251,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_BATCH_MEASURE, SOME_STRING_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -263,7 +263,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = toMeasure(batchMeasure, SOME_STRING_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.STRING); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.STRING); assertThat(measure.get().getStringValue()).isEqualTo(SOME_DATA); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java index e8112584986..b695087fb7f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java @@ -167,7 +167,7 @@ public class MapBasedRawMeasureRepositoryTest { @UseDataProvider("measures") public void update_throws_IAE_if_valueType_of_Measure_is_not_the_same_as_the_Metric_valueType_unless_NO_VALUE(Measure measure) { for (Metric.MetricType metricType : Metric.MetricType.values()) { - if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == Measure.ValueType.NO_VALUE) { + if (metricType.getValueType() == measure.getValueType() || measure.getValueType() == ValueType.NO_VALUE) { continue; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java index dab813fe5fc..3c06903da22 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.sonar.ce.task.projectanalysis.measure.Measure.ValueType; import org.sonar.ce.task.projectanalysis.metric.Metric; import org.sonar.ce.task.projectanalysis.metric.MetricImpl; import org.sonar.ce.task.projectanalysis.util.WrapInSingleElementArray; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/ProjectMeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/ProjectMeasureDtoToMeasureTest.java index 44895011e0d..29c03d96e73 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/ProjectMeasureDtoToMeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/ProjectMeasureDtoToMeasureTest.java @@ -32,7 +32,7 @@ import org.sonar.db.measure.ProjectMeasureDto; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.sonar.ce.task.projectanalysis.measure.ProjectMeasureDtoToMeasure.*; +import static org.sonar.ce.task.projectanalysis.measure.ProjectMeasureDtoToMeasure.toMeasure; @RunWith(DataProviderRunner.class) public class ProjectMeasureDtoToMeasureTest { @@ -68,21 +68,21 @@ public class ProjectMeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_data_for_Level_Metric() { Optional<Measure> measure = toMeasure(EMPTY_MEASURE_DTO, SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test public void toMeasure_returns_no_value_if_dto_has_invalid_data_for_Level_Metric() { Optional<Measure> measure = toMeasure(new ProjectMeasureDto().setData("trololo"), SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test public void toMeasure_returns_no_value_if_dta_has_data_in_wrong_case_for_Level_Metric() { Optional<Measure> measure = toMeasure(new ProjectMeasureDto().setData("waRn"), SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -116,7 +116,7 @@ public class ProjectMeasureDtoToMeasureTest { private void verify_toMeasure_returns_value_for_LEVEL_Metric(Level expectedLevel) { Optional<Measure> measure = toMeasure(new ProjectMeasureDto().setData(expectedLevel.name()), SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LEVEL); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LEVEL); assertThat(measure.get().getLevelValue()).isEqualTo(expectedLevel); } @@ -127,7 +127,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(projectMeasureDto, SOME_LEVEL_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LEVEL); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LEVEL); assertThat(measure.get().getLevelValue()).isEqualTo(Level.OK); assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.ERROR); assertThat(measure.get().getQualityGateStatus().getText()).isEqualTo(SOME_ALERT_TEXT); @@ -150,7 +150,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_MEASURE_DTO, SOME_INT_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -158,7 +158,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(new ProjectMeasureDto().setValue(1.5d), SOME_INT_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.INT); assertThat(measure.get().getIntValue()).isOne(); } @@ -169,7 +169,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(projectMeasureDto, SOME_INT_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.INT); assertThat(measure.get().getIntValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK); @@ -181,7 +181,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_MEASURE_DTO, SOME_LONG_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -189,7 +189,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(new ProjectMeasureDto().setValue(1.5d), SOME_LONG_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LONG); assertThat(measure.get().getLongValue()).isOne(); } @@ -200,7 +200,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(projectMeasureDto, SOME_LONG_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.LONG); assertThat(measure.get().getLongValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK); @@ -212,7 +212,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_MEASURE_DTO, SOME_DOUBLE_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -222,7 +222,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(projectMeasureDto, SOME_DOUBLE_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.DOUBLE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.DOUBLE); assertThat(measure.get().getDoubleValue()).isEqualTo(10.6395d); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK); @@ -234,7 +234,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_MEASURE_DTO, SOME_BOOLEAN_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -242,7 +242,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(new ProjectMeasureDto().setValue(1.987d), SOME_BOOLEAN_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isFalse(); } @@ -253,7 +253,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(projectMeasureDto, SOME_BOOLEAN_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isTrue(); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK); @@ -265,7 +265,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(EMPTY_MEASURE_DTO, SOME_STRING_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.NO_VALUE); } @Test @@ -275,7 +275,7 @@ public class ProjectMeasureDtoToMeasureTest { Optional<Measure> measure = toMeasure(projectMeasureDto, SOME_STRING_METRIC); assertThat(measure).isPresent(); - assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.STRING); + assertThat(measure.get().getValueType()).isEqualTo(ValueType.STRING); assertThat(measure.get().getStringValue()).isEqualTo(SOME_DATA); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); assertThat(measure.get().getQualityGateStatus().getStatus()).isEqualTo(Level.OK); diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java index 37b2a2233d6..c56075efb06 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java @@ -44,10 +44,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(int expected) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.INT) { + if (actual.getValueType() != ValueType.INT) { failWithMessage( "Expected Measure to have an int value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.INT, actual.getValueType()); + ValueType.INT, actual.getValueType()); } if (actual.getIntValue() != expected) { @@ -60,10 +60,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(long expected) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.LONG) { + if (actual.getValueType() != ValueType.LONG) { failWithMessage( "Expected Measure to have a long value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.LONG, actual.getValueType()); + ValueType.LONG, actual.getValueType()); } if (actual.getLongValue() != expected) { @@ -76,10 +76,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(double expected) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.DOUBLE) { + if (actual.getValueType() != ValueType.DOUBLE) { failWithMessage( "Expected Measure to have a double value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.DOUBLE, actual.getValueType()); + ValueType.DOUBLE, actual.getValueType()); } if (actual.getDoubleValue() != expected) { @@ -92,10 +92,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(double expected, Offset<Double> offset) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.DOUBLE) { + if (actual.getValueType() != ValueType.DOUBLE) { failWithMessage( "Expected Measure to have a double value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.DOUBLE, actual.getValueType()); + ValueType.DOUBLE, actual.getValueType()); } double value = actual.getDoubleValue(); @@ -111,10 +111,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(boolean expected) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.BOOLEAN) { + if (actual.getValueType() != ValueType.BOOLEAN) { failWithMessage( "Expected Measure to have a boolean value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.DOUBLE, actual.getValueType()); + ValueType.DOUBLE, actual.getValueType()); } if (actual.getBooleanValue() != expected) { @@ -127,10 +127,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(String expected) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.STRING) { + if (actual.getValueType() != ValueType.STRING) { failWithMessage( "Expected Measure to have a String value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.DOUBLE, actual.getValueType()); + ValueType.DOUBLE, actual.getValueType()); } if (!Objects.equals(actual.getStringValue(), expected)) { @@ -143,10 +143,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasValue(Measure.Level expected) { isNotNull(); - if (actual.getValueType() != Measure.ValueType.LEVEL) { + if (actual.getValueType() != ValueType.LEVEL) { failWithMessage( "Expected Measure to have a Level value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.DOUBLE, actual.getValueType()); + ValueType.DOUBLE, actual.getValueType()); } if (actual.getLevelValue() != expected) { @@ -159,10 +159,10 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { public MeasureAssert hasNoValue() { isNotNull(); - if (actual.getValueType() != Measure.ValueType.NO_VALUE) { + if (actual.getValueType() != ValueType.NO_VALUE) { failWithMessage( "Expected Measure to have no value and therefore its ValueType to be <%s> but was <%s>", - Measure.ValueType.DOUBLE, actual.getValueType()); + ValueType.DOUBLE, actual.getValueType()); } return this; |