S
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.public abstract class AbstractClassAssert<S extends AbstractClassAssert<S>> extends AbstractAssert<S,Class<?>>
Class
es.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractClassAssert(Class<?> actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
hasAnnotation(Class<? extends Annotation> annotation)
Verifies that the actual
Class has the given Annotation . |
S |
hasAnnotations(Class<? extends Annotation>... annotations)
Verifies that the actual
Class has the given Annotation s. |
S |
hasDeclaredFields(String... fields)
Verifies that the actual
Class has the declared fields . |
S |
hasFields(String... fields)
Verifies that the actual
Class has the fields . |
S |
isAnnotation()
Verifies that the actual
Class is an annotation. |
S |
isAssignableFrom(Class<?>... others)
Verifies that the actual
Class is assignable from others Class |
S |
isInterface()
Verifies that the actual
Class is an interface. |
S |
isNotAnnotation()
Verifies that the actual
Class is not an annotation. |
S |
isNotInterface()
Verifies that the actual
Class is not an interface. |
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
public S isAssignableFrom(Class<?>... others)
Class
is assignable from others Class
class Jedi {} class HumanJedi extends Jedi {} Should pass if : assertThat(Jedi.class).isAssignableFrom(HumanJedi.class); Should fail if : assertThat(HumanJedi.class).isAssignableFrom(Jedi.class);
others
- Class
who can be assignable from.AssertionError
- if the actual Date
is null
.NullPointerException
- if other Date
is null
.AssertionError
- if the actual Date
is not before or equals to the given one.Class.isAssignableFrom(Class)
public S isNotInterface()
Class
is not an interface.
interface Jedi {} class HumanJedi implements Jedi {} Should pass if : assertThat(HumanJedi.class).isNotInterface(); Should fail if : assertThat(Jedi.class).isNotInterface();
AssertionError
- if actual
is null
.AssertionError
- if the actual Class
is not an interface.public S isInterface()
Class
is an interface.
interface Jedi {} class HumanJedi implements Jedi {} Should pass if : assertThat(Jedi.class).isInterface(); Should fail if : assertThat(HumanJedi.class).isInterface();
AssertionError
- if actual
is null
.AssertionError
- if the actual Class
is not an interface.public S isAnnotation()
Class
is an annotation.
public @interface Jedi {} Should pass if : assertThat(Jedi.class).isAnnotation(); assertThat(Override.class).isAnnotation(); assertThat(Deprecated.class).isAnnotation(); Should fail if : assertThat(String.class).isAnnotation();
AssertionError
- if actual
is null
.AssertionError
- if the actual Class
is not an annotation.public S isNotAnnotation()
Class
is not an annotation.
public @interface Jedi {} Should pass if : assertThat(String.class).isNotAnnotation(); Should fail if : assertThat(Jedi.class).isNotAnnotation(); assertThat(Override.class).isNotAnnotation(); assertThat(Deprecated.class).isNotAnnotation();
AssertionError
- if actual
is null
.AssertionError
- if the actual Class
is an annotation.public S hasAnnotations(Class<? extends Annotation>... annotations)
Class
has the given Annotation
s.
annotations
- annotations who must be attached to the classAssertionError
- if actual
is null
.AssertionError
- if the actual Class
doesn't contains all of these annotations.public S hasAnnotation(Class<? extends Annotation> annotation)
Class
has the given Annotation
.
annotation
- annotations who must be attached to the classAssertionError
- if actual
is null
.AssertionError
- if the actual Class
doesn't contains all of these annotations.public S hasFields(String... fields)
Class
has the fields
.
class MyClass { public String fieldOne; private String fieldTwo; } This one should pass : assertThat(MyClass.class).hasFields("fieldOne"); This one should fail : assertThat(MyClass.class).hasFields("fieldTwo"); assertThat(MyClass.class).hasDeclaredFields("fieldThree");
fields
- the fields who must be in the class.AssertionError
- if actual
is null
.AssertionError
- if the actual Class
doesn't contains all of the field.Class.getField(String)
public S hasDeclaredFields(String... fields)
Class
has the declared fields
.
class MyClass { public String fieldOne; private String fieldTwo; } This one should pass : assertThat(MyClass.class).hasDeclaredFields("fieldOne", "fieldTwo"); This one should fail : assertThat(MyClass.class).hasDeclaredFields("fieldThree");
fields
- the fields who must be declared in the class.AssertionError
- if actual
is null
.AssertionError
- if the actual Class
doesn't contains all of the field.Class.getDeclaredField(String)
Copyright © 2013 AssertJ. All Rights Reserved.