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
Constructor and Description |
---|
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 |
isFinal()
Verifies that the actual
Class is final (has final modifier). |
S |
isInterface()
Verifies that the actual
Class is an interface. |
S |
isNotAnnotation()
Verifies that the actual
Class is not an annotation. |
S |
isNotFinal()
Verifies that the actual
Class is not final (does not have final modifier). |
S |
isNotInterface()
Verifies that the actual
Class is not an interface. |
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
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 Class
is null
.IllegalArgumentException
- if no others
classes have been specified.AssertionError
- if the actual Class
is not assignable from all of the others
classes.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 isFinal()
Class
is final (has final
modifier).
// These assertions succeed:
assertThat(String.class).isFinal();
assertThat(Math.class).isFinal();
// These assertions fail:
assertThat(Object.class).isFinal();
assertThat(Throwable.class).isFinal();
AssertionError
- if actual
is null
.AssertionError
- if the actual Class
is not final.public S isNotFinal()
Class
is not final (does not have final
modifier).
// These assertions succeed:
assertThat(Object.class).isNotFinal();
assertThat(Throwable.class).isNotFinal();
// These assertions fail:
assertThat(String.class).isNotFinal();
assertThat(Math.class).isNotFinal();
AssertionError
- if actual
is null
.AssertionError
- if the actual Class
is final.public S hasAnnotations(Class<? extends Annotation>... annotations)
Class
has the given Annotation
s.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
private static @interface Force { }
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
private static @interface Hero { }
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
private static @interface DarkSide { }
@Hero @Force
class Jedi implements Jedi {}
// Should pass:
assertThat(Jedi.class).containsAnnotations(Force.class, Hero.class);
// Should fail:
assertThat(Jedi.class).containsAnnotations(Force.class, DarkSide.class);
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
.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
private static @interface Force { }
@Force
class Jedi implements Jedi {}
// Should pass if :
assertThat(Jedi.class).containsAnnotation(Force.class);
// Should fail if :
assertThat(Jedi.class).containsAnnotation(DarkSide.class);
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 © 2014–2017 AssertJ. All rights reserved.