public class InstantiationNotAllowedMatcher extends org.hamcrest.TypeSafeDiagnosingMatcher<Class<?>>
First, the matcher verifies that all declared constructors are private, then it tries to produce a new instance using the default constructor, via Reflection.
A matching class should have all constructors declared as private and
throw an exception, so the class will never be instantiated.
For example:
private MyClass()
{
throw new UnsupportedOperationException("Instantiation not allowed");
}
| Constructor and Description |
|---|
InstantiationNotAllowedMatcher() |
| Modifier and Type | Method and Description |
|---|---|
void |
describeTo(org.hamcrest.Description description)
Describes the "expected" pat of the test description.
|
static org.hamcrest.Matcher<Class<?>> |
instantiationNotAllowed()
Creates a matcher that matches if the examined class cannot be instantiated, which is
particularly useful for utility classes.
|
public static org.hamcrest.Matcher<Class<?>> instantiationNotAllowed()
For example:
assertThat(TestUtils.class, instantiationNotAllowed())
public void describeTo(org.hamcrest.Description description)
SelfDescribing.describeTo(Description)Copyright © 2020. All rights reserved.