3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.computation.task.projectanalysis.formula.counter;
23 import org.junit.Test;
24 import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.A;
28 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.B;
29 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.C;
30 import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.D;
32 public class RatingVariationValueTest {
35 public void newly_created_value_is_unset_and_has_value_0() {
36 verifyUnsetVariationValue(new RatingVariationValue());
40 public void increment_sets_value_and_increments_value() {
41 verifySetVariationValue(new RatingVariationValue().increment(B), B);
45 public void increment_has_no_effect_if_arg_is_null() {
46 verifyUnsetVariationValue(new RatingVariationValue().increment((RatingVariationValue) null));
50 public void increment_has_no_effect_if_arg_is_unset() {
51 verifyUnsetVariationValue(new RatingVariationValue().increment(new RatingVariationValue()));
55 public void increment_increments_by_the_value_of_the_arg() {
56 RatingVariationValue source = new RatingVariationValue().increment(B);
57 RatingVariationValue target = new RatingVariationValue().increment(source);
59 verifySetVariationValue(target, B);
63 public void multiple_calls_to_increment_increments_by_the_value_of_the_arg() {
64 RatingVariationValue target = new RatingVariationValue()
65 .increment(new RatingVariationValue().increment(B))
66 .increment(new RatingVariationValue().increment(D));
68 verifySetVariationValue(target, D);
72 public void multiples_calls_to_increment_increments_the_value() {
73 RatingVariationValue variationValue = new RatingVariationValue()
77 verifySetVariationValue(variationValue, C);
80 private static void verifyUnsetVariationValue(RatingVariationValue variationValue) {
81 assertThat(variationValue.isSet()).isFalse();
82 assertThat(variationValue.getValue()).isEqualTo(A);
85 private static void verifySetVariationValue(RatingVariationValue variationValue, Rating expected) {
86 assertThat(variationValue.isSet()).isTrue();
87 assertThat(variationValue.getValue()).isEqualTo(expected);