]> source.dussan.org Git - sonarqube.git/blob
7491f588d6856122f6275ce7ca87e9e7bbcecf3d
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2016 SonarSource SA
4  * mailto:contact AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails;
21
22 import org.junit.Test;
23 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
24 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
25 import org.sonar.server.computation.task.projectanalysis.qualitygate.Condition;
26
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.mockito.Mockito.mock;
29
30 public class EvaluatedConditionTest {
31
32   private static final Condition SOME_CONDITION = new Condition(mock(Metric.class), Condition.Operator.EQUALS.getDbValue(), "1", null, null);
33   private static final Measure.Level SOME_LEVEL = Measure.Level.OK;
34   private static final String SOME_VALUE = "some value";
35
36   @Test(expected = NullPointerException.class)
37   public void constructor_throws_NPE_if_Condition_arg_is_null() {
38     new EvaluatedCondition(null, SOME_LEVEL, SOME_VALUE);
39   }
40
41   @Test(expected = NullPointerException.class)
42   public void constructor_throws_NPE_if_Level_arg_is_null() {
43     new EvaluatedCondition(SOME_CONDITION, null, SOME_VALUE);
44   }
45
46   @Test
47   public void getCondition_returns_object_passed_in_constructor() {
48     assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, SOME_VALUE).getCondition()).isSameAs(SOME_CONDITION);
49   }
50
51   @Test
52   public void getLevel_returns_object_passed_in_constructor() {
53     assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, SOME_VALUE).getLevel()).isSameAs(SOME_LEVEL);
54   }
55
56   @Test
57   public void getValue_returns_empty_string_if_null_was_passed_in_constructor() {
58     assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, null).getActualValue()).isEmpty();
59   }
60
61   @Test
62   public void getValue_returns_toString_of_Object_passed_in_constructor() {
63     assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, new A()).getActualValue()).isEqualTo("A string");
64   }
65
66   private static class A {
67     @Override
68     public String toString() {
69       return "A string";
70     }
71   }
72 }