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

java.lang.Object
  extended by org.hyphenType.dynamicproxy.AbstractArgumentsInvocationHandler<T>
      extended by org.hyphenType.unittesting.MockArgumentsInvocationHandler<T>
Type Parameters:
T - The option interface type.
All Implemented Interfaces:
InvocationHandler

public class MockArgumentsInvocationHandler<T extends Options<?>>
extends AbstractArgumentsInvocationHandler<T>

A mock to replace ConcreteArgumentsInvocationHandler. When this class is used instead of ConcreteArgumentsInvocationHandler, this class avoids calls to ArgumentsInvocationHandler#exit(Enum)) and ArgumentsInvocationHandler#exit(int))) to actually terminate the JVM. Instead, this class will log those calls. This way, a unit test can read the logs and determine if user source code is trying to terminate the JVM correctly.

This class was designed to be utilized by UnitTestingOptionExtractor.

Author:
Aurelio Akira M. Matsui
See Also:
UnitTestingOptionExtractor, ConcreteArgumentsInvocationHandler

Constructor Summary
MockArgumentsInvocationHandler(OptionValues<T> values, Class<? extends Options<?>> optionsInterface, Class<? extends StatusCode> exitCodeEnumClass, String[] rawArguments, boolean throwsNonExceptionalExit)
          Sole constructor.
 
Method Summary
protected  void exit(Enum<?> e)
          TODO Comment.
protected  void exit(int code)
          TODO Comment.
 boolean exitEnumCalled()
          Useful to check whether the exit(Enum) method was called or not.
 boolean exitIntCalled()
          Useful to check whether the exit(int) method was called or not.
 Enum<?> getStatusCodeEnum()
          Useful to analyze how the exit(Enum) method was called.
 int getStatusCodeInt()
          Useful to analyze how the exit(int) method was called.
 
Methods inherited from class org.hyphenType.dynamicproxy.AbstractArgumentsInvocationHandler
equals, hashCode, invoke, printDocumentation, printDocumentation, printDocumentation, printDocumentation, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockArgumentsInvocationHandler

public MockArgumentsInvocationHandler(OptionValues<T> values,
                                      Class<? extends Options<?>> optionsInterface,
                                      Class<? extends StatusCode> exitCodeEnumClass,
                                      String[] rawArguments,
                                      boolean throwsNonExceptionalExit)
Sole constructor.

Parameters:
values - The values parsed.
formatter - The documentation formatter.
exitCodeEnumClass - The enumeration class that will be used to exit.
rawArguments - The raw arguments "received" from the command line.
throwsNonExceptionalExit - Whether this mock implementation will throw the NonExceptionalExit exception or not.
Method Detail

exit

protected final void exit(Enum<?> e)
Description copied from class: AbstractArgumentsInvocationHandler
TODO Comment.

Specified by:
exit in class AbstractArgumentsInvocationHandler<T extends Options<?>>
Parameters:
e - TODO Comment.

exit

protected final void exit(int code)
Description copied from class: AbstractArgumentsInvocationHandler
TODO Comment.

Specified by:
exit in class AbstractArgumentsInvocationHandler<T extends Options<?>>
Parameters:
code - TODO Comment.

getStatusCodeEnum

public final Enum<?> getStatusCodeEnum()
Useful to analyze how the exit(Enum) method was called.

Returns:
The status code returned by the last call to the exit(Enum) method.

exitEnumCalled

public final boolean exitEnumCalled()
Useful to check whether the exit(Enum) method was called or not.

Returns:
Whether the method exit(Enum) was called or not.

getStatusCodeInt

public final int getStatusCodeInt()
Useful to analyze how the exit(int) method was called.

Returns:
The status code returned by the last call to the exit(int) method.

exitIntCalled

public final boolean exitIntCalled()
Useful to check whether the exit(int) method was called or not.

Returns:
Whether the method exit(int) was called or not.


Copyright © 2013. All Rights Reserved.