builder:RuleTest: added

Rule:

* remove redundant @ToString
* prevent creation of setProperties()
This commit is contained in:
Paul Campbell 2017-01-07 18:16:02 +00:00
parent 9b3f0869ea
commit 53586a7ffd
2 changed files with 80 additions and 3 deletions

View file

@ -26,7 +26,6 @@ package net.kemitix.checkstyle.ruleset.builder;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import java.net.URI; import java.net.URI;
import java.util.HashMap; import java.util.HashMap;
@ -37,7 +36,6 @@ import java.util.Map;
* *
* @author Paul Campbell (pcampbell@kemitix.net) * @author Paul Campbell (pcampbell@kemitix.net)
*/ */
@ToString
@Setter @Setter
@Getter @Getter
public class Rule { public class Rule {
@ -85,5 +83,5 @@ public class Rule {
/** /**
* Configuration properties. * Configuration properties.
*/ */
private Map<String, String> properties = new HashMap<>(); private final Map<String, String> properties = new HashMap<>();
} }

View file

@ -0,0 +1,79 @@
package net.kemitix.checkstyle.ruleset.builder;
import lombok.val;
import org.assertj.core.api.SoftAssertions;
import org.junit.Before;
import org.junit.Test;
import java.net.URI;
/**
* Tests for {@link Rule}.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
public class RuleTest {
private Rule rule;
@Before
public void setUp() throws Exception {
rule = new Rule();
}
@Test
public void setAndGet() throws Exception {
//given
val name = "name";
val parent = RuleParent.TREEWALKER;
val level = RuleLevel.LAYOUT;
val source = RuleSource.CHECKSTYLE;
val enabled = true;
val insuppressible = true;
val uri = URI.create("rule://name.md");
val reason = "reason";
val key = "key";
val value = "value";
//when
rule.setName(name);
rule.setParent(parent);
rule.setLevel(level);
rule.setSource(source);
rule.setEnabled(enabled);
rule.setInsuppressible(insuppressible);
rule.setUri(uri);
rule.setReason(reason);
rule.getProperties()
.put(key, value);
//then
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(rule.getName())
.as("set/getName()")
.isEqualTo(name);
softly.assertThat(rule.getParent())
.as("set/getParent()")
.isEqualTo(parent);
softly.assertThat(rule.getLevel())
.as("set/getLevel()")
.isEqualTo(level);
softly.assertThat(rule.getSource())
.as("set/getSource()")
.isEqualTo(source);
softly.assertThat(rule.isEnabled())
.as("set/isEnabled()")
.isEqualTo(enabled);
softly.assertThat(rule.isInsuppressible())
.as("set/isInsuppressible()")
.isEqualTo(insuppressible);
softly.assertThat(rule.getUri())
.as("set/getUri()")
.isEqualTo(uri);
softly.assertThat(rule.getReason())
.as("set/getReason()")
.isEqualTo(reason);
softly.assertThat(rule.getProperties())
.as("getProperties()")
.containsEntry(key, value);
});
}
}