org.jwalk.gen
Class RedirectInGenerator

java.lang.Object
  extended by org.jwalk.gen.RedirectInGenerator
All Implemented Interfaces:
CustomGenerator, Generator

public class RedirectInGenerator
extends java.lang.Object
implements CustomGenerator

RedirectInGenerator is a custom generator that redirects standard input. If the test class has methods that expect the user to type in text, this can be inconvenient to enter multiple times. RedirectInGenerator redirects standard input System.in to refer to a text file called "input.txt", which the tester can fill with suitable data (whether numbers or text) for the test class's methods. If no pre-existing "input.txt" file can be found, RedirectInGenerator creates a sample file containing lines of text that contain integer digits and strings. This default file can be edited later to suit the desired kind of input. The input file is always placed in the same directory as the test class, so that different input files may be created for different classes.

Version:
1.0
Author:
Anthony Simons

Constructor Summary
RedirectInGenerator()
          Creates a RedirectInGenerator that redirects standard input.
 
Method Summary
 boolean canCreate(java.lang.Class<?> type)
          Reports whether this RedirectInGenerator can create values of the requested type.
protected  void finalize()
          Secret method to reset standard input.
 java.lang.Object nextValue(java.lang.Class<?> type)
          Creates the next quasi-unique value in sequence for a particular type.
 void setOwner(MasterGenerator generator)
          Registers a MasterGenerator as the owner of this RedirectInGenerator.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RedirectInGenerator

public RedirectInGenerator()
Creates a RedirectInGenerator that redirects standard input. This constructor creates a basic instance and saves a backup reference to the original InputStream stored in System.in. Redirection only happens when the owning MasterGenerator is set.

Method Detail

finalize

protected void finalize()
Secret method to reset standard input. When this RedirectGenerator goes out of scope, ensures that System.in refers to what it did originally. Replacing the substitute FileInputStream should cause that stream's finalize-method to be invoked, closing the stream.

Overrides:
finalize in class java.lang.Object

setOwner

public void setOwner(MasterGenerator generator)
Registers a MasterGenerator as the owner of this RedirectInGenerator. This method is automatically called when this RedirectInGenerator is added as a delegate of a MasterGenerator. It allows this generator to have access to its owning MasterGenerator, and to the JWalker, which created the MasterGenerator.

Specified by:
setOwner in interface CustomGenerator

canCreate

public boolean canCreate(java.lang.Class<?> type)
Reports whether this RedirectInGenerator can create values of the requested type. Always returns false, because this RedirectInGenerator does not intercept any types, but rather redirects the standard input stream to read from a file.

Specified by:
canCreate in interface Generator
Parameters:
type - the requested type.
Returns:
false, as this RedirectInputGenerator does not synthesise values.

nextValue

public java.lang.Object nextValue(java.lang.Class<?> type)
                           throws GeneratorException
Creates the next quasi-unique value in sequence for a particular type. This is a null operation in RedirectInGenerator, which does not actually synthesise values of any type. Rather, it redirects standard input to read from a file. If invoked, this method raises a GeneratorException.

Specified by:
nextValue in interface Generator
Parameters:
type - the requested type.
Returns:
the next value of this type.
Throws:
GeneratorException, - since no value of this type could be synthesised.
GeneratorException - if no value of this type could be synthesised.