Class ClassTester


  • public class ClassTester
    extends AbstractTester
    This tester examines classes. E.g. if looks if classes can be loaded independent from other classes.

    If you want to test some dependencies to a given class you can use this tester here. This functionality was moved from the old ClassTester class in the experimental package to here.

    Since:
    1.6 (04.11.2015)
    Author:
    oboehm (ob@aosd.de)
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassTester​(java.lang.String classname)
      Instantiates a new class tester.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean dependsOn​(java.lang.Class<?> otherClass)
      Checks if the stored class depends on another class.
      boolean dependsOn​(java.lang.String otherClassname)
      Checks if the stored class depends on another class.
      static boolean dependsOn​(java.lang.String classname, java.lang.Class<?> otherClass)
      Checks if the given class depends on another class.
      java.lang.String getClassName()
      Gets the class name.
      java.util.Set<java.lang.Class<?>> getDependencies()
      Gets the dependencies of the class name.
      static java.util.Set<java.lang.Class<?>> getDependenciesOf​(java.lang.String classname)
      Gets the dependencies of the given class name.
      static void tryStaticInitializer​(java.lang.String classname)
      Every class has an static initializer which will be called after a class is loaded.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClassTester

        public ClassTester​(java.lang.String classname)
                    throws java.lang.ClassNotFoundException
        Instantiates a new class tester.
        Parameters:
        classname - the classname
        Throws:
        java.lang.ClassNotFoundException - the class not found exception
    • Method Detail

      • getClassName

        public java.lang.String getClassName()
        Gets the class name.
        Returns:
        the class name
      • getDependencies

        public java.util.Set<java.lang.Class<?>> getDependencies()
        Gets the dependencies of the class name. To get all dependencies we load all declared methods, fields and other stuff.
        Returns:
        the dependencies of
      • dependsOn

        public boolean dependsOn​(java.lang.Class<?> otherClass)
        Checks if the stored class depends on another class. Because the given otherClass is using probably another class loader we compare the class name to decide if it is loaded.
        Parameters:
        otherClass - the other class
        Returns:
        true, if successful
      • dependsOn

        public boolean dependsOn​(java.lang.String otherClassname)
        Checks if the stored class depends on another class.
        Parameters:
        otherClassname - the other classname
        Returns:
        true, if successful
      • getDependenciesOf

        public static java.util.Set<java.lang.Class<?>> getDependenciesOf​(java.lang.String classname)
                                                                   throws java.lang.ClassNotFoundException
        Gets the dependencies of the given class name.
        Parameters:
        classname - the classname
        Returns:
        the dependencies of
        Throws:
        java.lang.ClassNotFoundException - the class not found exception
      • dependsOn

        public static boolean dependsOn​(java.lang.String classname,
                                        java.lang.Class<?> otherClass)
                                 throws java.lang.ClassNotFoundException
        Checks if the given class depends on another class.
        Parameters:
        classname - the classname
        otherClass - the other class
        Returns:
        true, if successful
        Throws:
        java.lang.ClassNotFoundException - the class not found exception
      • tryStaticInitializer

        public static void tryStaticInitializer​(java.lang.String classname)
                                         throws java.lang.ClassNotFoundException
        Every class has an static initializer which will be called after a class is loaded. To find problems with such initializers or with dependencies to other classes which cannot be solved this method tries to load the class with an isolated classloader and will throw an AssertionError if it can't.

        We expect a String as parameter and not a class because if we receive a class as parameter this class was already loaded before and we need not to check it again if it can be loaded.

        Parameters:
        classname - the class name.
        Throws:
        java.lang.ClassNotFoundException - the class not found exception