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