Package org.onlab.junit
Class ImmutableClassChecker
- java.lang.Object
-
- org.onlab.junit.ImmutableClassChecker
-
public class ImmutableClassChecker extends java.lang.ObjectHamcrest style class for verifying that a class follows the accepted rules for immutable classes. The rules that are enforced for immutable classes: - the class must be declared final - all data members of the class must be declared private and final - the class must not define any setter methods
-
-
Constructor Summary
Constructors Constructor Description ImmutableClassChecker()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidassertThatClassIsImmutable(java.lang.Class<?> clazz)Assert that the given class adheres to the immutable class rules.static voidassertThatClassIsImmutableBaseClass(java.lang.Class<?> clazz)Assert that the given class adheres to the immutable class rules, but is not declared final.voiddescribeMismatch(org.hamcrest.Description description)Describe why an error was reported.voiddescribeTo(org.hamcrest.Description description)Describe the source object that caused an error, using a Hamcrest Matcher style interface.
-
-
-
Method Detail
-
describeMismatch
public void describeMismatch(org.hamcrest.Description description)
Describe why an error was reported. Uses Hamcrest style Description interfaces.- Parameters:
description- the Description object to use for reporting the mismatch
-
describeTo
public void describeTo(org.hamcrest.Description description)
Describe the source object that caused an error, using a Hamcrest Matcher style interface. In this case, it always returns that we are looking for a properly defined utility class.- Parameters:
description- the Description object to use to report the "to" object
-
assertThatClassIsImmutable
public static void assertThatClassIsImmutable(java.lang.Class<?> clazz)
Assert that the given class adheres to the immutable class rules.- Parameters:
clazz- the class to check- Throws:
java.lang.AssertionError- if the class is not an immutable class
-
assertThatClassIsImmutableBaseClass
public static void assertThatClassIsImmutableBaseClass(java.lang.Class<?> clazz)
Assert that the given class adheres to the immutable class rules, but is not declared final. Classes that need to be inherited from cannot be declared final.- Parameters:
clazz- the class to check- Throws:
java.lang.AssertionError- if the class is not an immutable class
-
-