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.batch.internal;
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;
28 import java.text.SimpleDateFormat;
30 import static org.fest.assertions.Assertions.assertThat;
32 public class DefaultRequirementTest {
35 public void test_setters_and_getters_for_characteristic() throws Exception {
36 DefaultCharacteristic root = new DefaultCharacteristic().setId(1).setKey("REUSABILITY");
38 DefaultCharacteristic characteristic = new DefaultCharacteristic()
41 .setName("Modularity")
45 DefaultRequirement requirement = new DefaultRequirement()
47 .setRuleKey(RuleKey.of("repo", "rule"))
48 .setCharacteristic(characteristic)
49 .setRootCharacteristic(root)
50 .setFunction("linear_offset")
52 .setFactorUnit(WorkDuration.UNIT.MINUTES)
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"));
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"));
74 public void test_equals() throws Exception {
75 DefaultCharacteristic characteristic = new DefaultCharacteristic()
77 .setKey("MODULARITY");
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));
84 assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
85 .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(
86 new DefaultCharacteristic()
88 .setKey("REUSABILITY")));
93 public void test_hascode() throws Exception {
94 DefaultCharacteristic characteristic = new DefaultCharacteristic()
97 .setName("Modularity")
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());