]> source.dussan.org Git - sonarqube.git/blob
6cdb209c18fec05a71836831a16b21328038324f
[sonarqube.git] /
1 /*
2  * SonarQube, open source software quality management tool.
3  * Copyright (C) 2008-2013 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
6  * SonarQube 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  * SonarQube 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
21 package org.sonar.api.technicaldebt.server.internal;
22
23 import org.junit.Test;
24 import org.sonar.api.rule.RuleKey;
25 import org.sonar.api.utils.WorkUnit;
26
27 import static org.fest.assertions.Assertions.assertThat;
28
29 public class DefaultCharacteristicTest {
30
31   @Test
32   public void test_setters_and_getters_for_characteristic() throws Exception {
33     DefaultCharacteristic characteristic = new DefaultCharacteristic()
34       .setId(1)
35       .setKey("NETWORK_USE")
36       .setName("Network use")
37       .setOrder(5)
38       .setParentId(2)
39       .setRootId(2);
40
41     assertThat(characteristic.id()).isEqualTo(1);
42     assertThat(characteristic.key()).isEqualTo("NETWORK_USE");
43     assertThat(characteristic.name()).isEqualTo("Network use");
44     assertThat(characteristic.order()).isEqualTo(5);
45     assertThat(characteristic.ruleKey()).isNull();
46     assertThat(characteristic.function()).isNull();
47     assertThat(characteristic.factor()).isNull();
48     assertThat(characteristic.offset()).isNull();
49     assertThat(characteristic.parentId()).isEqualTo(2);
50     assertThat(characteristic.rootId()).isEqualTo(2);
51   }
52
53   @Test
54   public void test_setters_and_getters_for_requirement() throws Exception {
55     DefaultCharacteristic requirement = new DefaultCharacteristic()
56       .setId(1)
57       .setRuleKey(RuleKey.of("repo", "rule"))
58       .setFunction("linear_offset")
59       .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
60       .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
61       .setRootId(3)
62       .setParentId(2);
63
64     assertThat(requirement.id()).isEqualTo(1);
65     assertThat(requirement.key()).isNull();
66     assertThat(requirement.name()).isNull();
67     assertThat(requirement.order()).isNull();
68     assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
69     assertThat(requirement.function()).isEqualTo("linear_offset");
70     assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
71     assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
72     assertThat(requirement.parentId()).isEqualTo(2);
73     assertThat(requirement.rootId()).isEqualTo(3);
74   }
75
76   @Test
77   public void is_root() throws Exception {
78     DefaultCharacteristic characteristic = new DefaultCharacteristic()
79       .setId(1)
80       .setKey("NETWORK_USE")
81       .setName("Network use")
82       .setOrder(5)
83       .setParentId(null)
84       .setRootId(null);
85
86     assertThat(characteristic.isRoot()).isTrue();
87   }
88
89   @Test
90   public void is_requirement() throws Exception {
91     DefaultCharacteristic requirement = new DefaultCharacteristic()
92       .setId(1)
93       .setRuleKey(RuleKey.of("repo", "rule"))
94       .setFunction("linear_offset")
95       .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
96       .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
97       .setRootId(3)
98       .setParentId(2);
99
100     assertThat(requirement.isRequirement()).isTrue();
101   }
102
103
104   @Test
105   public void test_equals() throws Exception {
106     assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE"));
107     assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isNotEqualTo(new DefaultCharacteristic().setKey("MAINTABILITY"));
108
109     assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule"))).isEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")));
110     assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule"))).isNotEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo2", "rule2")));
111   }
112
113   @Test
114   public void test_hascode() throws Exception {
115     assertThat(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode()).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode());
116     assertThat(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode()).isNotEqualTo(new DefaultCharacteristic().setKey("MAINTABILITY").hashCode());
117
118     assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode()).isEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode());
119     assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode()).isNotEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo2", "rule2")).hashCode());
120   }
121
122
123
124 }