2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
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.
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.
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.
21 package org.sonar.api.technicaldebt.server.internal;
23 import org.junit.Test;
24 import org.sonar.api.rule.RuleKey;
25 import org.sonar.api.utils.WorkUnit;
27 import static org.fest.assertions.Assertions.assertThat;
29 public class DefaultCharacteristicTest {
32 public void test_setters_and_getters_for_characteristic() throws Exception {
33 DefaultCharacteristic characteristic = new DefaultCharacteristic()
35 .setKey("NETWORK_USE")
36 .setName("Network use")
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);
54 public void test_setters_and_getters_for_requirement() throws Exception {
55 DefaultCharacteristic requirement = new DefaultCharacteristic()
57 .setRuleKey(RuleKey.of("repo", "rule"))
58 .setFunction("linear_offset")
59 .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
60 .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
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);
77 public void is_root() throws Exception {
78 DefaultCharacteristic characteristic = new DefaultCharacteristic()
80 .setKey("NETWORK_USE")
81 .setName("Network use")
86 assertThat(characteristic.isRoot()).isTrue();
90 public void is_requirement() throws Exception {
91 DefaultCharacteristic requirement = new DefaultCharacteristic()
93 .setRuleKey(RuleKey.of("repo", "rule"))
94 .setFunction("linear_offset")
95 .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
96 .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
100 assertThat(requirement.isRequirement()).isTrue();
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"));
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")));
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());
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());