edu.pdx.cs399J.grader
Class Tester

java.lang.Object
  extended by edu.pdx.cs399J.grader.Tester

public class Tester
extends Object

This class contains a number of helper methods for testing projects in CS399J.

Author:
David Whitlock

Constructor Summary
Tester(PrintWriter pw)
          Creates a new Tester that sends its output to a given PrintWriter.
Tester(String id, File logDir)
          Creates a new Tester for a given student.
 
Method Summary
 void cat(File file)
          "Cats" a file to the log.
 void cp(File srcFile, File destFile)
          Copies one file to another.
 void executeMain(String className, String[] args)
          Executes the main method of the class with the given name with the given arguments.
 Thread executeMainInThread(String className, String[] args)
          Executes the main method of the class with the given name in its own thread.
 Object executeStatic(String className, String methodName, Class[] paramTypes, Object[] params)
          Executes a static method of a given name in a given class with a given set of parameters.
 Object executeStatic(String className, String methodName, Class[] paramTypes, Object[] params, boolean printBanner)
          Executes a static method of a given name in a given class with a given set of parameters.
 void finalize()
          Make sure we're done when this Tester gets garbage collected.
static void main(String[] args)
          Load a class from a given directory
static void main0(String[] args)
          Old Test Program.
static URL[] parseURLPath(String path)
          Parses a file path and creates an array of URLs representing each file on the path.
 void printBanner(String text, char c)
          Prints a line of text to the log file, centers it, around surrounds it with a given character.
 void println(Object o)
          Prints a left justified line of text to the log file.
 void println(String text)
          Prints a left justified line of text to the log file.
 void printlnCentered(String text)
          Prints a line of text to the log file and centers it.
 void setURLs(URL[] urls)
          Sets the URLs on which to search for students' classes
 boolean wait(int seconds)
          Waits for a given number of seconds.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tester

public Tester(PrintWriter pw)
Creates a new Tester that sends its output to a given PrintWriter. This is useful when you want to dump to the console. The "student's" id is "writer".


Tester

public Tester(String id,
              File logDir)
Creates a new Tester for a given student. It will create a log file in given directory.

Parameters:
id - The student's login id
logDir - Directory into which the log file is placed.
Method Detail

parseURLPath

public static URL[] parseURLPath(String path)
Parses a file path and creates an array of URLs representing each file on the path.


setURLs

public void setURLs(URL[] urls)
Sets the URLs on which to search for students' classes


executeStatic

public Object executeStatic(String className,
                            String methodName,
                            Class[] paramTypes,
                            Object[] params)
Executes a static method of a given name in a given class with a given set of parameters.


executeStatic

public Object executeStatic(String className,
                            String methodName,
                            Class[] paramTypes,
                            Object[] params,
                            boolean printBanner)
Executes a static method of a given name in a given class with a given set of parameters.

Parameters:
printBanner - Do we print a banner message?

executeMainInThread

public Thread executeMainInThread(String className,
                                  String[] args)
Executes the main method of the class with the given name in its own thread.

Returns:
The Thread in which the main method is running.

wait

public boolean wait(int seconds)
Waits for a given number of seconds. Returns false if the thread was interrupted.


executeMain

public void executeMain(String className,
                        String[] args)
Executes the main method of the class with the given name with the given arguments.


println

public void println(Object o)
Prints a left justified line of text to the log file.


println

public void println(String text)
Prints a left justified line of text to the log file.


printlnCentered

public void printlnCentered(String text)
Prints a line of text to the log file and centers it.


printBanner

public void printBanner(String text,
                        char c)
Prints a line of text to the log file, centers it, around surrounds it with a given character.


cp

public void cp(File srcFile,
               File destFile)
Copies one file to another. If the destination file exists, it is overridden.


cat

public void cat(File file)
"Cats" a file to the log. That is, copies its contents to the log.

Parameters:
file - File to be catted

finalize

public void finalize()
Make sure we're done when this Tester gets garbage collected. This way, the stream will always get closed.

Overrides:
finalize in class Object

main

public static void main(String[] args)
Load a class from a given directory


main0

public static void main0(String[] args)
Old Test Program.



Copyright © 2000-2009 Portland State University. All Rights Reserved.