diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-09-01 11:00:46 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-09-02 14:28:19 +0200 |
commit | 5be09626fee67f720d766930cd79add7aaac3adc (patch) | |
tree | e3977b862d1ba64350d50508c893790e449ed686 /sonar-plugin-api/src/test | |
parent | d8efb97a9451855a881ab375768bcb044097ed5c (diff) | |
download | sonarqube-5be09626fee67f720d766930cd79add7aaac3adc.tar.gz sonarqube-5be09626fee67f720d766930cd79add7aaac3adc.zip |
SONAR-6730 Move test implementation to org.sonar.api.ce.measure.test
Diffstat (limited to 'sonar-plugin-api/src/test')
9 files changed, 0 insertions, 889 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/ComponentImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/ComponentImpl.java deleted file mode 100644 index b8fef1332bc..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/ComponentImpl.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; -import org.sonar.api.ce.measure.Component; - -import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; - -@Immutable -public class ComponentImpl implements Component { - - private final String key; - - private final Type type; - - @CheckForNull - private final FileAttributes fileAttributes; - - public ComponentImpl(String key, Type type, @Nullable FileAttributes fileAttributes) { - this.key = requireNonNull(key, "Key cannot be null"); - this.type = requireNonNull(type, "Type cannot be null"); - this.fileAttributes = checkFileAttributes(fileAttributes); - } - - @CheckForNull - private FileAttributes checkFileAttributes(@Nullable FileAttributes fileAttributes) { - if (fileAttributes == null && type == Type.FILE) { - throw new IllegalArgumentException("Component of type FILE must have a FileAttributes object"); - } else if (fileAttributes != null && type != Type.FILE) { - throw new IllegalArgumentException("Only component of type FILE have a FileAttributes object"); - } - return fileAttributes; - } - - @Override - public Type getType() { - return type; - } - - @Override - public String getKey() { - return key; - } - - @Override - public FileAttributes getFileAttributes() { - checkState(this.type == Component.Type.FILE, "Only component of type FILE have a FileAttributes object"); - return fileAttributes; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - ComponentImpl component = (ComponentImpl) o; - - return key.equals(component.key); - } - - @Override - public int hashCode() { - return key.hashCode(); - } - - @Override - public String toString() { - return "ComponentImpl{" + - "key=" + key + - ", type='" + type + '\'' + - ", fileAttributes=" + fileAttributes + - '}'; - } - - @Immutable - public static class FileAttributesImpl implements FileAttributes { - - private final boolean unitTest; - private final String languageKey; - - public FileAttributesImpl(@Nullable String languageKey, boolean unitTest) { - this.languageKey = languageKey; - this.unitTest = unitTest; - } - - @Override - public boolean isUnitTest() { - return unitTest; - } - - @Override - @CheckForNull - public String getLanguageKey() { - return languageKey; - } - - @Override - public String toString() { - return "FileAttributesImpl{" + - "languageKey='" + languageKey + '\'' + - ", unitTest=" + unitTest + - '}'; - } - } -} - diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java deleted file mode 100644 index 0f47f4ff133..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.sonar.api.ce.measure.Issue; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; -import org.sonar.api.utils.Duration; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -public class IssueImpl implements Issue { - - private String key; - private String status; - private String resolution; - private String severity; - private RuleKey ruleKey; - private Duration debt; - - private IssueImpl(Builder builder) { - this.key = builder.key; - this.status = builder.status; - this.resolution = builder.resolution; - this.severity = builder.severity; - this.ruleKey = builder.ruleKey; - this.debt = builder.debt; - } - - @Override - public String key() { - return key; - } - - @Override - public RuleKey ruleKey() { - return ruleKey; - } - - @Override - public String status() { - return status; - } - - @Override - @CheckForNull - public String resolution() { - return resolution; - } - - @Override - public String severity() { - return severity; - } - - @Override - @CheckForNull - public Duration debt() { - return debt; - } - - public static class Builder { - private String key; - private String status; - private String resolution; - private String severity; - private RuleKey ruleKey; - private Duration debt; - - public Builder setKey(String key) { - this.key = validateKey(key); - return this; - } - - public Builder setResolution(@Nullable String resolution) { - this.resolution = validateResolution(resolution); - return this; - } - - public Builder setSeverity(String severity) { - this.severity = validateSeverity(severity); - return this; - } - - public Builder setStatus(String status) { - this.status = validateStatus(status); - return this; - } - - public Builder setRuleKey(RuleKey ruleKey) { - this.ruleKey = validateRuleKey(ruleKey); - return this; - } - - public Builder setDebt(@Nullable Duration debt) { - this.debt = debt; - return this; - } - - private static String validateKey(String key){ - checkNotNull(key, "key cannot be null"); - return key; - } - - private static RuleKey validateRuleKey(RuleKey ruleKey){ - checkNotNull(ruleKey, "ruleKey cannot be null"); - return ruleKey; - } - - private static String validateResolution(@Nullable String resolution){ - checkArgument(resolution == null || org.sonar.api.issue.Issue.RESOLUTIONS.contains(resolution), String.format("resolution '%s' is invalid", resolution)); - return resolution; - } - - private static String validateSeverity(String severity){ - checkNotNull(severity, "severity cannot be null"); - checkArgument(Severity.ALL.contains(severity), String.format("severity '%s' is invalid", severity)); - return severity; - } - - private static String validateStatus(String status){ - checkNotNull(status, "status cannot be null"); - checkArgument(org.sonar.api.issue.Issue.STATUSES.contains(status), String.format("status '%s' is invalid", status)); - return status; - } - - public Issue build(){ - validateKey(key); - validateResolution(resolution); - validateSeverity(severity); - validateStatus(status); - validateRuleKey(ruleKey); - return new IssueImpl(this); - } - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java deleted file mode 100644 index b661247a517..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImpl.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import com.google.common.collect.ImmutableSet; -import java.util.Set; -import javax.annotation.Nullable; -import org.sonar.api.ce.measure.MeasureComputer; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; - -public class MeasureComputerImpl implements MeasureComputer { - - private final Set<String> inputMetricKeys; - private final Set<String> outputMetrics; - private final Implementation measureComputerImplementation; - - public MeasureComputerImpl(MeasureComputerBuilderImpl builder) { - this.inputMetricKeys = ImmutableSet.copyOf(builder.inputMetricKeys); - this.outputMetrics = ImmutableSet.copyOf(builder.outputMetrics); - this.measureComputerImplementation = builder.measureComputerImplementation; - } - - @Override - public Set<String> getInputMetrics() { - return inputMetricKeys; - } - - @Override - public Set<String> getOutputMetrics() { - return outputMetrics; - } - - @Override - public Implementation getImplementation() { - return measureComputerImplementation; - } - - @Override - public String toString() { - return "MeasureComputerImpl{" + - "inputMetricKeys=" + inputMetricKeys + - ", outputMetrics=" + outputMetrics + - ", implementation=" + measureComputerImplementation.toString() + - '}'; - } - - public static class MeasureComputerBuilderImpl implements MeasureComputerBuilder { - - private String[] inputMetricKeys = new String[] {}; - private String[] outputMetrics; - private Implementation measureComputerImplementation; - - @Override - public MeasureComputerBuilder setInputMetrics(String... inputMetrics) { - this.inputMetricKeys = validateInputMetricKeys(inputMetrics); - return this; - } - - @Override - public MeasureComputerBuilder setOutputMetrics(String... outputMetrics) { - this.outputMetrics = validateOutputMetricKeys(outputMetrics); - return this; - } - - @Override - public MeasureComputerBuilder setImplementation(Implementation impl) { - this.measureComputerImplementation = validateImplementation(impl); - return this; - } - - @Override - public MeasureComputer build() { - validateInputMetricKeys(this.inputMetricKeys); - validateOutputMetricKeys(this.outputMetrics); - validateImplementation(this.measureComputerImplementation); - return new MeasureComputerImpl(this); - } - - private static String[] validateInputMetricKeys(@Nullable String[] inputMetrics) { - requireNonNull(inputMetrics, "Input metrics cannot be null"); - checkNotNull(inputMetrics); - return inputMetrics; - } - - private static String[] validateOutputMetricKeys(@Nullable String[] outputMetrics) { - checkArgument(outputMetrics != null && outputMetrics.length > 0, "At least one output metric must be defined"); - checkNotNull(outputMetrics); - return outputMetrics; - } - - private static Implementation validateImplementation(Implementation impl) { - return requireNonNull(impl, "The implementation is missing"); - } - } - - private static void checkNotNull(String[] metrics){ - for (String metric : metrics) { - requireNonNull(metric, "Null metric is not allowed"); - } - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java deleted file mode 100644 index 2176a7ee8e8..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.annotation.CheckForNull; -import org.sonar.api.ce.measure.Component; -import org.sonar.api.ce.measure.Issue; -import org.sonar.api.ce.measure.Measure; -import org.sonar.api.ce.measure.MeasureComputer; -import org.sonar.api.ce.measure.Settings; - -import static com.google.common.base.Preconditions.checkArgument; - -public class MeasureComputerImplementationContext implements MeasureComputer.Implementation.Context { - - private final Component component; - private final MeasureComputer measureComputer; - private final Settings settings; - - private Map<String, Measure> componentMeasureByMetricKey = new HashMap<>(); - private Multimap<String, Measure> childrenComponentMeasureByMetricKey = ArrayListMultimap.create(); - private List<Issue> issues = new ArrayList<>(); - - public MeasureComputerImplementationContext(Component component, Settings settings, MeasureComputer measureComputer) { - this.measureComputer = measureComputer; - this.settings = settings; - this.component = component; - } - - @Override - public Component getComponent() { - return component; - } - - @Override - public Settings getSettings() { - return settings; - } - - @Override - @CheckForNull - public Measure getMeasure(String metric) { - validateInputMetric(metric); - return componentMeasureByMetricKey.get(metric); - } - - @Override - public Iterable<Measure> getChildrenMeasures(String metric) { - validateInputMetric(metric); - return childrenComponentMeasureByMetricKey.get(metric); - } - - @Override - public void addMeasure(String metricKey, int value) { - validateAddMeasure(metricKey); - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addInputMeasure(String metricKey, int value) { - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addChildrenMeasures(String metricKey, Integer... values) { - for (Integer value : values) { - childrenComponentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - } - - @Override - public void addMeasure(String metricKey, double value) { - validateAddMeasure(metricKey); - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addInputMeasure(String metricKey, double value) { - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addChildrenMeasures(String metricKey, Double... values) { - for (Double value : values) { - childrenComponentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - } - - @Override - public void addMeasure(String metricKey, long value) { - validateAddMeasure(metricKey); - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addInputMeasure(String metricKey, long value) { - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addChildrenMeasures(String metricKey, Long... values) { - for (Long value : values) { - childrenComponentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - } - - @Override - public void addMeasure(String metricKey, String value) { - validateAddMeasure(metricKey); - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addInputMeasure(String metricKey, String value) { - componentMeasureByMetricKey.put(metricKey, MeasureImpl.createMeasure(value)); - } - - public void addChildrenMeasures(String metricKey, String... values) { - for (String value : values) { - childrenComponentMeasureByMetricKey.put(metricKey,MeasureImpl.createMeasure(value)); - } - } - - @Override - public List<Issue> getIssues() { - return issues; - } - - public void setIssues(List<Issue> issues){ - this.issues = issues; - } - - private void validateInputMetric(String metric) { - Set<String> allowedMetrics = new HashSet<>(); - allowedMetrics.addAll(measureComputer.getInputMetrics()); - allowedMetrics.addAll(measureComputer.getOutputMetrics()); - checkArgument(allowedMetrics.contains(metric), "Only metrics in %s can be used to load measures", measureComputer.getInputMetrics()); - } - - private void validateAddMeasure(String metricKey) { - checkArgument(measureComputer.getOutputMetrics().contains(metricKey), "Only metrics in %s can be used to add measures. Metric '%s' is not allowed.", - measureComputer.getOutputMetrics(), metricKey); - if (componentMeasureByMetricKey.get(metricKey) != null) { - throw new UnsupportedOperationException(String.format("A measure on metric '%s' already exists", metricKey)); - } - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerProviderContext.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerProviderContext.java deleted file mode 100644 index 66318c0a967..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerProviderContext.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.sonar.api.ce.measure.MeasureComputer; -import org.sonar.api.ce.measure.MeasureComputerProvider; - -public class MeasureComputerProviderContext implements MeasureComputerProvider.Context { - - private final List<MeasureComputer> measureComputers = new ArrayList<>(); - private final Map<String, MeasureComputer> computerByOutputMetrics = new HashMap<>(); - - @Override - public MeasureComputerProvider.Context add(MeasureComputer measureComputer) { - checkOutputMetricsNotAlreadyDefinedByAnotherComputer(measureComputer); - this.measureComputers.add(measureComputer); - for (String metric : measureComputer.getOutputMetrics()) { - computerByOutputMetrics.put(metric, measureComputer); - } - return this; - } - - public List<MeasureComputer> getMeasureComputers() { - return measureComputers; - } - - private void checkOutputMetricsNotAlreadyDefinedByAnotherComputer(MeasureComputer measureComputer) { - Set<String> duplicated = ImmutableSet.copyOf(Sets.intersection(computerByOutputMetrics.keySet(), measureComputer.getOutputMetrics())); - if (!duplicated.isEmpty()) { - throw new UnsupportedOperationException(generateErrorMsg(duplicated)); - } - } - - private String generateErrorMsg(Set<String> duplicated){ - StringBuilder errorMsg = new StringBuilder(); - for (String duplicationMetric : duplicated) { - MeasureComputer otherComputer = computerByOutputMetrics.get(duplicationMetric); - errorMsg.append(String.format( - "The output metric '%s' is already declared by another computer. This computer has these input metrics '%s' and these output metrics '%s'. ", - duplicationMetric, otherComputer.getInputMetrics(), otherComputer.getOutputMetrics())); - } - return errorMsg.toString(); - } - - @Override - public MeasureComputer.MeasureComputerBuilder newMeasureComputerBuilder() { - return new MeasureComputerImpl.MeasureComputerBuilderImpl(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerTester.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerTester.java deleted file mode 100644 index f9d62ca11f5..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerTester.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; -import java.util.List; -import javax.annotation.CheckForNull; -import org.sonar.api.ce.measure.MeasureComputer; -import org.sonar.api.ce.measure.MeasureComputerProvider; - -public class MeasureComputerTester { - - private final MeasureComputerProviderContext context = new MeasureComputerProviderContext(); - - public MeasureComputerTester(MeasureComputerProvider... providers) { - for (MeasureComputerProvider provider : providers) { - provider.register(context); - } - } - - public MeasureComputerProvider.Context context() { - return context; - } - - public List<MeasureComputer> getMeasureComputers() { - return context.getMeasureComputers(); - } - - /** - * Return the measure computer that provide the output metric - */ - @CheckForNull - public MeasureComputer measureComputer(String outputMetric){ - Optional<MeasureComputer> measureComputer = FluentIterable.from(getMeasureComputers()).firstMatch(new MatchingOuputMetricKey(outputMetric)); - return measureComputer.isPresent() ? measureComputer.get() : null; - } - - private static class MatchingOuputMetricKey implements Predicate<MeasureComputer> { - - private final String metricKey; - - public MatchingOuputMetricKey(String metricKey) { - this.metricKey = metricKey; - } - - @Override - public boolean apply(MeasureComputer input) { - return input.getOutputMetrics().contains(metricKey); - } - } - - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureImpl.java deleted file mode 100644 index 43dc4bdb36a..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import javax.annotation.concurrent.Immutable; -import org.sonar.api.ce.measure.Measure; - -import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; - -@Immutable -public class MeasureImpl implements Measure { - - private Integer intValue; - private Long longValue; - private Double doubleValue; - private String stringValue; - - public static MeasureImpl createMeasure(double doubleValue){ - MeasureImpl measure = new MeasureImpl(); - measure.doubleValue = doubleValue; - return measure; - } - - public static MeasureImpl createMeasure(int intValue) { - MeasureImpl measure = new MeasureImpl(); - measure.intValue = intValue; - return measure; - } - - public static MeasureImpl createMeasure(long longValue) { - MeasureImpl measure = new MeasureImpl(); - measure.longValue = longValue; - return measure; - } - - public static MeasureImpl createMeasure(String stringValue) { - MeasureImpl measure = new MeasureImpl(); - measure.stringValue = requireNonNull(stringValue, "Value cannot be null"); - return measure; - } - - @Override - public int getIntValue() { - checkState(intValue != null, "Not an int measure"); - return intValue; - } - - @Override - public long getLongValue() { - checkState(longValue != null, "Not a long measure"); - return longValue; - } - - @Override - public double getDoubleValue() { - checkState(doubleValue != null, "Not a double measure"); - return doubleValue; - } - - @Override - public String getStringValue() { - checkState(stringValue != null, "Not a string measure"); - return stringValue; - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/SettingsImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/SettingsImpl.java deleted file mode 100644 index e713dc39c24..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/SettingsImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.test.ce.measure; - -import java.util.HashMap; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.ce.measure.Settings; - -public class SettingsImpl implements Settings { - - private Map<String, String> valuesByKey = new HashMap<>(); - - public Settings setValue(String key, String value){ - valuesByKey.put(key, value); - return this; - } - - @Override - @CheckForNull - public String getString(String key) { - return valuesByKey.get(key); - } - - @Override - public String[] getStringArray(String key) { - String value = getString(key); - if (value != null) { - String[] strings = StringUtils.splitByWholeSeparator(value, ","); - String[] result = new String[strings.length]; - for (int index = 0; index < strings.length; index++) { - result[index] = StringUtils.trim(strings[index]); - } - return result; - } - return ArrayUtils.EMPTY_STRING_ARRAY; - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java deleted file mode 100644 index aaa0831b888..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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. - */ - -@ParametersAreNonnullByDefault -package org.sonar.api.test.ce.measure; - -import javax.annotation.ParametersAreNonnullByDefault; |