From 444a92e27170f498b166879725dc762fc078b148 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 8 Feb 2017 08:47:32 +0100 Subject: [PATCH] SONAR-8743 Remove MeasureVariations from XXXVariationValue classes --- .../formula/VariationSumFormula.java | 4 +- .../formula/counter/DoubleValue.java | 58 ++++++++ .../formula/counter/DoubleVariationValue.java | 137 ------------------ .../formula/counter/IntValue.java | 58 ++++++++ .../formula/counter/IntVariationValue.java | 137 ------------------ .../formula/counter/LongValue.java | 58 ++++++++ .../formula/counter/LongVariationValue.java | 137 ------------------ .../formula/counter/RatingValue.java | 61 ++++++++ .../formula/counter/RatingVariationValue.java | 136 ----------------- .../coverage/CoverageVariationFormula.java | 6 +- ...ntsAndCoveredElementsVariationCounter.java | 6 +- .../MaintainabilityMeasuresVisitor.java | 6 +- .../NewMaintainabilityMeasuresVisitor.java | 16 +- ...ilityAndSecurityRatingMeasuresVisitor.java | 8 +- ...ilityAndSecurityRatingMeasuresVisitor.java | 8 +- .../step/NewCoverageMeasuresStep.java | 10 +- .../step/NewSizeMeasuresStep.java | 14 +- ...rtFormulaExecutorComponentVisitorTest.java | 64 ++++---- ...wsFormulaExecutorComponentVisitorTest.java | 62 ++++---- ...ionValueTest.java => DoubleValueTest.java} | 26 ++-- .../DoubleVariationValueArrayTest.java | 120 --------------- ...iationValueTest.java => IntValueTest.java} | 26 ++-- .../counter/IntVariationValueArrayTest.java | 120 --------------- ...ationValueTest.java => LongValueTest.java} | 26 ++-- .../counter/LongVariationValueArrayTest.java | 120 --------------- ...ionValueTest.java => RatingValueTest.java} | 26 ++-- .../RatingVariationValueArrayTest.java | 125 ---------------- 27 files changed, 383 insertions(+), 1192 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java rename server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/{DoubleVariationValueTest.java => DoubleValueTest.java} (68%) delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java rename server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/{IntVariationValueTest.java => IntValueTest.java} (69%) delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java rename server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/{LongVariationValueTest.java => LongValueTest.java} (69%) delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java rename server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/{RatingVariationValueTest.java => RatingValueTest.java} (71%) delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java index 77d1730e26b..b4186bf6f6c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java @@ -23,7 +23,7 @@ import com.google.common.base.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit; -import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import static java.util.Objects.requireNonNull; @@ -68,7 +68,7 @@ public class VariationSumFormula implements Formula { @CheckForNull private final Double defaultInputValue; - private final DoubleVariationValue doubleValue = new DoubleVariationValue(); + private final DoubleValue doubleValue = new DoubleValue(); private final String metricKey; private VariationSumCounter(String metricKey, @Nullable Double defaultInputValue) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java new file mode 100644 index 00000000000..adae6c5c915 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; + +import javax.annotation.Nullable; + +/** + * Convenience class wrapping a double to compute the value and know it is has ever been set. + */ +public class DoubleValue { + private boolean set = false; + private double value = 0L; + + /** + * @return the current {@link DoubleValue} so that chained calls on a specific {@link DoubleValue} instance can be done + */ + public DoubleValue increment(double increment) { + this.value += increment; + this.set = true; + return this; + } + + /** + * @return the current {@link DoubleValue} so that chained calls on a specific {@link DoubleValue} instance can be done + */ + public DoubleValue increment(@Nullable DoubleValue value) { + if (value != null && value.isSet()) { + increment(value.value); + } + return this; + } + + public boolean isSet() { + return set; + } + + public double getValue() { + return value; + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java deleted file mode 100644 index ad8f07dd078..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.base.Optional; -import javax.annotation.Nullable; -import org.sonar.server.computation.task.projectanalysis.formula.Counter; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS; - -/** - * Convenience class wrapping a double to compute the value of a MeasureVariation as an double and know it is has ever - * been set. - *

- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily - * creating using method {@link #newArray()}. - *

- */ -public class DoubleVariationValue { - private boolean set = false; - private double value = 0L; - - /** - * @return the current DoubleVariationValue so that chained calls on a specific DoubleVariationValue instance can be done - */ - public DoubleVariationValue increment(double increment) { - this.value += increment; - this.set = true; - return this; - } - - /** - * @return the current DoubleVariationValue so that chained calls on a specific DoubleVariationValue instance can be done - */ - public DoubleVariationValue increment(@Nullable DoubleVariationValue value) { - if (value != null && value.isSet()) { - increment(value.value); - } - return this; - } - - public boolean isSet() { - return set; - } - - public double getValue() { - return value; - } - - /** - * Creates a new Array of {@link DoubleVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS}, - * initialized with newly creates {@link DoubleVariationValue} instances. - */ - public static Array newArray() { - return new Array(); - } - - public static class Array { - private final DoubleVariationValue[] values; - - public Array() { - this.values = new DoubleVariationValue[MAX_NUMBER_OF_PERIODS]; - for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) { - this.values[i] = new DoubleVariationValue(); - } - } - - public DoubleVariationValue get(Period period) { - return values[period.getIndex() - 1]; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array increment(Period period, double value) { - this.values[period.getIndex() - 1].increment(value); - return this; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array incrementAll(Array source) { - for (int i = 0; i < this.values.length; i++) { - if (source.values[i].isSet()) { - this.values[i].increment(source.values[i]); - } - } - return this; - } - - /** - * Creates a new MeasureVariations from the current array. - */ - public Optional toMeasureVariations() { - if (!isAnySet()) { - return Optional.absent(); - } - Double[] variations = new Double[values.length]; - for (int i = 0; i < values.length; i++) { - if (values[i].isSet()) { - variations[i] = values[i].getValue(); - } - } - return Optional.of(new MeasureVariations(variations)); - } - - private boolean isAnySet() { - for (DoubleVariationValue variationValue : values) { - if (variationValue.isSet()) { - return true; - } - } - return false; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java new file mode 100644 index 00000000000..8ba101cb0e7 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; + +import javax.annotation.Nullable; + +/** + * Convenience class wrapping an int to compute the value and know it is has ever been set. + */ +public class IntValue { + private boolean set = false; + private int value = 0; + + /** + * @return the current {@link IntValue} so that chained calls on a specific {@link IntValue} instance can be done + */ + public IntValue increment(int increment) { + this.value += increment; + this.set = true; + return this; + } + + /** + * @return the current {@link IntValue} so that chained calls on a specific {@link IntValue} instance can be done + */ + public IntValue increment(@Nullable IntValue value) { + if (value != null && value.isSet()) { + increment(value.value); + } + return this; + } + + public boolean isSet() { + return set; + } + + public int getValue() { + return value; + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java deleted file mode 100644 index 4c1f92c6701..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.base.Optional; -import javax.annotation.Nullable; -import org.sonar.server.computation.task.projectanalysis.formula.Counter; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS; - -/** - * Convenience class wrapping a int to compute the value of a MeasureVariation as an int and know it is has ever been - * set. - *

- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily - * creating using method {@link #newArray()}. - *

- */ -public class IntVariationValue { - private boolean set = false; - private int value = 0; - - /** - * @return the current IntVariationValue so that chained calls on a specific IntVariationValue instance can be done - */ - public IntVariationValue increment(int increment) { - this.value += increment; - this.set = true; - return this; - } - - /** - * @return the current IntVariationValue so that chained calls on a specific IntVariationValue instance can be done - */ - public IntVariationValue increment(@Nullable IntVariationValue value) { - if (value != null && value.isSet()) { - increment(value.value); - } - return this; - } - - public boolean isSet() { - return set; - } - - public int getValue() { - return value; - } - - /** - * Creates a new Array of {@link IntVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS}, - * initialized with newly creates {@link IntVariationValue} instances. - */ - public static Array newArray() { - return new Array(); - } - - public static class Array { - private final IntVariationValue[] values; - - public Array() { - this.values = new IntVariationValue[MAX_NUMBER_OF_PERIODS]; - for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) { - this.values[i] = new IntVariationValue(); - } - } - - public IntVariationValue get(Period period) { - return values[period.getIndex() - 1]; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array increment(Period period, int value) { - this.values[period.getIndex() - 1].increment(value); - return this; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array incrementAll(Array source) { - for (int i = 0; i < this.values.length; i++) { - if (source.values[i].isSet()) { - this.values[i].increment(source.values[i]); - } - } - return this; - } - - /** - * Creates a new MeasureVariations from the current array. - */ - public Optional toMeasureVariations() { - if (!isAnySet()) { - return Optional.absent(); - } - Double[] variations = new Double[values.length]; - for (int i = 0; i < values.length; i++) { - if (values[i].isSet()) { - variations[i] = (double) values[i].getValue(); - } - } - return Optional.of(new MeasureVariations(variations)); - } - - private boolean isAnySet() { - for (IntVariationValue variationValue : values) { - if (variationValue.isSet()) { - return true; - } - } - return false; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java new file mode 100644 index 00000000000..8cdd0d20ced --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; + +import javax.annotation.Nullable; + +/** + * Convenience class wrapping a long to compute the value and know it is has ever been set. + */ +public class LongValue { + private boolean set = false; + private long value = 0L; + + /** + * @return the current {@link LongValue} so that chained calls on a specific {@link LongValue} instance can be done + */ + public LongValue increment(long increment) { + this.value += increment; + this.set = true; + return this; + } + + /** + * @return the current {@link LongValue} so that chained calls on a specific {@link LongValue} instance can be done + */ + public LongValue increment(@Nullable LongValue value) { + if (value != null && value.isSet()) { + increment(value.value); + } + return this; + } + + public boolean isSet() { + return set; + } + + public long getValue() { + return value; + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java deleted file mode 100644 index a53f1e37d0c..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.base.Optional; -import javax.annotation.Nullable; -import org.sonar.server.computation.task.projectanalysis.formula.Counter; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS; - -/** - * Convenience class wrapping a long to compute the value of a MeasureVariation as an long and know it is has ever been - * set. - *

- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily - * creating using method {@link #newArray()}. - *

- */ -public class LongVariationValue { - private boolean set = false; - private long value = 0L; - - /** - * @return the current LongVariationValue so that chained calls on a specific LongVariationValue instance can be done - */ - public LongVariationValue increment(long increment) { - this.value += increment; - this.set = true; - return this; - } - - /** - * @return the current LongVariationValue so that chained calls on a specific LongVariationValue instance can be done - */ - public LongVariationValue increment(@Nullable LongVariationValue value) { - if (value != null && value.isSet()) { - increment(value.value); - } - return this; - } - - public boolean isSet() { - return set; - } - - public long getValue() { - return value; - } - - /** - * Creates a new Array of {@link LongVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS}, - * initialized with newly creates {@link LongVariationValue} instances. - */ - public static Array newArray() { - return new Array(); - } - - public static class Array { - private final LongVariationValue[] values; - - public Array() { - this.values = new LongVariationValue[MAX_NUMBER_OF_PERIODS]; - for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) { - this.values[i] = new LongVariationValue(); - } - } - - public LongVariationValue get(Period period) { - return values[period.getIndex() - 1]; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array increment(Period period, long value) { - this.values[period.getIndex() - 1].increment(value); - return this; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array incrementAll(Array source) { - for (int i = 0; i < this.values.length; i++) { - if (source.values[i].isSet()) { - this.values[i].increment(source.values[i]); - } - } - return this; - } - - /** - * Creates a new MeasureVariations from the current array. - */ - public Optional toMeasureVariations() { - if (!isAnySet()) { - return Optional.absent(); - } - Double[] variations = new Double[values.length]; - for (int i = 0; i < values.length; i++) { - if (values[i].isSet()) { - variations[i] = (double) values[i].getValue(); - } - } - return Optional.of(new MeasureVariations(variations)); - } - - private boolean isAnySet() { - for (LongVariationValue variationValue : values) { - if (variationValue.isSet()) { - return true; - } - } - return false; - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java new file mode 100644 index 00000000000..bcafa642299 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; + +import javax.annotation.Nullable; +import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating; + +/** + * Convenience class wrapping a rating to compute the value and know it is has ever been set. + */ +public class RatingValue { + private boolean set = false; + private Rating value = Rating.A; + + /** + * @return the current {@link RatingValue} so that chained calls on a specific {@link RatingValue} instance can be done + */ + public RatingValue increment(Rating rating) { + if (value.compareTo(rating) > 0) { + value = rating; + } + this.set = true; + return this; + } + + /** + * @return the current {@link RatingValue} so that chained calls on a specific {@link RatingValue} instance can be done + */ + public RatingValue increment(@Nullable RatingValue value) { + if (value != null && value.isSet()) { + increment(value.value); + } + return this; + } + + public boolean isSet() { + return set; + } + + public Rating getValue() { + return value; + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java deleted file mode 100644 index 3535f8e277d..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import java.util.Arrays; -import java.util.Optional; -import javax.annotation.Nullable; -import org.sonar.server.computation.task.projectanalysis.formula.Counter; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; -import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating; - -import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS; - -/** - * Convenience class wrapping a rating. - * It also allows to compute the value of a MeasureVariation as a rating, and add a check to know if it is has ever been set. - *

- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily - * created using method {@link #newArray()}. - *

- */ -public class RatingVariationValue { - private boolean set = false; - private Rating value = Rating.A; - - /** - * @return the current RatingVariationValue so that chained calls on a specific RatingVariationValue instance can be done - */ - public RatingVariationValue increment(Rating rating) { - if (value.compareTo(rating) > 0) { - value = rating; - } - this.set = true; - return this; - } - - /** - * @return the current RatingVariationValue so that chained calls on a specific RatingVariationValue instance can be done - */ - public RatingVariationValue increment(@Nullable RatingVariationValue value) { - if (value != null && value.isSet()) { - increment(value.value); - } - return this; - } - - public boolean isSet() { - return set; - } - - public Rating getValue() { - return value; - } - - /** - * Creates a new Array of {@link RatingVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS}, - * initialized with newly creates {@link RatingVariationValue} instances. - */ - public static Array newArray() { - return new Array(); - } - - public static class Array { - private final RatingVariationValue[] values; - - public Array() { - this.values = new RatingVariationValue[MAX_NUMBER_OF_PERIODS]; - for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) { - this.values[i] = new RatingVariationValue(); - } - } - - public RatingVariationValue get(Period period) { - return values[period.getIndex() - 1]; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array increment(Period period, Rating value) { - this.values[period.getIndex() - 1].increment(value); - return this; - } - - /** - * @return the current Array, so that chained calls on a specific Array instance can be done - */ - public Array incrementAll(Array source) { - for (int i = 0; i < this.values.length; i++) { - if (source.values[i].isSet()) { - this.values[i].increment(source.values[i]); - } - } - return this; - } - - /** - * Creates a new MeasureVariations from the current array. - */ - public Optional toMeasureVariations() { - if (!isAnySet()) { - return Optional.empty(); - } - Double[] variations = new Double[values.length]; - for (int i = 0; i < values.length; i++) { - if (values[i].isSet()) { - variations[i] = (double) values[i].getValue().getIndex(); - } - } - return Optional.of(new MeasureVariations(variations)); - } - - private boolean isAnySet() { - return Arrays.stream(values).anyMatch(RatingVariationValue::isSet); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageVariationFormula.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageVariationFormula.java index b5b717c41ff..44f8c3dbc27 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageVariationFormula.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageVariationFormula.java @@ -22,7 +22,7 @@ package org.sonar.server.computation.task.projectanalysis.formula.coverage; import com.google.common.base.Optional; import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext; import org.sonar.server.computation.task.projectanalysis.formula.Formula; -import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.LongValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.calculateCoverage; @@ -36,9 +36,9 @@ public abstract class CoverageVariationFormula createMeasure(T counter, CreateMeasureContext context) { - LongVariationValue elements = counter.elements; + LongValue elements = counter.elements; if (elements.isSet() && elements.getValue() > 0d) { - LongVariationValue coveredElements = counter.coveredElements; + LongValue coveredElements = counter.coveredElements; double variation = calculateCoverage(coveredElements.getValue(), elements.getValue()); return Optional.of(newMeasureBuilder().setVariation(variation).createNoValue()); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java index 5c41fa06079..b833c1ed0ef 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java @@ -22,14 +22,14 @@ package org.sonar.server.computation.task.projectanalysis.formula.coverage; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.formula.Counter; import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext; -import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.LongValue; /** * A counter used to create measure variations which are based on a count of elements and coveredElements. */ public abstract class ElementsAndCoveredElementsVariationCounter implements Counter { - protected final LongVariationValue elements = new LongVariationValue(); - protected final LongVariationValue coveredElements = new LongVariationValue(); + protected final LongValue elements = new LongValue(); + protected final LongValue coveredElements = new LongValue(); @Override public void aggregate(ElementsAndCoveredElementsVariationCounter counter) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java index 80a340eb1d3..b6046375fe2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java @@ -24,7 +24,7 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit; import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisitorAdapter; -import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository; import org.sonar.server.computation.task.projectanalysis.metric.Metric; @@ -155,8 +155,8 @@ public class MaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter
newRatingValueByMetric = ImmutableMap.of( - NEW_RELIABILITY_RATING_KEY, new RatingVariationValue(), - NEW_SECURITY_RATING_KEY, new RatingVariationValue()); + private Map newRatingValueByMetric = ImmutableMap.of( + NEW_RELIABILITY_RATING_KEY, new RatingValue(), + NEW_SECURITY_RATING_KEY, new RatingValue()); private Counter() { // prevents instantiation diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitor.java index 6fd0994cb07..f3adfbc6ea9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitor.java @@ -26,7 +26,7 @@ import org.sonar.api.ce.measure.Issue; import org.sonar.api.measures.CoreMetrics; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisitorAdapter; -import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingValue; import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepository; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository; @@ -135,9 +135,9 @@ public class ReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVisito } static final class Counter { - private Map ratingValueByMetric = ImmutableMap.of( - RELIABILITY_RATING_KEY, new RatingVariationValue(), - SECURITY_RATING_KEY, new RatingVariationValue()); + private Map ratingValueByMetric = ImmutableMap.of( + RELIABILITY_RATING_KEY, new RatingValue(), + SECURITY_RATING_KEY, new RatingValue()); private Counter() { // prevents instantiation diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java index b2ca9560fc6..94eb9493bbb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java @@ -40,7 +40,7 @@ import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureCo import org.sonar.server.computation.task.projectanalysis.formula.Formula; import org.sonar.server.computation.task.projectanalysis.formula.FormulaExecutorComponentVisitor; import org.sonar.server.computation.task.projectanalysis.formula.VariationSumFormula; -import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue; import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys; import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredVariationFormula; import org.sonar.server.computation.task.projectanalysis.formula.coverage.SingleWithUncoveredMetricKeys; @@ -227,10 +227,10 @@ public class NewCoverageMeasuresStep implements ComputationStep { } public static final class NewCoverageCounter implements org.sonar.server.computation.task.projectanalysis.formula.Counter { - private final IntVariationValue newLines = new IntVariationValue(); - private final IntVariationValue newCoveredLines = new IntVariationValue(); - private final IntVariationValue newConditions = new IntVariationValue(); - private final IntVariationValue newCoveredConditions = new IntVariationValue(); + private final IntValue newLines = new IntValue(); + private final IntValue newCoveredLines = new IntValue(); + private final IntValue newConditions = new IntValue(); + private final IntValue newCoveredConditions = new IntValue(); private final ScmInfoRepository scmInfoRepository; private final NewCoverageInputMetricKeys metricKeys; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java index 5728fd552c3..d54ae239dfa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java @@ -39,7 +39,7 @@ import org.sonar.server.computation.task.projectanalysis.formula.CounterInitiali import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext; import org.sonar.server.computation.task.projectanalysis.formula.Formula; import org.sonar.server.computation.task.projectanalysis.formula.FormulaExecutorComponentVisitor; -import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository; @@ -92,9 +92,9 @@ public class NewSizeMeasuresStep implements ComputationStep { private static class NewSizeCounter implements Counter { private final DuplicationRepository duplicationRepository; private final ScmInfoRepository scmInfoRepository; - private final IntVariationValue newLines = new IntVariationValue(); - private final IntVariationValue newDuplicatedLines = new IntVariationValue(); - private final IntVariationValue newDuplicatedBlocks = new IntVariationValue(); + private final IntValue newLines = new IntValue(); + private final IntValue newDuplicatedLines = new IntValue(); + private final IntValue newDuplicatedBlocks = new IntValue(); private NewSizeCounter(DuplicationRepository duplicationRepository, ScmInfoRepository scmInfoRepository) { @@ -224,15 +224,15 @@ public class NewSizeMeasuresStep implements ComputationStep { } } - private static Optional createMeasure(IntVariationValue intValue) { + private static Optional createMeasure(IntValue intValue) { return intValue.isSet() ? Optional.of(Measure.newMeasureBuilder().setVariation(intValue.getValue()).createNoValue()) : Optional.absent(); } private static Optional createNewDuplicatedLinesDensityMeasure(NewSizeCounter counter) { - IntVariationValue newLines = counter.newLines; - IntVariationValue newDuplicatedLines = counter.newDuplicatedLines; + IntValue newLines = counter.newLines; + IntValue newDuplicatedLines = counter.newDuplicatedLines; if (newLines.isSet() && newDuplicatedLines.isSet()) { int newLinesVariations = newLines.getValue(); int newDuplicatedLinesVariations = newDuplicatedLines.getValue(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java index 8cccff51454..3437d47c9bd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java @@ -28,10 +28,9 @@ import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler; import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; -import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; import org.sonar.server.computation.task.projectanalysis.metric.Metric; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.server.computation.task.projectanalysis.period.Period; @@ -90,8 +89,7 @@ public class ReportFormulaExecutorComponentVisitorTest { @Rule public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); @Rule - public PeriodsHolderRule periodsHolder = new PeriodsHolderRule() - .setPeriods(new Period(2, "some mode", null, 95l, "756l"), new Period(5, "some other mode", null, 756L, "956L")); + public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriod(new Period("some mode", null, 95l, "756l")); @Test public void verify_aggregation_on_value() throws Exception { @@ -152,24 +150,24 @@ public class ReportFormulaExecutorComponentVisitorTest { } @Test - public void verify_aggregation_on_variations() throws Exception { + public void verify_aggregation_on_variation() throws Exception { treeRootHolder.setRoot(BALANCED_COMPONENT_TREE); - measureRepository.addRawMeasure(FILE_1_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(10, 20)); - measureRepository.addRawMeasure(FILE_2_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(8, 16)); - measureRepository.addRawMeasure(FILE_3_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(2, 4)); + measureRepository.addRawMeasure(FILE_1_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(10)); + measureRepository.addRawMeasure(FILE_2_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(8)); + measureRepository.addRawMeasure(FILE_3_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(2)); new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeVariationFormula())) .visit(BALANCED_COMPONENT_TREE); - assertAddedRawMeasure(ROOT_REF, 20, 40); - assertAddedRawMeasure(MODULE_1_REF, 18, 36); - assertAddedRawMeasure(DIRECTORY_1_REF, 18, 36); - assertAddedRawMeasure(FILE_1_REF, 10, 20); - assertAddedRawMeasure(FILE_2_REF, 8, 16); - assertAddedRawMeasure(MODULE_2_REF, 2, 4); - assertAddedRawMeasure(DIRECTORY_2_REF, 2, 4); - assertAddedRawMeasure(FILE_3_REF, 2, 4); + assertAddedRawMeasureVariation(ROOT_REF, 20); + assertAddedRawMeasureVariation(MODULE_1_REF, 18); + assertAddedRawMeasureVariation(DIRECTORY_1_REF, 18); + assertAddedRawMeasureVariation(FILE_1_REF, 10); + assertAddedRawMeasureVariation(FILE_2_REF, 8); + assertAddedRawMeasureVariation(MODULE_2_REF, 2); + assertAddedRawMeasureVariation(DIRECTORY_2_REF, 2); + assertAddedRawMeasureVariation(FILE_3_REF, 2); } @Test @@ -219,17 +217,17 @@ public class ReportFormulaExecutorComponentVisitorTest { .buildFor(ImmutableList.of(formula)); } - private static Measure createMeasureWithVariation(double variation2Value, double variation5Value) { - return newMeasureBuilder().setVariations(new MeasureVariations(null, variation2Value, null, null, variation5Value)).createNoValue(); + private static Measure createMeasureWithVariation(double variation) { + return newMeasureBuilder().setVariation(variation).createNoValue(); } private void assertAddedRawMeasure(int componentRef, int expectedValue) { assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).containsOnly(entryOf(NCLOC_KEY, newMeasureBuilder().create(expectedValue))); } - private void assertAddedRawMeasure(int componentRef, int variation2Value, int variation5Value) { + private void assertAddedRawMeasureVariation(int componentRef, int variation) { assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))) - .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation2Value, variation5Value))); + .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation))); } private class FakeFormula implements Formula { @@ -265,7 +263,7 @@ public class ReportFormulaExecutorComponentVisitorTest { @Override public Optional createMeasure(FakeCounter counter, CreateMeasureContext context) { // verify the context which is passed to the method - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); assertThat(context.getComponent()).isNotNull(); assertThat(context.getMetric()) .isIn(metricRepository.getByKey(NEW_LINES_TO_COVER_KEY), metricRepository.getByKey(NEW_COVERAGE_KEY)); @@ -301,7 +299,7 @@ public class ReportFormulaExecutorComponentVisitorTest { public void initialize(CounterInitializationContext context) { // verify the context which is passed to the method assertThat(context.getLeaf().getChildren()).isEmpty(); - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); Optional measureOptional = context.getMeasure(LINES_KEY); if (measureOptional.isPresent()) { @@ -320,15 +318,15 @@ public class ReportFormulaExecutorComponentVisitorTest { @Override public Optional createMeasure(FakeVariationCounter counter, CreateMeasureContext context) { // verify the context which is passed to the method - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); assertThat(context.getComponent()).isNotNull(); assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NEW_COVERAGE_KEY)); - Optional measureVariations = counter.values.toMeasureVariations(); - if (measureVariations.isPresent()) { + IntValue measureVariations = counter.values; + if (measureVariations.isSet()) { return Optional.of( newMeasureBuilder() - .setVariations(measureVariations.get()) + .setVariation(measureVariations.getValue()) .createNoValue()); } return Optional.absent(); @@ -341,28 +339,24 @@ public class ReportFormulaExecutorComponentVisitorTest { } private class FakeVariationCounter implements Counter { - private final IntVariationValue.Array values = IntVariationValue.newArray(); + private final IntValue values = new IntValue(); @Override public void aggregate(FakeVariationCounter counter) { - values.incrementAll(counter.values); + values.increment(counter.values); } @Override public void initialize(CounterInitializationContext context) { // verify the context which is passed to the method assertThat(context.getLeaf().getChildren()).isEmpty(); - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); Optional measureOptional = context.getMeasure(NEW_LINES_TO_COVER_KEY); - if (!measureOptional.isPresent()) { + if (!measureOptional.isPresent() || !context.hasPeriod()) { return; } - for (Period period : context.getPeriods()) { - this.values.increment( - period, - (int) measureOptional.get().getVariations().getVariation(period.getIndex())); - } + this.values.increment((int) measureOptional.get().getVariation()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java index 0bb77e1239a..3adeb437b3d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java @@ -28,11 +28,10 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler; import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent; -import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue; +import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; import org.sonar.server.computation.task.projectanalysis.metric.Metric; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.server.computation.task.projectanalysis.period.Period; @@ -90,8 +89,7 @@ public class ViewsFormulaExecutorComponentVisitorTest { @Rule public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); @Rule - public PeriodsHolderRule periodsHolder = new PeriodsHolderRule() - .setPeriods(new Period(2, "some mode", null, 95l, "u1"), new Period(5, "some other mode", null, 756L, "u2")); + public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriod(new Period("some mode", null, 95l, "u1")); @Test public void verify_aggregation_on_value() throws Exception { @@ -137,33 +135,32 @@ public class ViewsFormulaExecutorComponentVisitorTest { public void verify_aggregation_on_variations() throws Exception { treeRootHolder.setRoot(BALANCED_COMPONENT_TREE); - addRawMeasureWithVariation(PROJECT_VIEW_1_REF, NEW_LINES_TO_COVER_KEY, 10, 20); - addRawMeasureWithVariation(PROJECT_VIEW_2_REF, NEW_LINES_TO_COVER_KEY, 8, 16); - addRawMeasureWithVariation(PROJECT_VIEW_3_REF, NEW_LINES_TO_COVER_KEY, 2, 4); - addRawMeasureWithVariation(PROJECT_VIEW_4_REF, NEW_LINES_TO_COVER_KEY, 3, 7); + addRawMeasureWithVariation(PROJECT_VIEW_1_REF, NEW_LINES_TO_COVER_KEY, 10); + addRawMeasureWithVariation(PROJECT_VIEW_2_REF, NEW_LINES_TO_COVER_KEY, 8); + addRawMeasureWithVariation(PROJECT_VIEW_3_REF, NEW_LINES_TO_COVER_KEY, 2); + addRawMeasureWithVariation(PROJECT_VIEW_4_REF, NEW_LINES_TO_COVER_KEY, 3); new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeVariationFormula())) .visit(BALANCED_COMPONENT_TREE); verifyProjectViewsHasNoAddedRawMeasures(); - verifySingleMetricWithVariations(SUB_SUBVIEW_REF, 18, 36); - verifySingleMetricWithVariations(SUBVIEW_1_REF, 18, 36); - verifySingleMetricWithVariations(SUBVIEW_2_REF, 2, 4); - verifySingleMetricWithVariations(ROOT_REF, 23, 47); + verifySingleMetricWithVariation(SUB_SUBVIEW_REF, 18); + verifySingleMetricWithVariation(SUBVIEW_1_REF, 18); + verifySingleMetricWithVariation(SUBVIEW_2_REF, 2); + verifySingleMetricWithVariation(ROOT_REF, 23); } - private AbstractIterableAssert, MeasureRepoEntry> verifySingleMetricWithVariations(int componentRef, int variation2Value, - int variation5Value) { + private AbstractIterableAssert, MeasureRepoEntry> verifySingleMetricWithVariation(int componentRef, int variation) { return assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))) - .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation2Value, variation5Value))); + .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation))); } - private MeasureRepositoryRule addRawMeasureWithVariation(int componentRef, String metricKey, int variation2Value, int variation5Value) { - return measureRepository.addRawMeasure(componentRef, metricKey, createMeasureWithVariation(variation2Value, variation5Value)); + private MeasureRepositoryRule addRawMeasureWithVariation(int componentRef, String metricKey, int variation) { + return measureRepository.addRawMeasure(componentRef, metricKey, createMeasureWithVariation(variation)); } - private static Measure createMeasureWithVariation(double variation2Value, double variation5Value) { - return newMeasureBuilder().setVariations(new MeasureVariations(null, variation2Value, null, null, variation5Value)).createNoValue(); + private static Measure createMeasureWithVariation(double variation) { + return newMeasureBuilder().setVariation(variation).createNoValue(); } @Test @@ -218,7 +215,7 @@ public class ViewsFormulaExecutorComponentVisitorTest { @Override public Optional createMeasure(FakeCounter counter, CreateMeasureContext context) { // verify the context which is passed to the method - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); assertThat(context.getComponent()).isNotNull(); assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NCLOC_KEY)); @@ -241,7 +238,7 @@ public class ViewsFormulaExecutorComponentVisitorTest { @Override public Optional createMeasure(FakeCounter counter, CreateMeasureContext context) { // verify the context which is passed to the method - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); assertThat(context.getComponent()).isNotNull(); assertThat(context.getMetric()) .isIn(metricRepository.getByKey(NEW_LINES_TO_COVER_KEY), metricRepository.getByKey(NEW_COVERAGE_KEY)); @@ -294,15 +291,15 @@ public class ViewsFormulaExecutorComponentVisitorTest { @Override public Optional createMeasure(FakeVariationCounter counter, CreateMeasureContext context) { // verify the context which is passed to the method - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); assertThat(context.getComponent()).isNotNull(); assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NEW_COVERAGE_KEY)); - Optional measureVariations = counter.values.toMeasureVariations(); - if (measureVariations.isPresent()) { + IntValue measureVariations = counter.values; + if (measureVariations.isSet()) { return Optional.of( newMeasureBuilder() - .setVariations(measureVariations.get()) + .setVariation(measureVariations.getValue()) .createNoValue()); } return Optional.absent(); @@ -315,11 +312,11 @@ public class ViewsFormulaExecutorComponentVisitorTest { } private class FakeVariationCounter implements Counter { - private final IntVariationValue.Array values = IntVariationValue.newArray(); + private final IntValue values = new IntValue(); @Override public void aggregate(FakeVariationCounter counter) { - values.incrementAll(counter.values); + values.increment(counter.values); } @Override @@ -327,15 +324,12 @@ public class ViewsFormulaExecutorComponentVisitorTest { verifyLeafContext(context); Optional measureOptional = context.getMeasure(NEW_LINES_TO_COVER_KEY); - if (!measureOptional.isPresent()) { + if (!measureOptional.isPresent() || !context.hasPeriod()) { return; } - for (Period period : context.getPeriods()) { - this.values.increment( - period, - (int) measureOptional.get().getVariations().getVariation(period.getIndex())); - } + this.values.increment((int) measureOptional.get().getVariation()); } + } private FormulaExecutorComponentVisitor formulaExecutorComponentVisitor(Formula formula) { @@ -369,7 +363,7 @@ public class ViewsFormulaExecutorComponentVisitorTest { private void verifyLeafContext(CounterInitializationContext context) { assertThat(context.getLeaf().getChildren()).isEmpty(); - assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods()); + assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValueTest.java similarity index 68% rename from server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueTest.java rename to server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValueTest.java index 8964971802e..3149c4ba962 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValueTest.java @@ -23,59 +23,59 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -public class DoubleVariationValueTest { +public class DoubleValueTest { @Test public void newly_created_DoubleVariationValue_is_unset_and_has_value_0() { - verifyUnsetVariationValue(new DoubleVariationValue()); + verifyUnsetVariationValue(new DoubleValue()); } @Test public void increment_double_sets_DoubleVariationValue_and_increments_value() { - verifySetVariationValue(new DoubleVariationValue().increment(10.6), 10.6); + verifySetVariationValue(new DoubleValue().increment(10.6), 10.6); } @Test public void increment_DoubleVariationValue_has_no_effect_if_arg_is_null() { - verifyUnsetVariationValue(new DoubleVariationValue().increment(null)); + verifyUnsetVariationValue(new DoubleValue().increment(null)); } @Test public void increment_DoubleVariationValue_has_no_effect_if_arg_is_unset() { - verifyUnsetVariationValue(new DoubleVariationValue().increment(new DoubleVariationValue())); + verifyUnsetVariationValue(new DoubleValue().increment(new DoubleValue())); } @Test public void increment_DoubleVariationValue_increments_by_the_value_of_the_arg() { - DoubleVariationValue source = new DoubleVariationValue().increment(10); - DoubleVariationValue target = new DoubleVariationValue().increment(source); + DoubleValue source = new DoubleValue().increment(10); + DoubleValue target = new DoubleValue().increment(source); verifySetVariationValue(target, 10); } @Test public void multiple_calls_to_increment_DoubleVariationValue_increments_by_the_value_of_the_arg() { - DoubleVariationValue target = new DoubleVariationValue() - .increment(new DoubleVariationValue().increment(35)) - .increment(new DoubleVariationValue().increment(10)); + DoubleValue target = new DoubleValue() + .increment(new DoubleValue().increment(35)) + .increment(new DoubleValue().increment(10)); verifySetVariationValue(target, 45); } @Test public void multiples_calls_to_increment_double_increment_the_value() { - DoubleVariationValue variationValue = new DoubleVariationValue() + DoubleValue variationValue = new DoubleValue() .increment(10.6) .increment(95.4); verifySetVariationValue(variationValue, 106); } - private static void verifyUnsetVariationValue(DoubleVariationValue variationValue) { + private static void verifyUnsetVariationValue(DoubleValue variationValue) { assertThat(variationValue.isSet()).isFalse(); assertThat(variationValue.getValue()).isEqualTo(0); } - private static void verifySetVariationValue(DoubleVariationValue variationValue, double expected) { + private static void verifySetVariationValue(DoubleValue variationValue, double expected) { assertThat(variationValue.isSet()).isTrue(); assertThat(variationValue.getValue()).isEqualTo(expected); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java deleted file mode 100644 index 1949be16d11..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.junit.Test; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.guava.api.Assertions.assertThat; - -public class DoubleVariationValueArrayTest { - private static final List PERIODS; - - static { - ImmutableList.Builder builder = ImmutableList.builder(); - for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) { - builder.add(createPeriod(i)); - } - PERIODS = builder.build(); - } - - @Test - public void newArray_always_returns_a_new_instance() { - assertThat(DoubleVariationValue.newArray()).isNotSameAs(DoubleVariationValue.newArray()); - } - - @Test - public void get_returns_unset_DoubleVariationValue_for_each_Period_index() { - DoubleVariationValue.Array array = DoubleVariationValue.newArray(); - for (Period period : PERIODS) { - DoubleVariationValue value = array.get(period); - verifyUnsetVariationValue(value); - } - } - - @Test - public void get_returns_set_DoubleVariationValue_for_each_Period_index_if_increment_has_been_called() { - DoubleVariationValue.Array array = DoubleVariationValue.newArray(); - for (Period period : PERIODS) { - array.increment(period, 66.66); - DoubleVariationValue value = array.get(period); - verifySetDoubleVariation(value, 66.66); - } - } - - @Test - public void incrementAll_increments_internals_from_all_set_DoubleVariationValue_from_source() { - DoubleVariationValue.Array source = DoubleVariationValue.newArray() - .increment(createPeriod(2), 20.6) - .increment(createPeriod(5), 5.5); - - DoubleVariationValue.Array target = DoubleVariationValue.newArray() - .increment(createPeriod(1), 1.7) - .increment(createPeriod(5), 30.5); - target.incrementAll(source); - - verifySetDoubleVariation(target.get(createPeriod(1)), 1.7); - verifySetDoubleVariation(target.get(createPeriod(2)), 20.6); - verifyUnsetVariationValue(target.get(createPeriod(3))); - verifyUnsetVariationValue(target.get(createPeriod(4))); - verifySetDoubleVariation(target.get(createPeriod(5)), 36); - } - - @Test - public void toMeasureVariations_returns_absent_if_no_DoubleVariationValue_has_been_set() { - assertThat(DoubleVariationValue.newArray().toMeasureVariations()).isAbsent(); - } - - @Test - public void toMeasureVariations_returns_value_of_set_DoubleVariationValue_as_double() { - Optional variationsOptional = DoubleVariationValue.newArray() - .increment(createPeriod(2), 2.6) - .increment(createPeriod(5), 15.9) - .toMeasureVariations(); - - assertThat(variationsOptional).isPresent(); - MeasureVariations variations = variationsOptional.get(); - assertThat(variations.hasVariation1()).isFalse(); - assertThat(variations.getVariation2()).isEqualTo(2.6d); - assertThat(variations.hasVariation3()).isFalse(); - assertThat(variations.hasVariation4()).isFalse(); - assertThat(variations.getVariation5()).isEqualTo(15.9d); - } - - private static void verifyUnsetVariationValue(DoubleVariationValue value) { - assertThat(value.isSet()).isFalse(); - assertThat(value.getValue()).isEqualTo(0); - } - - private static void verifySetDoubleVariation(DoubleVariationValue value, double expectedValue) { - assertThat(value.isSet()).isTrue(); - assertThat(value.getValue()).isEqualTo(expectedValue); - } - - private static Period createPeriod(int i) { - return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i)); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValueTest.java similarity index 69% rename from server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueTest.java rename to server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValueTest.java index 7cca94fadc7..5718c4e2391 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValueTest.java @@ -23,59 +23,59 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -public class IntVariationValueTest { +public class IntValueTest { @Test public void newly_created_IntVariationValue_is_unset_and_has_value_0() { - verifyUnsetVariationValue(new IntVariationValue()); + verifyUnsetVariationValue(new IntValue()); } @Test public void increment_int_sets_IntVariationValue_and_increments_value() { - verifySetVariationValue(new IntVariationValue().increment(10), 10); + verifySetVariationValue(new IntValue().increment(10), 10); } @Test public void increment_IntVariationValue_has_no_effect_if_arg_is_null() { - verifyUnsetVariationValue(new IntVariationValue().increment(null)); + verifyUnsetVariationValue(new IntValue().increment(null)); } @Test public void increment_IntVariationValue_has_no_effect_if_arg_is_unset() { - verifyUnsetVariationValue(new IntVariationValue().increment(new IntVariationValue())); + verifyUnsetVariationValue(new IntValue().increment(new IntValue())); } @Test public void increment_IntVariationValue_increments_by_the_value_of_the_arg() { - IntVariationValue source = new IntVariationValue().increment(10); - IntVariationValue target = new IntVariationValue().increment(source); + IntValue source = new IntValue().increment(10); + IntValue target = new IntValue().increment(source); verifySetVariationValue(target, 10); } @Test public void multiple_calls_to_increment_IntVariationValue_increments_by_the_value_of_the_arg() { - IntVariationValue target = new IntVariationValue() - .increment(new IntVariationValue().increment(35)) - .increment(new IntVariationValue().increment(10)); + IntValue target = new IntValue() + .increment(new IntValue().increment(35)) + .increment(new IntValue().increment(10)); verifySetVariationValue(target, 45); } @Test public void multiples_calls_to_increment_int_increment_the_value() { - IntVariationValue variationValue = new IntVariationValue() + IntValue variationValue = new IntValue() .increment(10) .increment(95); verifySetVariationValue(variationValue, 105); } - private static void verifyUnsetVariationValue(IntVariationValue variationValue) { + private static void verifyUnsetVariationValue(IntValue variationValue) { assertThat(variationValue.isSet()).isFalse(); assertThat(variationValue.getValue()).isEqualTo(0); } - private static void verifySetVariationValue(IntVariationValue variationValue, int expected) { + private static void verifySetVariationValue(IntValue variationValue, int expected) { assertThat(variationValue.isSet()).isTrue(); assertThat(variationValue.getValue()).isEqualTo(expected); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java deleted file mode 100644 index 25aa126d301..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.junit.Test; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.guava.api.Assertions.assertThat; - -public class IntVariationValueArrayTest { - private static final List PERIODS; - - static { - ImmutableList.Builder builder = ImmutableList.builder(); - for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) { - builder.add(createPeriod(i)); - } - PERIODS = builder.build(); - } - - @Test - public void newArray_always_returns_a_new_instance() { - assertThat(IntVariationValue.newArray()).isNotSameAs(IntVariationValue.newArray()); - } - - @Test - public void get_returns_unset_IntVariationValue_for_each_Period_index() { - IntVariationValue.Array array = IntVariationValue.newArray(); - for (Period period : PERIODS) { - IntVariationValue value = array.get(period); - verifyUnsetVariationValue(value); - } - } - - @Test - public void get_returns_set_IntVariationValue_for_each_Period_index_if_increment_has_been_called() { - IntVariationValue.Array array = IntVariationValue.newArray(); - for (Period period : PERIODS) { - array.increment(period, 66); - IntVariationValue value = array.get(period); - verifySetVariationValue(value, 66); - } - } - - @Test - public void incrementAll_increments_internals_from_all_set_IntVariationValue_from_source() { - IntVariationValue.Array source = IntVariationValue.newArray() - .increment(createPeriod(2), 20) - .increment(createPeriod(5), 5); - - IntVariationValue.Array target = IntVariationValue.newArray() - .increment(createPeriod(1), 1) - .increment(createPeriod(5), 30); - target.incrementAll(source); - - verifySetVariationValue(target.get(createPeriod(1)), 1); - verifySetVariationValue(target.get(createPeriod(2)), 20); - verifyUnsetVariationValue(target.get(createPeriod(3))); - verifyUnsetVariationValue(target.get(createPeriod(4))); - verifySetVariationValue(target.get(createPeriod(5)), 35); - } - - @Test - public void toMeasureVariations_returns_absent_if_no_IntVariationValue_has_been_set() { - assertThat(IntVariationValue.newArray().toMeasureVariations()).isAbsent(); - } - - @Test - public void toMeasureVariations_returns_value_of_set_IntVariationValue_as_double() { - Optional variationsOptional = IntVariationValue.newArray() - .increment(createPeriod(2), 2) - .increment(createPeriod(5), 15) - .toMeasureVariations(); - - assertThat(variationsOptional).isPresent(); - MeasureVariations variations = variationsOptional.get(); - assertThat(variations.hasVariation1()).isFalse(); - assertThat(variations.getVariation2()).isEqualTo(2d); - assertThat(variations.hasVariation3()).isFalse(); - assertThat(variations.hasVariation4()).isFalse(); - assertThat(variations.getVariation5()).isEqualTo(15d); - } - - private static void verifyUnsetVariationValue(IntVariationValue value) { - assertThat(value.isSet()).isFalse(); - assertThat(value.getValue()).isEqualTo(0); - } - - private static void verifySetVariationValue(IntVariationValue value, int expectedValue) { - assertThat(value.isSet()).isTrue(); - assertThat(value.getValue()).isEqualTo(expectedValue); - } - - private static Period createPeriod(int i) { - return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i)); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValueTest.java similarity index 69% rename from server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueTest.java rename to server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValueTest.java index 0a64ffa145a..4c506df86cb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValueTest.java @@ -23,59 +23,59 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -public class LongVariationValueTest { +public class LongValueTest { @Test public void newly_created_LongVariationValue_is_unset_and_has_value_0() { - verifyUnsetVariationValue(new LongVariationValue()); + verifyUnsetVariationValue(new LongValue()); } @Test public void increment_long_sets_LongVariationValue_and_increments_value() { - verifySetVariationValue(new LongVariationValue().increment(10L), 10L); + verifySetVariationValue(new LongValue().increment(10L), 10L); } @Test public void increment_LongVariationValue_has_no_effect_if_arg_is_null() { - verifyUnsetVariationValue(new LongVariationValue().increment(null)); + verifyUnsetVariationValue(new LongValue().increment(null)); } @Test public void increment_LongVariationValue_has_no_effect_if_arg_is_unset() { - verifyUnsetVariationValue(new LongVariationValue().increment(new LongVariationValue())); + verifyUnsetVariationValue(new LongValue().increment(new LongValue())); } @Test public void increment_LongVariationValue_increments_by_the_value_of_the_arg() { - LongVariationValue source = new LongVariationValue().increment(10L); - LongVariationValue target = new LongVariationValue().increment(source); + LongValue source = new LongValue().increment(10L); + LongValue target = new LongValue().increment(source); verifySetVariationValue(target, 10L); } @Test public void multiple_calls_to_increment_LongVariationValue_increments_by_the_value_of_the_arg() { - LongVariationValue target = new LongVariationValue() - .increment(new LongVariationValue().increment(35L)) - .increment(new LongVariationValue().increment(10L)); + LongValue target = new LongValue() + .increment(new LongValue().increment(35L)) + .increment(new LongValue().increment(10L)); verifySetVariationValue(target, 45L); } @Test public void multiples_calls_to_increment_long_increment_the_value() { - LongVariationValue variationValue = new LongVariationValue() + LongValue variationValue = new LongValue() .increment(10L) .increment(95L); verifySetVariationValue(variationValue, 105L); } - private static void verifyUnsetVariationValue(LongVariationValue variationValue) { + private static void verifyUnsetVariationValue(LongValue variationValue) { assertThat(variationValue.isSet()).isFalse(); assertThat(variationValue.getValue()).isEqualTo(0L); } - private static void verifySetVariationValue(LongVariationValue variationValue, long expected) { + private static void verifySetVariationValue(LongValue variationValue, long expected) { assertThat(variationValue.isSet()).isTrue(); assertThat(variationValue.getValue()).isEqualTo(expected); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java deleted file mode 100644 index ea31e62d132..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; -import java.util.List; -import org.junit.Test; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.guava.api.Assertions.assertThat; - -public class LongVariationValueArrayTest { - private static final List PERIODS; - - static { - ImmutableList.Builder builder = ImmutableList.builder(); - for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) { - builder.add(createPeriod(i)); - } - PERIODS = builder.build(); - } - - @Test - public void newArray_always_returns_a_new_instance() { - assertThat(LongVariationValue.newArray()).isNotSameAs(LongVariationValue.newArray()); - } - - @Test - public void get_returns_unset_LongVariationValue_for_each_Period_index() { - LongVariationValue.Array array = LongVariationValue.newArray(); - for (Period period : PERIODS) { - LongVariationValue value = array.get(period); - verifyUnsetLongVariation(value); - } - } - - @Test - public void get_returns_set_LongVariationValue_for_each_Period_index_if_increment_has_been_called() { - LongVariationValue.Array array = LongVariationValue.newArray(); - for (Period period : PERIODS) { - array.increment(period, 66L); - LongVariationValue value = array.get(period); - verifySetLongVariation(value, 66L); - } - } - - @Test - public void incrementAll_increments_internals_from_all_set_LongVariationValue_from_source() { - LongVariationValue.Array source = LongVariationValue.newArray() - .increment(createPeriod(2), 20l) - .increment(createPeriod(5), 5l); - - LongVariationValue.Array target = LongVariationValue.newArray() - .increment(createPeriod(1), 1L) - .increment(createPeriod(5), 30L); - target.incrementAll(source); - - verifySetLongVariation(target.get(createPeriod(1)), 1L); - verifySetLongVariation(target.get(createPeriod(2)), 20L); - verifyUnsetLongVariation(target.get(createPeriod(3))); - verifyUnsetLongVariation(target.get(createPeriod(4))); - verifySetLongVariation(target.get(createPeriod(5)), 35L); - } - - @Test - public void toMeasureVariations_returns_absent_if_no_LongVariationValue_has_been_set() { - assertThat(LongVariationValue.newArray().toMeasureVariations()).isAbsent(); - } - - @Test - public void toMeasureVariations_returns_value_of_set_LongVariationValue_as_double() { - Optional variationsOptional = LongVariationValue.newArray() - .increment(createPeriod(2), 2L) - .increment(createPeriod(5), 15L) - .toMeasureVariations(); - - assertThat(variationsOptional).isPresent(); - MeasureVariations variations = variationsOptional.get(); - assertThat(variations.hasVariation1()).isFalse(); - assertThat(variations.getVariation2()).isEqualTo(2d); - assertThat(variations.hasVariation3()).isFalse(); - assertThat(variations.hasVariation4()).isFalse(); - assertThat(variations.getVariation5()).isEqualTo(15d); - } - - private static void verifyUnsetLongVariation(LongVariationValue value) { - assertThat(value.isSet()).isFalse(); - assertThat(value.getValue()).isEqualTo(0L); - } - - private static void verifySetLongVariation(LongVariationValue value, long expectedValue) { - assertThat(value.isSet()).isTrue(); - assertThat(value.getValue()).isEqualTo(expectedValue); - } - - private static Period createPeriod(int i) { - return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i)); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValueTest.java similarity index 71% rename from server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueTest.java rename to server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValueTest.java index d8af49ee590..29f5427e604 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValueTest.java @@ -29,60 +29,60 @@ import static org.sonar.server.computation.task.projectanalysis.qualitymodel.Rat import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.C; import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.D; -public class RatingVariationValueTest { +public class RatingValueTest { @Test public void newly_created_value_is_unset_and_has_value_0() { - verifyUnsetVariationValue(new RatingVariationValue()); + verifyUnsetVariationValue(new RatingValue()); } @Test public void increment_sets_value_and_increments_value() { - verifySetVariationValue(new RatingVariationValue().increment(B), B); + verifySetVariationValue(new RatingValue().increment(B), B); } @Test public void increment_has_no_effect_if_arg_is_null() { - verifyUnsetVariationValue(new RatingVariationValue().increment((RatingVariationValue) null)); + verifyUnsetVariationValue(new RatingValue().increment((RatingValue) null)); } @Test public void increment_has_no_effect_if_arg_is_unset() { - verifyUnsetVariationValue(new RatingVariationValue().increment(new RatingVariationValue())); + verifyUnsetVariationValue(new RatingValue().increment(new RatingValue())); } @Test public void increment_increments_by_the_value_of_the_arg() { - RatingVariationValue source = new RatingVariationValue().increment(B); - RatingVariationValue target = new RatingVariationValue().increment(source); + RatingValue source = new RatingValue().increment(B); + RatingValue target = new RatingValue().increment(source); verifySetVariationValue(target, B); } @Test public void multiple_calls_to_increment_increments_by_the_value_of_the_arg() { - RatingVariationValue target = new RatingVariationValue() - .increment(new RatingVariationValue().increment(B)) - .increment(new RatingVariationValue().increment(D)); + RatingValue target = new RatingValue() + .increment(new RatingValue().increment(B)) + .increment(new RatingValue().increment(D)); verifySetVariationValue(target, D); } @Test public void multiples_calls_to_increment_increments_the_value() { - RatingVariationValue variationValue = new RatingVariationValue() + RatingValue variationValue = new RatingValue() .increment(B) .increment(C); verifySetVariationValue(variationValue, C); } - private static void verifyUnsetVariationValue(RatingVariationValue variationValue) { + private static void verifyUnsetVariationValue(RatingValue variationValue) { assertThat(variationValue.isSet()).isFalse(); assertThat(variationValue.getValue()).isEqualTo(A); } - private static void verifySetVariationValue(RatingVariationValue variationValue, Rating expected) { + private static void verifySetVariationValue(RatingValue variationValue, Rating expected) { assertThat(variationValue.isSet()).isTrue(); assertThat(variationValue.getValue()).isEqualTo(expected); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java deleted file mode 100644 index 6d34d932d78..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.task.projectanalysis.formula.counter; - -import com.google.common.collect.ImmutableList; -import java.util.List; -import java.util.Optional; -import org.assertj.guava.api.Assertions; -import org.junit.Test; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; -import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating; -import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.A; -import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.B; -import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.C; -import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.D; -import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.E; - -public class RatingVariationValueArrayTest { - - private static final List PERIODS; - - static { - ImmutableList.Builder builder = ImmutableList.builder(); - for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) { - builder.add(createPeriod(i)); - } - PERIODS = builder.build(); - } - - @Test - public void newArray_always_returns_a_new_instance() { - assertThat(RatingVariationValue.newArray()).isNotSameAs(RatingVariationValue.newArray()); - } - - @Test - public void get_returns_unset_value_for_each_period_index() { - RatingVariationValue.Array array = RatingVariationValue.newArray(); - PERIODS.forEach(p -> verifyUnsetVariation(array.get(p))); - } - - @Test - public void get_returns_set_value_for_each_period_index_if_increment_has_been_called() { - RatingVariationValue.Array array = RatingVariationValue.newArray(); - PERIODS.forEach(period -> { - array.increment(period, C); - verifySetVariation(array.get(period), C); - }); - } - - @Test - public void incrementAll_increments_internals_from_all_set_value_from_source() { - RatingVariationValue.Array source = RatingVariationValue.newArray() - .increment(createPeriod(2), B) - .increment(createPeriod(5), C); - - RatingVariationValue.Array target = RatingVariationValue.newArray() - .increment(createPeriod(1), D) - .increment(createPeriod(5), E); - target.incrementAll(source); - - verifySetVariation(target.get(createPeriod(1)), D); - verifySetVariation(target.get(createPeriod(2)), B); - verifyUnsetVariation(target.get(createPeriod(3))); - verifyUnsetVariation(target.get(createPeriod(4))); - verifySetVariation(target.get(createPeriod(5)), E); - } - - @Test - public void toMeasureVariations_returns_absent_if_no_value_has_been_set() { - Assertions.assertThat(LongVariationValue.newArray().toMeasureVariations()).isAbsent(); - } - - @Test - public void toMeasureVariations_returns_value_of_set_value_as_double() { - Optional variationsOptional = RatingVariationValue.newArray() - .increment(createPeriod(2), B) - .increment(createPeriod(5), A) - .toMeasureVariations(); - - assertThat(variationsOptional).isPresent(); - MeasureVariations variations = variationsOptional.get(); - assertThat(variations.hasVariation1()).isFalse(); - assertThat(variations.getVariation2()).isEqualTo(2d); - assertThat(variations.hasVariation3()).isFalse(); - assertThat(variations.hasVariation4()).isFalse(); - assertThat(variations.getVariation5()).isEqualTo(1d); - } - - private static void verifyUnsetVariation(RatingVariationValue value) { - assertThat(value.isSet()).isFalse(); - assertThat(value.getValue()).isEqualTo(A); - } - - private static void verifySetVariation(RatingVariationValue value, Rating expectedValue) { - assertThat(value.isSet()).isTrue(); - assertThat(value.getValue()).isEqualTo(expectedValue); - } - - private static Period createPeriod(int i) { - return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i)); - } - -} -- 2.39.5