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.
20 package org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails;
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;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.mockito.Mockito.mock;
30 public class EvaluatedConditionTest {
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";
36 @Test(expected = NullPointerException.class)
37 public void constructor_throws_NPE_if_Condition_arg_is_null() {
38 new EvaluatedCondition(null, SOME_LEVEL, SOME_VALUE);
41 @Test(expected = NullPointerException.class)
42 public void constructor_throws_NPE_if_Level_arg_is_null() {
43 new EvaluatedCondition(SOME_CONDITION, null, SOME_VALUE);
47 public void getCondition_returns_object_passed_in_constructor() {
48 assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, SOME_VALUE).getCondition()).isSameAs(SOME_CONDITION);
52 public void getLevel_returns_object_passed_in_constructor() {
53 assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, SOME_VALUE).getLevel()).isSameAs(SOME_LEVEL);
57 public void getValue_returns_empty_string_if_null_was_passed_in_constructor() {
58 assertThat(new EvaluatedCondition(SOME_CONDITION, SOME_LEVEL, null).getActualValue()).isEmpty();
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");
66 private static class A {
68 public String toString() {