Top Description Fields Constructors Methods
org.assertj.core.internal

public Class Classes

extends Object
Class Inheritance
Static Imports
java.util.Objects.requireNonNull, java.util.stream.Collectors.toCollection, org.assertj.core.error.ShouldBeAssignableFrom.shouldBeAssignableFrom, .ShouldHaveAnnotations.shouldHaveAnnotations, .ShouldHaveFields.shouldHaveDeclaredFields, .ShouldHaveFields.shouldHaveFields, .ShouldHaveMethods.shouldHaveMethods, .ShouldHaveMethods.shouldNotHaveMethods, .ShouldHaveNoFields.shouldHaveNoDeclaredFields, .ShouldHaveNoFields.shouldHaveNoPublicFields, .ShouldOnlyHaveFields.shouldOnlyHaveDeclaredFields, .ShouldOnlyHaveFields.shouldOnlyHaveFields, org.assertj.core.util.Lists.newArrayList, .Preconditions.checkArgument, .Sets.newLinkedHashSet, .Sets.newTreeSet

Reusable assertions for Classs.
Author
William Delanoue

Field Summary

Modifier and TypeField and Description
private final ComparisonStrategy
private final Failures
private static final Classes

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
assertContainsAnnotations(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
Class<? extends Annotation>[]
annotations who must be attached to the class
annotations
)

Verifies that the actual Class contains the given Annotations.

public void
assertHasDeclaredFields(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
the fields who must be declared in the class.
fields
)

Verifies that the actual Class has the declared fields.

public void
assertHasDeclaredMethods(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
the methods who must be declared in the class.
methods
)

Verifies that the actual Class has the declared methods.

public void
assertHasMethods(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
the methods who must be present in the class.
methods
)

Verifies that the actual Class has the methods.

public void
assertHasOnlyDeclaredFields(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
all the fields that are expected to be in the class.
expectedFields
)

Verifies that the actual Class has the exactly the fields and nothing more.

public void
assertHasOnlyPublicFields(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
all the fields that are expected to be in the class.
expectedFields
)

Verifies that the actual Class has only the fields and nothing more.

public void
assertHasPublicFields(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
the fields who must be present in the class.
fields
)

Verifies that the actual Class has the fields.

public void
assertHasPublicMethods(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
String...
the public methods who must be present in the class.
methods
)

Verifies that the actual Class has the public methods.

public void
assertIsAssignableFrom(AssertionInfo
contains information about the assertion.
info
,
Class<?>
the "actual" Class.
actual
,
Class<?>...
the others Class who this actual class must be assignable.
others
)

Verifies that the actual Class is assignable from all the others classes.

private static void
public void
classParameterIsNotNull(Class<?>
the class to check
clazz
)

used to check that the class to compare is not null, in that case throws a NullPointerException with an explicit message.

private void
doAssertHasMethods(AssertionInfo info, Class<?> actual, Set<Method> actualMethods, boolean declared, String... expectedMethods)

private static Set<String>
private static <M extends Member> Set<M>
private static Method[]
getAllMethods(Class<?> actual)

private static SortedSet<String>
getMethodsWithModifier(Set<Method> methods, int modifier)

private static boolean
public static Classes

Returns:

the singleton instance of this class.
instance
()

Returns the singleton instance of this class.

private static SortedSet<String>
private static Map<String, Integer>
private static boolean

Returns:

true if all expectedNames are part of the actualNames, false otherwise
noMissingElement
(Set<String>
the names that should be used to check
actualNames
,
Set<String>
the names that should be contained in actualNames
expectedNames
,
Set<String>
the names that were not part of expectedNames
missingNames
)

Checks that the expectedNames are part of the actualNames.

private static boolean
noNonMatchingModifier(Set<String> expectedMethodNames, Map<String, Integer> methodsModifier, Map<String, String> nonMatchingModifiers, int modifier)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

comparisonStrategyback to summary
private final ComparisonStrategy comparisonStrategy
failuresback to summary
private final Failures failures
INSTANCEback to summary
private static final Classes INSTANCE

Constructor Detail

Classesback to summary
public Classes()

Method Detail

assertContainsAnnotationsback to summary
public void assertContainsAnnotations(AssertionInfo info, Class<?> actual, Class<? extends Annotation>[] annotations)

Verifies that the actual Class contains the given Annotations.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

annotations:Class<? extends Annotation>[]

annotations who must be attached to the class

Exceptions
AssertionError:
  • if actual is null.
  • if the actual Class doesn't contains all of these annotations.
assertHasDeclaredFieldsback to summary
public void assertHasDeclaredFields(AssertionInfo info, Class<?> actual, String... fields)

Verifies that the actual Class has the declared fields.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

fields:String[]

the fields who must be declared in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if the actual Class doesn't contains all of the field.
assertHasDeclaredMethodsback to summary
public void assertHasDeclaredMethods(AssertionInfo info, Class<?> actual, String... methods)

Verifies that the actual Class has the declared methods.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

methods:String[]

the methods who must be declared in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if the actual Class doesn't contains all the methods.
assertHasMethodsback to summary
public void assertHasMethods(AssertionInfo info, Class<?> actual, String... methods)

Verifies that the actual Class has the methods.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

methods:String[]

the methods who must be present in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if the actual Class doesn't contains all the methods.
assertHasOnlyDeclaredFieldsback to summary
public void assertHasOnlyDeclaredFields(AssertionInfo info, Class<?> actual, String... expectedFields)

Verifies that the actual Class has the exactly the fields and nothing more. in any order.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

expectedFields:String[]

all the fields that are expected to be in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if fields are not all the fields of the actual Class.
assertHasOnlyPublicFieldsback to summary
public void assertHasOnlyPublicFields(AssertionInfo info, Class<?> actual, String... expectedFields)

Verifies that the actual Class has only the fields and nothing more. in any order.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

expectedFields:String[]

all the fields that are expected to be in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if fields are not all the fields of the actual Class.
assertHasPublicFieldsback to summary
public void assertHasPublicFields(AssertionInfo info, Class<?> actual, String... fields)

Verifies that the actual Class has the fields.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

fields:String[]

the fields who must be present in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if the actual Class doesn't contains all of the field.
assertHasPublicMethodsback to summary
public void assertHasPublicMethods(AssertionInfo info, Class<?> actual, String... methods)

Verifies that the actual Class has the public methods.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

methods:String[]

the public methods who must be present in the class.

Exceptions
AssertionError:
  • if actual is null.
  • if the actual Class doesn't contains all the public methods.
assertIsAssignableFromback to summary
public void assertIsAssignableFrom(AssertionInfo info, Class<?> actual, Class<?>... others)

Verifies that the actual Class is assignable from all the others classes.

Parameters
info:AssertionInfo

contains information about the assertion.

actual:Class<?>

the "actual" Class.

others:Class<?>[]

the others Class who this actual class must be assignable.

Exceptions
NullPointerException:
if one of the others is null.
AssertionError:
  • if actual is null.
  • if the actual Class is not assignable from all of the others classes.
assertNotNullback to summary
private static void assertNotNull(AssertionInfo info, Class<?> actual)
classParameterIsNotNullback to summary
public void classParameterIsNotNull(Class<?> clazz)

used to check that the class to compare is not null, in that case throws a NullPointerException with an explicit message.

Parameters
clazz:Class<?>

the class to check

Exceptions
NullPointerException:
with an explicit message if the given class is null
doAssertHasMethodsback to summary
private void doAssertHasMethods(AssertionInfo info, Class<?> actual, Set<Method> actualMethods, boolean declared, String... expectedMethods)
fieldsToNameback to summary
private static Set<String> fieldsToName(Set<Field> fields)
filterSyntheticMembersback to summary
private static <M extends Member> Set<M> filterSyntheticMembers(M[] members)
getAllMethodsback to summary
private static Method[] getAllMethods(Class<?> actual)
getMethodsWithModifierback to summary
private static SortedSet<String> getMethodsWithModifier(Set<Method> methods, int modifier)
hasPublicMethodsback to summary
private static boolean hasPublicMethods(Method[] methods)
instanceback to summary
public static Classes instance()

Returns the singleton instance of this class.

Returns:Classes

the singleton instance of this class.

methodsToNameback to summary
private static SortedSet<String> methodsToName(Set<Method> methods)
methodsToNameAndModifierback to summary
private static Map<String, Integer> methodsToNameAndModifier(Method[] methods)
noMissingElementback to summary
private static boolean noMissingElement(Set<String> actualNames, Set<String> expectedNames, Set<String> missingNames)

Checks that the expectedNames are part of the actualNames. If an expectedName is not contained in the actualNames, the this method will return true. THe missingNames will contain all the expectedNames that are not part of the actualNames.

Parameters
actualNames:Set<String>

the names that should be used to check

expectedNames:Set<String>

the names that should be contained in actualNames

missingNames:Set<String>

the names that were not part of expectedNames

Returns:boolean

true if all expectedNames are part of the actualNames, false otherwise

noNonMatchingModifierback to summary
private static boolean noNonMatchingModifier(Set<String> expectedMethodNames, Map<String, Integer> methodsModifier, Map<String, String> nonMatchingModifiers, int modifier)