Class AbstractClassAssert<SELF extends AbstractClassAssert<SELF>>
- Type Parameters:
SELF- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
- All Implemented Interfaces:
Assert<SELF,,Class<?>> Descriptable<SELF>,ExtensionPoints<SELF,Class<?>>
- Direct Known Subclasses:
ClassAssert
Classes.- Author:
- William Delanoue, Mikhail Mazursky
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionhasAnnotation(Class<? extends Annotation> annotation) Verifies that the actualClasshas the givenAnnotation.final SELFhasAnnotations(Class<? extends Annotation>... annotations) Verifies that the actualClasshas the givenAnnotations.protected SELFhasAnnotationsForProxy(Class<? extends Annotation>[] annotations) hasDeclaredFields(String... fields) Verifies that the actualClasshas the given declared fields (as inClass.getDeclaredFields()).hasDeclaredMethods(String... methodNames) Verifies that the actualClasshas the given declared methods.Deprecated.hasMethods(String... methodNames) Verifies that the actualClasshas the given methods (including inherited) whatever their visibility are.Verifies that the actualClasshas no superclass (as inClass.getSuperclass(), whennullis returned).hasOnlyDeclaredFields(String... fields) Verifies that the actualClassonly has the given declaredfieldsand nothing more in any order (as inClass.getDeclaredFields()).hasOnlyPublicFields(String... fields) Verifies that the actualClassonly has the given accessible public fields (as inClass.getFields()) and nothing more in any order.hasPackage(Package expected) Verifies that the actualClasshas the given package (as inClass.getPackage()).hasPackage(String expected) Verifies that the actualClasshas the given package name (as inClass.getPackage()).hasPermittedSubclasses(Class<?>... permittedSubclasses) Verifies that the actualClasspermitted subclasses contains the given classes.hasPublicFields(String... fields) Verifies that the actualClasshas the given accessible public fields (as inClass.getFields()).hasPublicMethods(String... methodNames) Verifies that the actualClasshas the given public methods.hasRecordComponents(String first, String... rest) Verifies that the actualClasshas the given record componentshasSuperclass(Class<?> superclass) Verifies that the actualClasshas the given class as direct superclass (as inClass.getSuperclass()).Verifies that the actualClassis abstract (hasabstractmodifier).Verifies that the actualClassis an annotation.isAssignableFrom(Class<?>... others) Verifies that the actualClassis assignable from othersClassisAssignableTo(Class<?> other) Verifies that theClassunder test is assignable to the givenClass.isFinal()Verifies that the actualClassis final (hasfinalmodifier).Verifies that the actualClassis an interface.Verifies that the actualClassis not an annotation.Verifies that the actualClassis not final (does not havefinalmodifier).Verifies that the actualClassis not an interface.Verifies that the actualClassis not a primitive type.Verifies that the actualClassis not a record.Verifies that the actualClassis not sealed.Verifies that the actualClassis not static (does not havestaticmodifier).Verifies that the actualClassis package-private (i.e., has no explicit access level modifier).Verifies that the actualClassis a primitive type.Verifies that the actualClassis private (hasprivatemodifier).Verifies that the actualClassis protected (hasprotectedmodifier).isPublic()Verifies that the actualClassis public (haspublicmodifier).isRecord()Verifies that the actualClassis a record.isSealed()Verifies that the actualClassis sealed.isStatic()Verifies that the actualClassis static (hasstaticmodifier).Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Constructor Details
-
AbstractClassAssert
-
-
Method Details
-
isAssignableFrom
Verifies that the actualClassis assignable from othersClassExample:
class Jedi {} class HumanJedi extends Jedi {} // this assertion succeeds: assertThat(Jedi.class).isAssignableFrom(HumanJedi.class); // this assertion fails: assertThat(HumanJedi.class).isAssignableFrom(Jedi.class);- Parameters:
others-Classwho can be assignable from.- Returns:
thisassertions object- Throws:
AssertionError- if the actualClassisnull.IllegalArgumentException- if noothersclasses have been specified.AssertionError- if the actualClassis not assignable from all of theothersclasses.- See Also:
-
isAssignableTo
Verifies that theClassunder test is assignable to the givenClass.Example:
class Jedi {} class HumanJedi extends Jedi {} // this assertion succeeds: assertThat(HumanJedi.class).isAssignableTo(Jedi.class); // this assertion fails assertThat(Jedi.class).isAssignableTo(HumanJedi.class);- Parameters:
other-Classwho can be assignable to.- Returns:
thisassertions object- Throws:
AssertionError- if the actualClassisnull.IllegalArgumentException- ifotheris null.AssertionError- if the actualClassis not assignable to theothersclass.- Since:
- 3.24.0
- See Also:
-
isNotInterface
Verifies that the actualClassis not an interface.Example:
interface Jedi {} class HumanJedi implements Jedi {} // this assertion succeeds: assertThat(HumanJedi.class).isNotInterface(); // this assertion fails: assertThat(Jedi.class).isNotInterface();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not an interface.
-
isInterface
Verifies that the actualClassis an interface.Example:
interface Jedi {} class HumanJedi implements Jedi {} // this assertion succeeds: assertThat(Jedi.class).isInterface(); // this assertion fails: assertThat(HumanJedi.class).isInterface();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not an interface.
-
isAbstract
Verifies that the actualClassis abstract (hasabstractmodifier).Example:
public abstract class MyClass { } // this assertion succeeds: assertThat(MyClass.class).isAbstract(); // this assertion fails: assertThat(String.class).isAbstract();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not abstract.- Since:
- 3.12.0
-
isAnnotation
Verifies that the actualClassis 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();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not an annotation.
-
isNotAnnotation
Verifies that the actualClassis 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();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis an annotation.
-
isRecord
Verifies that the actualClassis a record.Example:
public record Jedi(String name) {} // this assertion succeeds: assertThat(Jedi.class).isRecord(); // this assertion fails: assertThat(String.class).isRecord();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not a record.- Since:
- 3.25.0
-
isNotRecord
Verifies that the actualClassis not a record.Example:
public record Jedi(String name) {} // this assertion succeeds: assertThat(String.class).isNotRecord(); // this assertion fails: assertThat(Jedi.class).isNotRecord();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis a record.- Since:
- 3.25.0
-
hasRecordComponents
Verifies that the actualClasshas the given record componentsExample:
public class NotARecord {} public record MyRecord(String componentOne, String componentTwo) {} // these assertions succeed: assertThat(MyRecord.class).hasRecordComponents("componentOne"); assertThat(MyRecord.class).hasRecordComponents("componentOne", "componentTwo"); // these assertions fail: assertThat(NotARecord.class).hasRecordComponents("componentOne"); assertThat(MyRecord.class).hasRecordComponents("componentOne", "unknownComponent");- Parameters:
first- the first record component name which must be in this classrest- the remaining record component names which must be in this class- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not a record.AssertionError- if the actualClassdoesn't contain all the record component names.- Since:
- 3.25.0
-
isFinal
Verifies that the actualClassis final (hasfinalmodifier).Example:
// these assertions succeed: assertThat(String.class).isFinal(); assertThat(Math.class).isFinal(); // these assertions fail: assertThat(Object.class).isFinal(); assertThat(Throwable.class).isFinal();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not final.
-
isNotFinal
Verifies that the actualClassis not final (does not havefinalmodifier).Example:
// these assertions succeed: assertThat(Object.class).isNotFinal(); assertThat(Throwable.class).isNotFinal(); // these assertions fail: assertThat(String.class).isNotFinal(); assertThat(Math.class).isNotFinal();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis final.
-
isPublic
Verifies that the actualClassis public (haspublicmodifier).Example:
protected class MyClass { } // these assertions succeed: assertThat(String.class).isPublic(); assertThat(Math.class).isPublic(); // This assertion fails: assertThat(MyClass.class).isPublic();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not public.- Since:
- 2.7.0 / 3.7.0
-
isProtected
Verifies that the actualClassis protected (hasprotectedmodifier).Example:
public class MyClass { } // this assertion succeeds: assertThat(MyClass.class).isProtected(); // these assertions fail: assertThat(String.class).isProtected(); assertThat(Math.class).isProtected();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not protected.- Since:
- 2.7.0 / 3.7.0
-
isPackagePrivate
Verifies that the actualClassis package-private (i.e., has no explicit access level modifier).Example:
class MyClass { } // this assertion succeeds: assertThat(MyClass.class).isPackagePrivate(); // these assertions fail: assertThat(String.class).isPackagePrivate(); assertThat(Math.class).isPackagePrivate();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not package-private.- Since:
- 3.15.0
-
isPrivate
Verifies that the actualClassis private (hasprivatemodifier).Example:
class EnclosingClass { private static class PrivateClass { } } // these assertions succeed: assertThat(PrivateClass.class).isPrivate(); assertThat(Class.forName(EnclosingClass.class.getName() + "$PrivateClass")).isPrivate(); // This assertion fails: assertThat(String.class).isPrivate();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not private.- Since:
- 3.26.0
-
isStatic
Verifies that the actualClassis static (hasstaticmodifier).Example:
class OuterClass { static class StaticNestedClass { } } // this assertion succeeds: assertThat(OuterClass.StaticNestedClass.class).isStatic(); // these assertions fail: assertThat(Object.class).isStatic(); assertThat(Throwable.class).isStatic();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not static.- Since:
- 3.23.0
-
isNotStatic
Verifies that the actualClassis not static (does not havestaticmodifier).Example:
// these assertions succeed: assertThat(Object.class).isNotStatic(); assertThat(Throwable.class).isNotStatic(); class OuterClass { static class StaticNestedClass { } } // this assertion fails: assertThat(OuterClass.StaticNestedClass.class).isNotStatic();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis static.- Since:
- 3.23.0
-
hasAnnotations
Verifies that the actualClasshas the givenAnnotations.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);- Parameters:
annotations- annotations who must be attached to the class- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contains all of these annotations.
-
hasAnnotationsForProxy
-
hasAnnotation
Verifies that the actualClasshas the givenAnnotation.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);- Parameters:
annotation- annotations who must be attached to the class- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contains all of these annotations.
-
hasSuperclass
Verifies that the actualClasshas the given class as direct superclass (as inClass.getSuperclass()).The expected
superclassshould always be notnull. To verify the absence of the superclass, usehasNoSuperclass().Example:
// this assertion succeeds: assertThat(Integer.class).hasSuperclass(Number.class); // this assertion succeeds as superclass for array classes is Object: assertThat(Integer[].class).hasSuperclass(Object.class); // this assertion fails: assertThat(String.class).hasSuperclass(Number.class); // this assertion fails as only direct superclass matches: assertThat(String.class).hasSuperclass(Object.class); // this assertion fails as interfaces are not superclasses: assertThat(String.class).hasSuperclass(Comparable.class);- Parameters:
superclass- the class which must be the direct superclass of actual.- Returns:
thisassertions object- Throws:
NullPointerException- ifsuperclassisnull.AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't have the given class as direct superclass.- Since:
- 3.15.0
- See Also:
-
hasNoSuperclass
Verifies that the actualClasshas no superclass (as inClass.getSuperclass(), whennullis returned).Example:
// this assertion succeeds as Object has no superclass: assertThat(Object.class).hasNoSuperclass(); // this assertion succeeds as interfaces have no superclass: assertThat(Cloneable.class).hasNoSuperclass(); // this assertion succeeds as primitive types have no superclass: assertThat(Integer.TYPE).hasNoSuperclass(); // this assertion succeeds as void type has no superclass: assertThat(Void.TYPE).hasNoSuperclass(); // this assertion fails as Integer has Number as superclass: assertThat(Integer.class).hasNoSuperclass();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClasshas a superclass.- Since:
- 3.15.0
- See Also:
-
hasFields
Deprecated.usehasPublicFields(String...)instead.- Parameters:
fields- the fields who must be in the class.- Returns:
thisassertions object
-
hasPublicFields
Verifies that the actualClasshas the given accessible public fields (as inClass.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
Classhas no accessible public fields.- Parameters:
fields- the fields who must be in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contain all of the fields.- See Also:
-
hasOnlyPublicFields
Verifies that the actualClassonly has the given accessible public fields (as inClass.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
Classhas no accessible public fields.- Parameters:
fields- all the fields that are expected to be in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if fields are not all the actualClass's accessible public fields.- Since:
- 2.7.0 / 3.7.0
- See Also:
-
hasDeclaredFields
Verifies that the actualClasshas the given declared fields (as inClass.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
Classhas no declared fields.- Parameters:
fields- the fields who must be declared in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contains all of the field.- See Also:
-
hasOnlyDeclaredFields
Verifies that the actualClassonly has the given declaredfieldsand nothing more in any order (as inClass.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
Classhas no declared fields.- Parameters:
fields- all the fields that are expected to be in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if fields are not all the declared fields of the actualClass.- Since:
- 2.7.0 / 3.7.0
- See Also:
-
hasMethods
Verifies that the actualClasshas 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");- Parameters:
methodNames- the method names which must be in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contains all of the method names.- Since:
- 2.7.0 / 3.7.0
-
hasDeclaredMethods
Verifies that the actualClasshas 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
Classhas no declared methods.- Parameters:
methodNames- the method names which must be declared in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contains all of the given methods.- Since:
- 2.7.0 / 3.7.0
-
hasPublicMethods
Verifies that the actualClasshas 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");- Parameters:
methodNames- the public method names which must be in the class.- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoesn't contains all of the given public methods.- Since:
- 2.7.0 / 3.7.0
-
hasPackage
Verifies that the actualClasshas the given package name (as inClass.getPackage()).The expected package name should always be not
null. To verify the absence of the package, usehasNoPackage().Example:
package one.two; class MyClass {} // this assertions succeeds: assertThat(MyClass.class).hasPackage("one.two"); // these assertions fail: assertThat(MyClass.class).hasPackage("one"); assertThat(MyClass.class).hasPackage(""); assertThat(MyClass.class).hasPackage("java.lang");- Parameters:
expected- the package name the class should have- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoes not have the given package.- Since:
- 3.18.0
-
hasPackage
Verifies that the actualClasshas the given package (as inClass.getPackage()).The expected package should always be not
null. To verify the absence of the package, usehasNoPackage().Example:
package one.two; class MyClass {} // these assertions succeed: assertThat(MyClass.class).hasPackage(Package.getPackage("one.two")); assertThat(MyClass.class).hasPackage(MyClass.class.getPackage()); // these assertions fail: assertThat(MyClass.class).hasPackage(Package.getPackage("one")); assertThat(MyClass.class).hasPackage(Package.getPackage("")); assertThat(MyClass.class).hasPackage(Object.class.getPackage());- Parameters:
expected- the package the class should have- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoes not have the given package.- Since:
- 3.18.0
- See Also:
-
hasNoPackage
Verifies that the actualClasshas no package (as inClass.getPackage(), whennullis returned).Example:
// this assertion succeeds as arrays have no package: assertThat(int[].class).hasNoPackage(); // this assertion succeeds as primitive types have no package: assertThat(Integer.TYPE).hasNoPackage(); // this assertion succeeds as void type has no package: assertThat(Void.TYPE).hasNoPackage(); // this assertion fails as Object has java.lang as package: assertThat(Object.class).hasNoPackage();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClasshas a package.- Since:
- 3.25.0
- See Also:
-
isSealed
Verifies that the actualClassis sealed.Example:
sealed class SealedClass permits NonSealedClass {} non-sealed class NonSealedClass extends SealedClass {} // this assertion succeeds: assertThat(SealedClass.class).isSealed(); // this assertion fails: assertThat(NonSealedClass.class).isSealed();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not sealed.- Since:
- 3.25.0
-
isNotSealed
Verifies that the actualClassis not sealed.Example:
sealed class SealedClass permits NonSealedClass {} non-sealed class NonSealedClass extends SealedClass {} // this assertion succeeds: assertThat(NonSealedClass.class).isNotSealed(); // this assertion fails: assertThat(SealedClass.class).isNotSealed();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis sealed.- Since:
- 3.25.0
-
hasPermittedSubclasses
Verifies that the actualClasspermitted subclasses contains the given classes.Example:
sealed class SealedClass permits NonSealedClass, FinalClass {} non-sealed class NonSealedClass extends SealedClass {} final class FinalClass extends SealedClass {} // these assertions succeed: assertThat(SealedClass.class).hasPermittedSubclasses(NonSealedClass.class) .hasPermittedSubclasses(FinalClass.class) .hasPermittedSubclasses(NonSealedClass.class, FinalClass.class) .hasPermittedSubclasses(); // these assertions fail: assertThat(SealedClass.class).hasPermittedSubclasses(String.class); assertThat(SealedClass.class).hasPermittedSubclasses(FinalClass.class, String.class);- Parameters:
permittedSubclasses- classes that must be permitted subclasses of the given class- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassdoes not have all of given permitted subclasses
-
isPrimitive
Verifies that the actualClassis a primitive type.Example:
// these assertions succeed: assertThat(byte.class).isPrimitive(); assertThat(short.class).isPrimitive(); assertThat(int.class).isPrimitive(); assertThat(long.class).isPrimitive(); assertThat(float.class).isPrimitive(); assertThat(double.class).isPrimitive(); assertThat(boolean.class).isPrimitive(); assertThat(char.class).isPrimitive(); // this assertion fails as Object is not a primitive type: assertThat(Object.class).isPrimitive();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis not a primitive type.- See Also:
-
isNotPrimitive
Verifies that the actualClassis not a primitive type.Example:
// this assertion succeeds as Object is not a primitive type: assertThat(Object.class).isNotPrimitive(); // these assertions fail: assertThat(byte.class).isNotPrimitive(); assertThat(short.class).isNotPrimitive(); assertThat(int.class).isNotPrimitive(); assertThat(long.class).isNotPrimitive(); assertThat(float.class).isNotPrimitive(); assertThat(double.class).isNotPrimitive(); assertThat(boolean.class).isNotPrimitive(); assertThat(char.class).isNotPrimitive();- Returns:
thisassertions object- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualClassis a primitive type.- See Also:
-
hasPublicFields(String...)instead.