3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info 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.
20 package org.sonar.ce.task.projectanalysis.measure.qualitygatedetails;
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;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
31 public class EvaluatedConditionTest {
33 private static final Metric SOME_METRIC = mock(Metric.class);
35 when(SOME_METRIC.getKey()).thenReturn("dummy key");
37 private static final Condition SOME_CONDITION = new Condition(SOME_METRIC, Condition.Operator.EQUALS.getDbValue(), "1");
38 private static final Measure.Level SOME_LEVEL = Measure.Level.OK;
39 private static final String SOME_VALUE = "some value";
41 @Test(expected = NullPointerException.class)
42 public void constructor_throws_NPE_if_Condition_arg_is_null() {
43 new EvaluatedCondition(null, SOME_LEVEL, SOME_VALUE);
46 @Test(expected = NullPointerException.class)
47 public void constructor_throws_NPE_if_Level_arg_is_null() {
48 new EvaluatedCondition(SOME_CONDITION, null, SOME_VALUE);
52 public void getCondition_returns_object_passed_in_constructor() {
53 assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, SOME_VALUE).getCondition()).isSameAs(SOME_CONDITION);
57 public void getLevel_returns_object_passed_in_constructor() {
58 assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, SOME_VALUE).getLevel()).isSameAs(SOME_LEVEL);
62 public void getValue_returns_empty_string_if_null_was_passed_in_constructor() {
63 assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, null).getActualValue()).isEmpty();
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");
71 private static class A {
73 public String toString() {