diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-01 17:59:39 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-01 18:07:49 +0100 |
commit | 40b377727fb47c4640d597f4bd3ff192ab143833 (patch) | |
tree | 49489a6cfd4b347ff0ae77ba47a88c3125ba0ad3 /sonar-db | |
parent | 67ebdfe31073e8bb8b019990d9c0f463a85da204 (diff) | |
download | sonarqube-40b377727fb47c4640d597f4bd3ff192ab143833.tar.gz sonarqube-40b377727fb47c4640d597f4bd3ff192ab143833.zip |
Fix quality flaws
Diffstat (limited to 'sonar-db')
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/metric/MetricDtoFunctionsTest.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/metric/MetricDtoFunctionsTest.java b/sonar-db/src/test/java/org/sonar/db/metric/MetricDtoFunctionsTest.java new file mode 100644 index 00000000000..386b6b604c6 --- /dev/null +++ b/sonar-db/src/test/java/org/sonar/db/metric/MetricDtoFunctionsTest.java @@ -0,0 +1,81 @@ +/* + * 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.db.metric; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MetricDtoFunctionsTest { + + MetricDto metric; + + @Test + public void toId() { + metric = new MetricDto().setId(42); + + Integer result = MetricDtoFunctions.toId().apply(metric); + + assertThat(result).isEqualTo(42); + } + + @Test + public void toKey() { + metric = new MetricDto().setKey("my-metric-key"); + + String result = MetricDtoFunctions.toKey().apply(metric); + + assertThat(result).isEqualTo("my-metric-key"); + } + + @Test + public void isOptimizedForBestValue_at_true() { + metric = new MetricDto() + .setBestValue(42.0d) + .setOptimizedBestValue(true); + + boolean result = MetricDtoFunctions.isOptimizedForBestValue().apply(metric); + + assertThat(result).isTrue(); + } + + @Test + public void isOptimizedForBestValue_is_false_when_no_best_value() { + metric = new MetricDto() + .setBestValue(null) + .setOptimizedBestValue(true); + + boolean result = MetricDtoFunctions.isOptimizedForBestValue().apply(metric); + + assertThat(result).isFalse(); + } + + @Test + public void isOptimizedForBestValue_is_false_when_is_not_optimized() { + metric = new MetricDto() + .setBestValue(42.0d) + .setOptimizedBestValue(false); + + boolean result = MetricDtoFunctions.isOptimizedForBestValue().apply(metric); + + assertThat(result).isFalse(); + } +} |