Package org.assertj.core.internal
Class Classes
java.lang.Object
org.assertj.core.internal.Classes
Reusable assertions for
Class
s.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ComparisonStrategy
private Failures
private static final Classes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
assertContainsAnnotations
(AssertionInfo info, Class<?> actual, Class<? extends Annotation>[] annotations) Verifies that the actualClass
contains the givenAnnotation
s.void
assertHasDeclaredFields
(AssertionInfo info, Class<?> actual, String... fields) Verifies that the actualClass
has the declaredfields
.void
assertHasDeclaredMethods
(AssertionInfo info, Class<?> actual, String... methods) Verifies that the actualClass
has the declaredmethods
.void
assertHasMethods
(AssertionInfo info, Class<?> actual, String... methods) Verifies that the actualClass
has themethods
.void
assertHasNoSuperclass
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
has no superclass.void
assertHasOnlyDeclaredFields
(AssertionInfo info, Class<?> actual, String... expectedFields) Verifies that the actualClass
has the exactly thefields
and nothing more.void
assertHasOnlyPublicFields
(AssertionInfo info, Class<?> actual, String... expectedFields) Verifies that the actualClass
has only thefields
and nothing more.void
assertHasPackage
(AssertionInfo info, Class<?> actual, Package aPackage) Verifies that the actualClass
has the givenPackage
.void
assertHasPackage
(AssertionInfo info, Class<?> actual, String packageName) Verifies that the actualClass
has the givenpackageName
.void
assertHasPublicFields
(AssertionInfo info, Class<?> actual, String... fields) Verifies that the actualClass
has thefields
.void
assertHasPublicMethods
(AssertionInfo info, Class<?> actual, String... methods) Verifies that the actualClass
has the publicmethods
.void
assertHasSuperclass
(AssertionInfo info, Class<?> actual, Class<?> superclass) Verifies that the actualClass
has the given class as directsuperclass
.void
assertIsAbstract
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is abstract.void
assertIsAnnotation
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is an annotation.void
assertIsAssignableFrom
(AssertionInfo info, Class<?> actual, Class<?>... others) Verifies that the actualClass
is assignable from all theothers
classes.void
assertIsFinal
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is final.void
assertIsInterface
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is an interface.void
assertIsNotAnnotation
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is not an annotation.void
assertIsNotFinal
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is not final.void
assertIsNotInterface
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is not an interface.void
assertIsNotStatic
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is not static.void
assertIsPackagePrivate
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is package-private.void
assertIsProtected
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is protected.void
assertIsPublic
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is public.void
assertIsStatic
(AssertionInfo info, Class<?> actual) Verifies that the actualClass
is static.private static void
assertNotNull
(AssertionInfo info, Class<?> actual) private static void
classParameterIsNotNull
(Class<?> clazz) used to check that the class to compare is not null, in that case throws aNullPointerException
with an explicit message.private void
doAssertHasMethods
(AssertionInfo info, Class<?> actual, Set<Method> actualMethods, boolean declared, String... expectedMethods) fieldsToName
(Set<Field> fields) filterSyntheticMembers
(M[] members) private static Method[]
getAllMethods
(Class<?> actual) getMethodsWithModifier
(Set<Method> methods, int modifier) private static boolean
hasPublicMethods
(Method[] methods) static Classes
instance()
Returns the singleton instance of this class.methodsToName
(Set<Method> methods) methodsToNameAndModifier
(Method[] methods) private static boolean
Checks that theexpectedNames
are part of theactualNames
.private static boolean
noNonMatchingModifier
(Set<String> expectedMethodNames, Map<String, Integer> methodsModifier, Map<String, String> nonMatchingModifiers, int modifier)
-
Field Details
-
INSTANCE
-
failures
-
comparisonStrategy
-
-
Constructor Details
-
Classes
public Classes()
-
-
Method Details
-
instance
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
assertIsAssignableFrom
Verifies that the actualClass
is assignable from all theothers
classes.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.others
- the othersClass
who this actual class must be assignable.- Throws:
NullPointerException
- if one of theothers
isnull
.AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not assignable from all of theothers
classes.
-
assertIsNotInterface
Verifies that the actualClass
is not an interface.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is an interface.
-
assertIsInterface
Verifies that the actualClass
is an interface.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not an interface.
-
assertIsAbstract
Verifies that the actualClass
is abstract.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not abstract.
-
assertIsNotAnnotation
Verifies that the actualClass
is not an annotation.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is an annotation.
-
assertIsAnnotation
Verifies that the actualClass
is an annotation.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not an annotation.
-
assertIsFinal
Verifies that the actualClass
is final.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not final.
-
assertIsPublic
Verifies that the actualClass
is public.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not public.
-
assertIsProtected
Verifies that the actualClass
is protected.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not protected.
-
assertIsPackagePrivate
Verifies that the actualClass
is package-private.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not package-private.
-
assertIsNotFinal
Verifies that the actualClass
is not final.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is final.
-
assertIsStatic
Verifies that the actualClass
is static.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is not static.
-
assertIsNotStatic
Verifies that the actualClass
is not static.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
is static.
-
assertContainsAnnotations
public void assertContainsAnnotations(AssertionInfo info, Class<?> actual, Class<? extends Annotation>[] annotations) Verifies that the actualClass
contains the givenAnnotation
s.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.annotations
- annotations who must be attached to the class- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
doesn't contains all of these annotations.
-
assertHasSuperclass
Verifies that the actualClass
has the given class as directsuperclass
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.superclass
- the direct superclass, which should not be null.- Throws:
NullPointerException
- ifsuperclass
isnull
.AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
does not have the expected superclass.
-
assertHasNoSuperclass
Verifies that the actualClass
has no superclass.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
has a superclass.
-
assertHasPublicFields
Verifies that the actualClass
has thefields
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.fields
- the fields who must be present in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
doesn't contains all of the field.
-
assertHasOnlyPublicFields
public void assertHasOnlyPublicFields(AssertionInfo info, Class<?> actual, String... expectedFields) Verifies that the actualClass
has only thefields
and nothing more. in any order.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.expectedFields
- all the fields that are expected to be in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if fields are not all the fields of the actualClass
.
-
noMissingElement
private static boolean noMissingElement(Set<String> actualNames, Set<String> expectedNames, Set<String> missingNames) Checks that theexpectedNames
are part of theactualNames
. If anexpectedName
is not contained in theactualNames
, the this method will returntrue
. THemissingNames
will contain all theexpectedNames
that are not part of theactualNames
.- Parameters:
actualNames
- the names that should be used to checkexpectedNames
- the names that should be contained inactualNames
missingNames
- the names that were not part ofexpectedNames
- Returns:
true
if allexpectedNames
are part of theactualNames
,false
otherwise
-
assertHasDeclaredFields
Verifies that the actualClass
has the declaredfields
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.fields
- the fields who must be declared in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
doesn't contains all of the field.
-
assertHasOnlyDeclaredFields
public void assertHasOnlyDeclaredFields(AssertionInfo info, Class<?> actual, String... expectedFields) Verifies that the actualClass
has the exactly thefields
and nothing more. in any order.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.expectedFields
- all the fields that are expected to be in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if fields are not all the fields of the actualClass
.
-
fieldsToName
-
assertHasMethods
Verifies that the actualClass
has themethods
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.methods
- the methods who must be present in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
doesn't contains all the methods.
-
assertHasDeclaredMethods
Verifies that the actualClass
has the declaredmethods
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.methods
- the methods who must be declared in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
doesn't contains all the methods.
-
doAssertHasMethods
private void doAssertHasMethods(AssertionInfo info, Class<?> actual, Set<Method> actualMethods, boolean declared, String... expectedMethods) -
assertHasPublicMethods
Verifies that the actualClass
has the publicmethods
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.methods
- the public methods who must be present in the class.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualClass
doesn't contains all the public methods.
-
getMethodsWithModifier
-
noNonMatchingModifier
-
hasPublicMethods
-
methodsToName
-
methodsToNameAndModifier
-
getAllMethods
-
filterSyntheticMembers
-
assertNotNull
-
classParameterIsNotNull
used to check that the class to compare is not null, in that case throws aNullPointerException
with an explicit message.- Parameters:
clazz
- the date to check- Throws:
NullPointerException
- with an explicit message if the given class is null
-
assertHasPackage
Verifies that the actualClass
has the givenpackageName
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.packageName
- the package that must be declared in the class.- Throws:
NullPointerException
- ifpackageName
isnull
.AssertionError
- ifactual
isnull
.AssertionError
- ifactual
does not have the given package name.
-
assertHasPackage
Verifies that the actualClass
has the givenPackage
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Class
.aPackage
- the package that must be declared in the class.- Throws:
NullPointerException
- ifaPackage
isnull
.AssertionError
- ifactual
isnull
.AssertionError
- ifactual
does not have the given package.
-