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.WorkUnit;
27 import java.text.SimpleDateFormat;
29 import static org.fest.assertions.Assertions.assertThat;
31 public class DefaultRequirementTest {
34 public void test_setters_and_getters_for_characteristic() throws Exception {
35 DefaultCharacteristic root = new DefaultCharacteristic().setId(1).setKey("REUSABILITY");
37 DefaultCharacteristic characteristic = new DefaultCharacteristic()
40 .setName("Modularity")
44 DefaultRequirement requirement = new DefaultRequirement()
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"));
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"));
67 public void test_equals() throws Exception {
68 DefaultCharacteristic characteristic = new DefaultCharacteristic()
70 .setKey("MODULARITY");
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));
77 assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
78 .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(
79 new DefaultCharacteristic()
81 .setKey("REUSABILITY")));
86 public void test_hascode() throws Exception {
87 DefaultCharacteristic characteristic = new DefaultCharacteristic()
90 .setName("Modularity")
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());