1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2011 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.api.qualitymodel;
import org.junit.Test;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
public class CharacteristicTest {
@Test
public void testStringProperties() {
Characteristic characteristic = Characteristic.create();
characteristic.setProperty("foo", "bar");
assertThat(characteristic.getProperty("foo"), notNullValue());
assertThat(characteristic.getPropertyTextValue("foo", null), is("bar"));
assertThat(characteristic.getPropertyValue("foo", null), nullValue());
assertThat(characteristic.getProperty("unknown"), nullValue());
assertThat(characteristic.getPropertyTextValue("unknown", null), nullValue());
}
@Test
public void testDoubleProperties() {
Characteristic characteristic = Characteristic.create();
characteristic.setProperty("foo", 3.1);
assertThat(characteristic.getProperty("foo"), notNullValue());
assertThat(characteristic.getPropertyValue("foo", null), is(3.1));
assertThat(characteristic.getPropertyTextValue("foo", null), nullValue());
}
@Test
public void addProperty() {
Characteristic characteristic = Characteristic.create();
characteristic.addProperty(CharacteristicProperty.create("foo"));
CharacteristicProperty property = characteristic.getProperty("foo");
assertThat(property, notNullValue());
assertTrue(property.getCharacteristic()==characteristic);
}
@Test
public void shouldCreateByName() {
Characteristic characteristic = Characteristic.createByName("Foo");
assertThat(characteristic.getKey(), is("FOO"));
assertThat(characteristic.getName(), is("Foo"));
}
@Test
public void shouldReturnDefaultValues() {
Characteristic characteristic = Characteristic.create();
characteristic.setProperty("foo", (String)null);
characteristic.setProperty("bar", (Double)null);
assertThat(characteristic.getPropertyTextValue("foo", "foodef"), is("foodef"));
assertThat(characteristic.getPropertyTextValue("other", "otherdef"), is("otherdef"));
assertThat(characteristic.getPropertyValue("bar", 3.14), is(3.14));
assertThat(characteristic.getPropertyValue("other", 3.14), is(3.14));
}
}
|