org.hyphenType.unittesting
Class UnitTestingOptionExtractor<T extends Options<?>>

java.lang.Object
  extended by org.hyphenType.optionsextractor.OptionsExtractor<T>
      extended by org.hyphenType.unittesting.UnitTestingOptionExtractor<T>
Type Parameters:
T -

public class UnitTestingOptionExtractor<T extends Options<?>>
extends OptionsExtractor<T>

An OptionsExtractor that is ready for unit tests. This kind of OptionsExtractor will replace the actual routines to terminate the JVM (Options#exit(Enum) and Options#exit(int)) with mock implementations. Calls for exit methods will be logged and can be read by unit tests after the code under test was executed. To analyze the usage of exit methods, the following methods are available:

This class can also be utilized to test option interface processors (see ArgumentsProcessorEngine).

Author:
Aurelio Akira M. Matsui
See Also:
ArgumentsProcessorEngine, OptionsExtractor

Constructor Summary
UnitTestingOptionExtractor(Class<T> clazz)
          Creates a new UnitTestingOptionExtractor object that will work as a factory for objects whose options interface's class is the class given as argument.
UnitTestingOptionExtractor(Class<T> clazz, boolean throwsNotExceptionalExit)
          Creates a new UnitTestingOptionExtractor object in a way that allows the caller to chose whether or not calls to Options#exit(Enum) or Options#exit(int) will result into throwing a NonExceptionalExit exception.
 
Method Summary
protected  InvocationHandler buildInvocationHandler(OptionValues<T> values, Class<? extends Options<?>> optionsInterface, Class<? extends StatusCode> exitCodeEnumClass, String[] rawArguments)
          Prepared to be replaced by a subclass.
 boolean exitEnumCalled(T options)
          Returns whether or not the method Options#exit(Enum) was called on the given options.
 boolean exitIntCalled(T options)
          Returns whether or not the method Options#exit(int) was called on the given options.
 Enum<?> getStatusCodeEnum(T options)
          Retrieves the status code of a certain options object.
 int getStatusCodeInt(T options)
          Retrieves the status code (int) of a certain options object.
 
Methods inherited from class org.hyphenType.optionsextractor.OptionsExtractor
options, options
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnitTestingOptionExtractor

public UnitTestingOptionExtractor(Class<T> clazz)
                           throws InvalidOptionsInterfaceException
Creates a new UnitTestingOptionExtractor object that will work as a factory for objects whose options interface's class is the class given as argument. This constructor will configure UnitTestingOptionExtractor to factor option objects that throw NonExceptionalExit exceptions. If you want to chose whether or not the options objects will throw NonExceptionalExit, use the constructor UnitTestingOptionExtractor(Class, boolean) instead.

Parameters:
clazz -
Throws:
InvalidOptionsInterfaceException
InvalidOptionException

UnitTestingOptionExtractor

public UnitTestingOptionExtractor(Class<T> clazz,
                                  boolean throwsNotExceptionalExit)
                           throws InvalidOptionsInterfaceException
Creates a new UnitTestingOptionExtractor object in a way that allows the caller to chose whether or not calls to Options#exit(Enum) or Options#exit(int) will result into throwing a NonExceptionalExit exception.

Parameters:
clazz - The option interface class.
throwsNotExceptionalExit - A flag to configure whether option objects will throw NonExceptionalExit when one calls Options#exit(Enum) or Options#exit(int).
Throws:
InvalidOptionsInterfaceException
InvalidOptionException
See Also:
NonExceptionalExit
Method Detail

buildInvocationHandler

protected InvocationHandler buildInvocationHandler(OptionValues<T> values,
                                                   Class<? extends Options<?>> optionsInterface,
                                                   Class<? extends StatusCode> exitCodeEnumClass,
                                                   String[] rawArguments)
Description copied from class: OptionsExtractor
Prepared to be replaced by a subclass. Extending OptionsExtractor is useful to replace the composition of objects that will process the arguments.

Overrides:
buildInvocationHandler in class OptionsExtractor<T extends Options<?>>
Returns:

exitEnumCalled

public boolean exitEnumCalled(T options)
Returns whether or not the method Options#exit(Enum) was called on the given options.

Parameters:
options -
Returns:

getStatusCodeEnum

public Enum<?> getStatusCodeEnum(T options)
Retrieves the status code of a certain options object. The status code is set when the method Options#exit(Enum) is called. If Options#exit(Enum) was never called on the given options object, this method will throw a RuntimeException. You can call exitEnumCalled(Options) to avoid having to catch the exception.

Parameters:
options - The options object that we will extract the status code enumeration from.
Returns:
The status code, if the method Options#exit(Enum) was already called.
Throws:
RuntimeException - If the method Options#exit(Enum) was never called.

exitIntCalled

public boolean exitIntCalled(T options)
Returns whether or not the method Options#exit(int) was called on the given options.

Parameters:
options -
Returns:

getStatusCodeInt

public int getStatusCodeInt(T options)
Retrieves the status code (int) of a certain options object. The status code (int) is set when the method Options#exit(int) is called. If Options#exit(int) was never called on the given options object, this method will throw a RuntimeException. You can call UnitTestingOptionExtractor#exitEnumCalled(int) to avoid having to catch the exception.

Parameters:
options - The options object that we will extract the status code integer from.
Returns:
The status code, if the method Options#exit(int) was already called.
Throws:
RuntimeException - If the method Options#exit(int) was never called.


Copyright © 2013. All Rights Reserved.