Class Classes

java.lang.Object
org.assertj.core.internal.Classes

public class Classes extends Object
Reusable assertions for Classs.
  • Field Details

  • Constructor Details

    • Classes

      public Classes()
  • Method Details

    • 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, Class<?> actual, Class<?>... others)
      Verifies that the actual Class is assignable from all the others classes.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      others - the others Class who this actual class must be assignable.
      Throws:
      NullPointerException - if one of the others is null.
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not assignable from all of the others classes.
    • assertIsNotInterface

      public void assertIsNotInterface(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is not an interface.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is an interface.
    • assertIsInterface

      public void assertIsInterface(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is an interface.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not an interface.
    • assertIsAbstract

      public void assertIsAbstract(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is abstract.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not abstract.
    • assertIsNotAnnotation

      public void assertIsNotAnnotation(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is not an annotation.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is an annotation.
    • assertIsAnnotation

      public void assertIsAnnotation(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is an annotation.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not an annotation.
    • assertIsFinal

      public void assertIsFinal(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is final.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not final.
    • assertIsPublic

      public void assertIsPublic(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is public.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not public.
    • assertIsProtected

      public void assertIsProtected(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is protected.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not protected.
    • assertIsPackagePrivate

      public void assertIsPackagePrivate(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is package-private.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not package-private.
    • assertIsNotFinal

      public void assertIsNotFinal(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is not final.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is final.
    • assertIsStatic

      public void assertIsStatic(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is static.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is not static.
    • assertIsNotStatic

      public void assertIsNotStatic(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class is not static.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class is static.
    • assertContainsAnnotations

      public void assertContainsAnnotations(AssertionInfo info, Class<?> actual, Class<? extends Annotation>[] annotations)
      Verifies that the actual Class contains the given Annotations.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      annotations - annotations who must be attached to the class
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class doesn't contains all of these annotations.
    • assertHasSuperclass

      public void assertHasSuperclass(AssertionInfo info, Class<?> actual, Class<?> superclass)
      Verifies that the actual Class has the given class as direct superclass.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      superclass - the direct superclass, which should not be null.
      Throws:
      NullPointerException - if superclass is null.
      AssertionError - if actual is null.
      AssertionError - if the actual Class does not have the expected superclass.
    • assertHasNoSuperclass

      public void assertHasNoSuperclass(AssertionInfo info, Class<?> actual)
      Verifies that the actual Class has no superclass.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class has a superclass.
    • assertHasPublicFields

      public void assertHasPublicFields(AssertionInfo info, Class<?> actual, String... fields)
      Verifies that the actual Class has the fields.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      fields - the fields who must be present in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class doesn't contains all of the field.
    • assertHasOnlyPublicFields

      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 - contains information about the assertion.
      actual - the "actual" Class.
      expectedFields - all the fields that are expected to be in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if fields are not all the fields of the actual Class.
    • noMissingElement

      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 - the names that should be used to check
      expectedNames - the names that should be contained in actualNames
      missingNames - the names that were not part of expectedNames
      Returns:
      true if all expectedNames are part of the actualNames, false otherwise
    • assertHasDeclaredFields

      public void assertHasDeclaredFields(AssertionInfo info, Class<?> actual, String... fields)
      Verifies that the actual Class has the declared fields.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      fields - the fields who must be declared in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class doesn't contains all of the field.
    • assertHasOnlyDeclaredFields

      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 - contains information about the assertion.
      actual - the "actual" Class.
      expectedFields - all the fields that are expected to be in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if fields are not all the fields of the actual Class.
    • fieldsToName

      private static Set<String> fieldsToName(Set<Field> fields)
    • assertHasMethods

      public void assertHasMethods(AssertionInfo info, Class<?> actual, String... methods)
      Verifies that the actual Class has the methods.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      methods - the methods who must be present in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class doesn't contains all the methods.
    • assertHasDeclaredMethods

      public void assertHasDeclaredMethods(AssertionInfo info, Class<?> actual, String... methods)
      Verifies that the actual Class has the declared methods.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      methods - the methods who must be declared in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class doesn't contains all the methods.
    • doAssertHasMethods

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

      public void assertHasPublicMethods(AssertionInfo info, Class<?> actual, String... methods)
      Verifies that the actual Class has the public methods.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      methods - the public methods who must be present in the class.
      Throws:
      AssertionError - if actual is null.
      AssertionError - if the actual Class doesn't contains all the public methods.
    • getMethodsWithModifier

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

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

      private static boolean hasPublicMethods(Method[] methods)
    • methodsToName

      private static SortedSet<String> methodsToName(Set<Method> methods)
    • methodsToNameAndModifier

      private static Map<String,Integer> methodsToNameAndModifier(Method[] methods)
    • getAllMethods

      private static Method[] getAllMethods(Class<?> actual)
    • filterSyntheticMembers

      private static <M extends Member> Set<M> filterSyntheticMembers(M[] members)
    • assertNotNull

      private static void assertNotNull(AssertionInfo info, Class<?> actual)
    • classParameterIsNotNull

      private static 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 - the date to check
      Throws:
      NullPointerException - with an explicit message if the given class is null
    • assertHasPackage

      public void assertHasPackage(AssertionInfo info, Class<?> actual, String packageName)
      Verifies that the actual Class has the given packageName.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      packageName - the package that must be declared in the class.
      Throws:
      NullPointerException - if packageName is null.
      AssertionError - if actual is null.
      AssertionError - if actual does not have the given package name.
    • assertHasPackage

      public void assertHasPackage(AssertionInfo info, Class<?> actual, Package aPackage)
      Verifies that the actual Class has the given Package.
      Parameters:
      info - contains information about the assertion.
      actual - the "actual" Class.
      aPackage - the package that must be declared in the class.
      Throws:
      NullPointerException - if aPackage is null.
      AssertionError - if actual is null.
      AssertionError - if actual does not have the given package.