]> source.dussan.org Git - sonarqube.git/blob
918b5918f183a921996ca02b31e42ab2d1d959ef
[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.batch.internal;
22
23 import org.junit.Test;
24 import org.sonar.api.rule.RuleKey;
25 import org.sonar.api.utils.WorkUnit;
26
27 import java.text.SimpleDateFormat;
28
29 import static org.fest.assertions.Assertions.assertThat;
30
31 public class DefaultRequirementTest {
32
33   @Test
34   public void test_setters_and_getters_for_characteristic() throws Exception {
35     DefaultCharacteristic root = new DefaultCharacteristic().setId(1).setKey("REUSABILITY");
36
37     DefaultCharacteristic characteristic = new DefaultCharacteristic()
38       .setId(1)
39       .setKey("MODULARITY")
40       .setName("Modularity")
41       .setParent(root)
42       .setRoot(root);
43
44     DefaultRequirement requirement = new DefaultRequirement()
45       .setId(3)
46       .setRuleKey(RuleKey.of("repo", "rule"))
47       .setCharacteristic(characteristic)
48       .setRootCharacteristic(root)
49       .setFunction("linear_offset")
50       .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
51       .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
52       .setCreatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"))
53       .setUpdatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
54
55     assertThat(requirement.id()).isEqualTo(3);
56     assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
57     assertThat(requirement.characteristic()).isEqualTo(characteristic);
58     assertThat(requirement.rootCharacteristic()).isEqualTo(root);
59     assertThat(requirement.function()).isEqualTo("linear_offset");
60     assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
61     assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
62     assertThat(requirement.createdAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
63     assertThat(requirement.updatedAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
64   }
65
66   @Test
67   public void test_equals() throws Exception {
68     DefaultCharacteristic characteristic = new DefaultCharacteristic()
69       .setId(1)
70       .setKey("MODULARITY");
71
72     assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
73       .isEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic));
74     assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
75       .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo2", "rule2")).setCharacteristic(characteristic));
76
77     assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
78       .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(
79         new DefaultCharacteristic()
80           .setId(2)
81           .setKey("REUSABILITY")));
82
83   }
84
85   @Test
86   public void test_hascode() throws Exception {
87     DefaultCharacteristic characteristic = new DefaultCharacteristic()
88       .setId(1)
89       .setKey("MODULARITY")
90       .setName("Modularity")
91       .setOrder(5);
92
93     assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode())
94       .isEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode());
95     assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode())
96       .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo2", "rule2")).setCharacteristic(characteristic).hashCode());
97   }
98 }