com.atlassian.clover.api.optimization

## Class TestOptimizer

- java.lang.Object
- - com.atlassian.clover.api.optimization.TestOptimizer

-     public class TestOptimizer
      extends java.lang.Object

  A TestOptimizer allows you to optimize a Collection of classes (that are Tests) programatically.

  Typically, this is to be done if your tests in are defined in a junit.framework.TestSuite.

  - The `optimize(java.util.List<T>)` method will take a list of Optimizables and return an optimized list of Optimizables.
  - The `optimizeTestClasses(java.util.Collection<java.lang.Class>)` method is a convenience method for optimizing a list of Test Classes.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TestOptimizer(OptimizationOptions options)`
    `TestOptimizer(java.lang.String initString, java.io.File snapshotFile)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T extends Optimizable> java.util.List<T>` | `optimize(java.util.List<T> optimizables)` Optimize a collection of any Optimizable.
    `java.util.List<Optimizable>` | `optimizeObjects(java.util.List objectList)` Optimizes a collection of unknown objects.
    `java.util.Collection<java.lang.Class>` | `optimizeTestClasses(java.util.Collection<java.lang.Class> testClasses)` Optimize a collection of Test classes.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TestOptimizer

          public TestOptimizer(OptimizationOptions options)

    - #### TestOptimizer

          public TestOptimizer(java.lang.String initString,
                               java.io.File snapshotFile)

  - ### Method Detail

    - #### optimizeTestClasses

          public java.util.Collection<java.lang.Class> optimizeTestClasses(java.util.Collection<java.lang.Class> testClasses)

      Optimize a collection of Test classes.
      Parameters:
        `testClasses` - classes to be optimized
      Returns:
        an optimized list of Classes

    - #### optimize

          public <T extends Optimizable> java.util.List<T> optimize(java.util.List<T> optimizables)

      Optimize a collection of any Optimizable.
      Type Parameters:
        `T` - Optimizable
      Parameters:
        `optimizables` - a list of objects, denoting tests, to optimize
      Returns:
        an optimized list of optimizable objects

    - #### optimizeObjects

          public java.util.List<Optimizable> optimizeObjects(java.util.List objectList)
                                                      throws java.lang.NoSuchMethodException,
                                                             java.lang.reflect.InvocationTargetException,
                                                             java.lang.IllegalAccessException

      Optimizes a collection of unknown objects. It tries to call 'getName()' method on each element from `objectList` using reflections. It returns a List where each element is an Optimizable which getName() method returns a value of corresponding `objectList.get(x).getName()`.

      This is a workaround for Clover-for-Grails plugin, where FileOptimizable class cannot implement Optimizable interface due to problems with dependency resolution in Grails via 'install-plugin' command. We're using Object and reflections to pass the necessary information.

      Parameters:
        `objectList` - list of objects having the 'String getName()' method returning name of optimizable resource
      Returns:
        List<Optimizable> optimized resource set
      Throws:
        `java.lang.NoSuchMethodException` - if getName() method does not exist
        `java.lang.reflect.InvocationTargetException` - if getName() call fails
        `java.lang.IllegalAccessException` - if getName() call fails