SELF - 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<SELF extends AbstractClassAssert<SELF>> extends AbstractAssert<SELF,Class<?>>
Classes.actual, info, myself, throwUnsupportedExceptionOnEquals| Constructor and Description |
|---|
AbstractClassAssert(Class<?> actual,
Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
SELF |
hasAnnotation(Class<? extends Annotation> annotation)
Verifies that the actual
Class has the given Annotation. |
SELF |
hasAnnotations(Class<? extends Annotation>... annotations)
Verifies that the actual
Class has the given Annotations. |
SELF |
hasDeclaredFields(String... fields)
Verifies that the actual
Class has the given declared fields (as in Class.getDeclaredFields()). |
SELF |
hasDeclaredMethods(String... methodNames)
Verifies that the actual
Class has the given declared methods. |
SELF |
hasFields(String... fields)
Deprecated.
use
hasPublicFields(String...) instead. |
SELF |
hasMethods(String... methodNames)
Verifies that the actual
Class has the given methods (including inherited) whatever their visibility are. |
SELF |
hasOnlyDeclaredFields(String... fields)
Verifies that the actual
Class only has the given declared fields and nothing more in any order
(as in Class.getDeclaredFields()). |
SELF |
hasOnlyPublicFields(String... fields)
Verifies that the actual
Class only has the given accessible public
fields (as in Class.getFields()) and nothing more in any order. |
SELF |
hasPublicFields(String... fields)
Verifies that the actual
Class has the given accessible public fields (as in Class.getFields()). |
SELF |
hasPublicMethods(String... methodNames)
Verifies that the actual
Class has the given public methods. |
SELF |
isAnnotation()
Verifies that the actual
Class is an annotation. |
SELF |
isAssignableFrom(Class<?>... others)
Verifies that the actual
Class is assignable from others Class |
SELF |
isFinal()
Verifies that the actual
Class is final (has final modifier). |
SELF |
isInterface()
Verifies that the actual
Class is an interface. |
SELF |
isNotAnnotation()
Verifies that the actual
Class is not an annotation. |
SELF |
isNotFinal()
Verifies that the actual
Class is not final (does not have final modifier). |
SELF |
isNotInterface()
Verifies that the actual
Class is not an interface. |
SELF |
isProtected()
Verifies that the actual
Class is protected (has protected modifier). |
SELF |
isPublic()
Verifies that the actual
Class is public (has public modifier). |
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, 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, newListAssertInstance, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnErrorpublic SELF isAssignableFrom(Class<?>... others)
Class is assignable from others Class
Example:
class Jedi {}
class HumanJedi extends Jedi {}
// this assertion succeeds:
assertThat(Jedi.class).isAssignableFrom(HumanJedi.class);
// this assertion fails:
assertThat(HumanJedi.class).isAssignableFrom(Jedi.class);others - Class who can be assignable from.this assertions objectAssertionError - 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 SELF isNotInterface()
Class is not an interface.
Example:
interface Jedi {}
class HumanJedi implements Jedi {}
// this assertion succeeds:
assertThat(HumanJedi.class).isNotInterface();
// this assertion fails:
assertThat(Jedi.class).isNotInterface();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is not an interface.public SELF isInterface()
Class is an interface.
Example:
interface Jedi {}
class HumanJedi implements Jedi {}
// this assertion succeeds:
assertThat(Jedi.class).isInterface();
// this assertion fails:
assertThat(HumanJedi.class).isInterface();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is not an interface.public SELF isAnnotation()
Class is an annotation.
Example:
public @interface Jedi {}
// these assertions succeed:
assertThat(Jedi.class).isAnnotation();
assertThat(Override.class).isAnnotation();
assertThat(Deprecated.class).isAnnotation();
// this assertion fails:
assertThat(String.class).isAnnotation();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is not an annotation.public SELF isNotAnnotation()
Class is not an annotation.
Example:
public @interface Jedi {}
// this assertion succeeds:
assertThat(String.class).isNotAnnotation();
// these assertions fail:
assertThat(Jedi.class).isNotAnnotation();
assertThat(Override.class).isNotAnnotation();
assertThat(Deprecated.class).isNotAnnotation();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is an annotation.public SELF isFinal()
Class is final (has final modifier).
Example:
// these assertions succeed:
assertThat(String.class).isFinal();
assertThat(Math.class).isFinal();
// these assertions fail:
assertThat(Object.class).isFinal();
assertThat(Throwable.class).isFinal();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is not final.public SELF isNotFinal()
Class is not final (does not have final modifier).
Example:
// these assertions succeed:
assertThat(Object.class).isNotFinal();
assertThat(Throwable.class).isNotFinal();
// these assertions fail:
assertThat(String.class).isNotFinal();
assertThat(Math.class).isNotFinal();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is final.public SELF isPublic()
Class is public (has public modifier).
Example:
protected class MyClass { }
// these assertions succeed:
assertThat(String.class).isPublic();
assertThat(Math.class).isPublic();
// This assertion fails:
assertThat(MyClass.class).isPublic();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is not public.public SELF isProtected()
Class is protected (has protected modifier).
Example:
public class MyClass { }
// this assertion succeeds:
assertThat(MyClass.class).isProtected();
// these assertions fail:
assertThat(String.class).isProtected();
assertThat(Math.class).isProtected();this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class is not protected.public SELF hasAnnotations(Class<? extends Annotation>... annotations)
Class has the given Annotations.
Example:
@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 {}
// this assertion succeeds:
assertThat(Jedi.class).containsAnnotations(Force.class, Hero.class);
// this assertion fails:
assertThat(Jedi.class).containsAnnotations(Force.class, DarkSide.class);annotations - annotations who must be attached to the classthis assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contains all of these annotations.public SELF hasAnnotation(Class<? extends Annotation> annotation)
Class has the given Annotation.
Example:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
private static @interface Force { }
@Force
class Jedi implements Jedi {}
// this assertion succeeds:
assertThat(Jedi.class).containsAnnotation(Force.class);
// this assertion fails:
assertThat(Jedi.class).containsAnnotation(DarkSide.class);annotation - annotations who must be attached to the classthis assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contains all of these annotations.@Deprecated public SELF hasFields(String... fields)
hasPublicFields(String...) instead.fields - the fields who must be in the class.this assertions objectpublic SELF hasPublicFields(String... fields)
Class has the given accessible public fields (as in Class.getFields()).
Example:
class MyClass {
public String fieldOne;
protected String fieldTwo;
String fieldThree;
private String fieldFour;
}
// this assertion succeeds:
assertThat(MyClass.class).hasPublicFields("fieldOne");
// these assertions fail:
assertThat(MyClass.class).hasPublicFields("fieldTwo");
assertThat(MyClass.class).hasPublicFields("fieldThree");
assertThat(MyClass.class).hasPublicFields("fieldFour");
assertThat(MyClass.class).hasPublicFields("unknownField");
The assertion succeeds if no given fields are passed and the actual Class has no accessible public fields.
fields - the fields who must be in the class.this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contain all of the fields.Class.getField(String)public SELF hasOnlyPublicFields(String... fields)
Class only has the given accessible public
fields (as in Class.getFields()) and nothing more in any order.
Example:
class MyClass {
public String fieldOne;
public String fieldTwo;
private String fieldThree;
}
// these assertions succeed:
assertThat(MyClass.class).hasOnlyPublicFields("fieldOne", "fieldTwo");
assertThat(MyClass.class).hasOnlyPublicFields("fieldTwo", "fieldOne");
// this assertion fails:
assertThat(MyClass.class).hasOnlyPublicFields("fieldOne");
The assertion succeeds if no given fields are passed and the actual Class has no accessible public fields.
fields - all the fields that are expected to be in the class.this assertions objectAssertionError - if actual is null.AssertionError - if fields are not all the actual Class's accessible public fields.Class.getField(String)public SELF hasDeclaredFields(String... fields)
Class has the given declared fields (as in Class.getDeclaredFields()).
Example:
class MyClass {
public String fieldOne;
private String fieldTwo;
}
// this assertion succeeds:
assertThat(MyClass.class).hasDeclaredFields("fieldOne", "fieldTwo");
// this assertion fails:
assertThat(MyClass.class).hasDeclaredFields("fieldThree");
The assertion succeeds if no given fields are passed and the actual Class has no declared fields.
fields - the fields who must be declared in the class.this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contains all of the field.Class.getDeclaredField(String)public SELF hasOnlyDeclaredFields(String... fields)
Class only has the given declared fields and nothing more in any order
(as in Class.getDeclaredFields()).
Example:
class MyClass {
public String fieldOne;
public String fieldTwo;
private String fieldThree;
private String fieldFour;
}
// this assertion succeeds:
assertThat(MyClass.class).hasOnlyDeclaredFields("fieldOne", "fieldTwo", "fieldThree", "fieldFour");
// this assertion fails:
assertThat(MyClass.class).hasOnlyDeclaredFields("fieldOne", "fieldThree");
The assertion succeeds if no given fields are passed and the actual Class has no declared fields.
fields - all the fields that are expected to be in the class.this assertions objectAssertionError - if actual is null.AssertionError - if fields are not all the declared fields of the actual Class.Class.getField(String)public SELF hasMethods(String... methodNames)
Class has the given methods (including inherited) whatever their visibility are.
Example:
class MySuperClass {
public void superMethod() {}
private void privateSuperMethod() {}
}
class MyClass extends MySuperClass {
public void methodOne() {}
private void methodTwo() {}
}
// this assertion succeeds:
assertThat(MyClass.class).hasMethods("methodOne", "methodTwo", "superMethod", "privateSuperMethod");
// this assertion fails:
assertThat(MyClass.class).hasMethods("methodThree");methodNames - the method names which must be in the class.this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contains all of the method names.public SELF hasDeclaredMethods(String... methodNames)
Class has the given declared methods.
Example:
class MySuperClass {
public void superMethod() {}
}
class MyClass extends MySuperClass {
public void methodOne() {}
private void methodTwo() {}
}
// This assertion succeeds:
assertThat(MyClass.class).hasDeclaredMethods("methodOne", "methodTwo");
// these assertions fail:
assertThat(MyClass.class).hasDeclaredMethods("superMethod");
assertThat(MyClass.class).hasDeclaredMethods("methodThree");
The assertion succeeds if no given methods are passed and the actual Class has no declared methods.
methodNames - the method names which must be declared in the class.this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contains all of the given methods.public SELF hasPublicMethods(String... methodNames)
Class has the given public methods.
Example:
class MyClass {
public void methodOne() {}
public void methodTwo() {}
protected void methodThree() {}
}
// these assertions succeed:
assertThat(MyClass.class).hasPublicMethods("methodOne");
assertThat(MyClass.class).hasPublicMethods("methodOne", "methodTwo");
// these assertions fail:
assertThat(MyClass.class).hasPublicMethods("methodOne", "methodThree");
assertThat(MyClass.class).hasPublicMethods("methodThree");methodNames - the public method names which must be in the class.this assertions objectAssertionError - if actual is null.AssertionError - if the actual Class doesn't contains all of the given public methods.Copyright © 2014–2018 AssertJ. All rights reserved.