...
Code Block |
---|
language | java |
---|
title | Using EqualsTester |
---|
|
final FlowId flowId1 = FlowId.valueOf(1);
final FlowId sameAsFlowId1 = FlowId.valueOf(1);
final FlowId flowId2 = FlowId.valueOf(2);
/**
* Checks the operation of equals(), hashCode() and toString() methods.
*/
@Test
public void testEquals() {
new EqualsTester()
.addEqualityGroup(flowId1, sameAsFlowId1)
.addEqualityGroup(flowId2)
.testEquals();
} |
Testing immutable classes and utility classes
Utility test methods are provided to
...
check that classes are properly defined immutable classes, immutable base classes or utility classes. Using these methods will assure that other developers don't make changes to your classes that violate your assumptions.
Immutable Classes
Code Block |
---|
language | java |
---|
title | Immutable Class Check |
---|
|
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Checks that the FlowId class is immutable.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(FlowId.class);
} |
Immutable Base Classes
Code Block |
---|
language | java |
---|
title | Immutable Base Class Check |
---|
|
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
/**
* Checks that the DefaultFlowRule class is immutable but can be inherited
* from.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutableBaseClass(DefaultFlowRule.class);
} |
Utility Classes
Code Block |
---|
language | java |
---|
title | Utility Class Check |
---|
|
import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
/**
* Check that the Criteria class is a valid utility class.
*/
@Test
public void testCriteriaUtility() {
assertThatClassIsUtility(Criteria.class);
} |
...