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