Package org.assertj.core.internal
Class Classes
- java.lang.Object
-
- org.assertj.core.internal.Classes
-
public class Classes extends java.lang.ObjectReusable assertions fors.Class
-
-
Field Summary
Fields Modifier and Type Field Description private ComparisonStrategycomparisonStrategyprivate Failuresfailuresprivate static ClassesINSTANCE
-
Constructor Summary
Constructors Constructor Description Classes()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertContainsAnnotations(AssertionInfo info, java.lang.Class<?> actual, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)Verifies that the actualClasscontains the givenAnnotations.voidassertHasDeclaredFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... fields)Verifies that the actualClasshas the declaredfields.voidassertHasDeclaredMethods(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... methods)Verifies that the actualClasshas the declaredmethods.voidassertHasMethods(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... methods)Verifies that the actualClasshas themethods.voidassertHasNoSuperclass(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClasshas no superclass.voidassertHasOnlyDeclaredFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... expectedFields)Verifies that the actualClasshas the exactly thefieldsand nothing more.voidassertHasOnlyPublicFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... expectedFields)Verifies that the actualClasshas only thefieldsand nothing more.voidassertHasPackage(AssertionInfo info, java.lang.Class<?> actual, java.lang.Package aPackage)Verifies that the actualClasshas the givenPackage.voidassertHasPackage(AssertionInfo info, java.lang.Class<?> actual, java.lang.String packageName)Verifies that the actualClasshas the givenpackageName.voidassertHasPublicFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... fields)Verifies that the actualClasshas thefields.voidassertHasPublicMethods(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... methods)Verifies that the actualClasshas the publicmethods.voidassertHasSuperclass(AssertionInfo info, java.lang.Class<?> actual, java.lang.Class<?> superclass)Verifies that the actualClasshas the given class as directsuperclass.voidassertIsAbstract(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis abstract.voidassertIsAnnotation(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis an annotation.voidassertIsAssignableFrom(AssertionInfo info, java.lang.Class<?> actual, java.lang.Class<?>... others)Verifies that the actualClassis assignable from all theothersclasses.voidassertIsFinal(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis final.voidassertIsInterface(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis an interface.voidassertIsNotAnnotation(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis not an annotation.voidassertIsNotFinal(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis not final.voidassertIsNotInterface(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis not an interface.voidassertIsPackagePrivate(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis package-private.voidassertIsProtected(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis protected.voidassertIsPublic(AssertionInfo info, java.lang.Class<?> actual)Verifies that the actualClassis public.private static voidassertNotNull(AssertionInfo info, java.lang.Class<?> actual)private static voidclassParameterIsNotNull(java.lang.Class<?> clazz)used to check that the class to compare is not null, in that case throws aNullPointerExceptionwith an explicit message.private voiddoAssertHasMethods(AssertionInfo info, java.lang.Class<?> actual, java.util.Set<java.lang.reflect.Method> actualMethods, boolean declared, java.lang.String... expectedMethods)private static java.util.Set<java.lang.String>fieldsToName(java.util.Set<java.lang.reflect.Field> fields)private static <M extends java.lang.reflect.Member>
java.util.Set<M>filterSyntheticMembers(M[] members)private static java.lang.reflect.Method[]getAllMethods(java.lang.Class<?> actual)private static java.util.SortedSet<java.lang.String>getMethodsWithModifier(java.util.Set<java.lang.reflect.Method> methods, int modifier)private static booleanhasPublicMethods(java.lang.reflect.Method[] methods)static Classesinstance()Returns the singleton instance of this class.private static java.util.SortedSet<java.lang.String>methodsToName(java.util.Set<java.lang.reflect.Method> methods)private static java.util.Map<java.lang.String,java.lang.Integer>methodsToNameAndModifier(java.lang.reflect.Method[] methods)private static booleannoMissingElement(java.util.Set<java.lang.String> actualNames, java.util.Set<java.lang.String> expectedNames, java.util.Set<java.lang.String> missingNames)Checks that theexpectedNamesare part of theactualNames.private static booleannoNonMatchingModifier(java.util.Set<java.lang.String> expectedMethodNames, java.util.Map<java.lang.String,java.lang.Integer> methodsModifier, java.util.Map<java.lang.String,java.lang.String> nonMatchingModifiers, int modifier)
-
-
-
Field Detail
-
INSTANCE
private static final Classes INSTANCE
-
failures
private Failures failures
-
comparisonStrategy
private ComparisonStrategy comparisonStrategy
-
-
Method Detail
-
instance
public static Classes instance()
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
assertIsAssignableFrom
public void assertIsAssignableFrom(AssertionInfo info, java.lang.Class<?> actual, java.lang.Class<?>... others)
Verifies that the actualClassis assignable from all theothersclasses.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.others- the othersClasswho this actual class must be assignable.- Throws:
java.lang.NullPointerException- if one of theothersisnull.java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not assignable from all of theothersclasses.
-
assertIsNotInterface
public void assertIsNotInterface(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis not an interface.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis an interface.
-
assertIsInterface
public void assertIsInterface(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis an interface.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not an interface.
-
assertIsAbstract
public void assertIsAbstract(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis abstract.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not abstract.
-
assertIsNotAnnotation
public void assertIsNotAnnotation(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis not an annotation.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis an annotation.
-
assertIsAnnotation
public void assertIsAnnotation(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis an annotation.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not an annotation.
-
assertIsFinal
public void assertIsFinal(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis final.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not final.
-
assertIsPublic
public void assertIsPublic(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis public.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not public.
-
assertIsProtected
public void assertIsProtected(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis protected.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not protected.
-
assertIsPackagePrivate
public void assertIsPackagePrivate(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis package-private.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis not package-private.
-
assertIsNotFinal
public void assertIsNotFinal(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClassis not final.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassis final.
-
assertContainsAnnotations
public void assertContainsAnnotations(AssertionInfo info, java.lang.Class<?> actual, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
Verifies that the actualClasscontains the givenAnnotations.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.annotations- annotations who must be attached to the class- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoesn't contains all of these annotations.
-
assertHasSuperclass
public void assertHasSuperclass(AssertionInfo info, java.lang.Class<?> actual, java.lang.Class<?> superclass)
Verifies that the actualClasshas 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:
java.lang.NullPointerException- ifsuperclassisnull.java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoes not have the expected superclass.
-
assertHasNoSuperclass
public void assertHasNoSuperclass(AssertionInfo info, java.lang.Class<?> actual)
Verifies that the actualClasshas no superclass.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClasshas a superclass.
-
assertHasPublicFields
public void assertHasPublicFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... fields)
Verifies that the actualClasshas thefields.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.fields- the fields who must be present in the class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoesn't contains all of the field.
-
assertHasOnlyPublicFields
public void assertHasOnlyPublicFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... expectedFields)
Verifies that the actualClasshas only thefieldsand 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:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if fields are not all the fields of the actualClass.
-
noMissingElement
private static boolean noMissingElement(java.util.Set<java.lang.String> actualNames, java.util.Set<java.lang.String> expectedNames, java.util.Set<java.lang.String> missingNames)Checks that theexpectedNamesare part of theactualNames. If anexpectedNameis not contained in theactualNames, the this method will returntrue. THemissingNameswill contain all theexpectedNamesthat are not part of theactualNames.- Parameters:
actualNames- the names that should be used to checkexpectedNames- the names that should be contained inactualNamesmissingNames- the names that were not part ofexpectedNames- Returns:
trueif allexpectedNamesare part of theactualNames,falseotherwise
-
assertHasDeclaredFields
public void assertHasDeclaredFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... fields)
Verifies that the actualClasshas the declaredfields.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.fields- the fields who must be declared in the class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoesn't contains all of the field.
-
assertHasOnlyDeclaredFields
public void assertHasOnlyDeclaredFields(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... expectedFields)
Verifies that the actualClasshas the exactly thefieldsand 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:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if fields are not all the fields of the actualClass.
-
fieldsToName
private static java.util.Set<java.lang.String> fieldsToName(java.util.Set<java.lang.reflect.Field> fields)
-
assertHasMethods
public void assertHasMethods(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... methods)
Verifies that the actualClasshas themethods.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.methods- the methods who must be present in the class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoesn't contains all of the methods.
-
assertHasDeclaredMethods
public void assertHasDeclaredMethods(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... methods)
Verifies that the actualClasshas the declaredmethods.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.methods- the methods who must be declared in the class.- Throws:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoesn't contains all of the methods.
-
doAssertHasMethods
private void doAssertHasMethods(AssertionInfo info, java.lang.Class<?> actual, java.util.Set<java.lang.reflect.Method> actualMethods, boolean declared, java.lang.String... expectedMethods)
-
assertHasPublicMethods
public void assertHasPublicMethods(AssertionInfo info, java.lang.Class<?> actual, java.lang.String... methods)
Verifies that the actualClasshas 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:
java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- if the actualClassdoesn't contains all of the public methods.
-
getMethodsWithModifier
private static java.util.SortedSet<java.lang.String> getMethodsWithModifier(java.util.Set<java.lang.reflect.Method> methods, int modifier)
-
noNonMatchingModifier
private static boolean noNonMatchingModifier(java.util.Set<java.lang.String> expectedMethodNames, java.util.Map<java.lang.String,java.lang.Integer> methodsModifier, java.util.Map<java.lang.String,java.lang.String> nonMatchingModifiers, int modifier)
-
hasPublicMethods
private static boolean hasPublicMethods(java.lang.reflect.Method[] methods)
-
methodsToName
private static java.util.SortedSet<java.lang.String> methodsToName(java.util.Set<java.lang.reflect.Method> methods)
-
methodsToNameAndModifier
private static java.util.Map<java.lang.String,java.lang.Integer> methodsToNameAndModifier(java.lang.reflect.Method[] methods)
-
getAllMethods
private static java.lang.reflect.Method[] getAllMethods(java.lang.Class<?> actual)
-
filterSyntheticMembers
private static <M extends java.lang.reflect.Member> java.util.Set<M> filterSyntheticMembers(M[] members)
-
assertNotNull
private static void assertNotNull(AssertionInfo info, java.lang.Class<?> actual)
-
classParameterIsNotNull
private static void classParameterIsNotNull(java.lang.Class<?> clazz)
used to check that the class to compare is not null, in that case throws aNullPointerExceptionwith an explicit message.- Parameters:
clazz- the date to check- Throws:
java.lang.NullPointerException- with an explicit message if the given class is null
-
assertHasPackage
public void assertHasPackage(AssertionInfo info, java.lang.Class<?> actual, java.lang.String packageName)
Verifies that the actualClasshas the givenpackageName.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.packageName- the package that must be declared in the class.- Throws:
java.lang.NullPointerException- ifpackageNameisnull.java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- ifactualdoes not have the given package name.
-
assertHasPackage
public void assertHasPackage(AssertionInfo info, java.lang.Class<?> actual, java.lang.Package aPackage)
Verifies that the actualClasshas the givenPackage.- Parameters:
info- contains information about the assertion.actual- the "actual"Class.aPackage- the package that must be declared in the class.- Throws:
java.lang.NullPointerException- ifaPackageisnull.java.lang.AssertionError- ifactualisnull.java.lang.AssertionError- ifactualdoes not have the given package.
-
-