package candy;

import java.io.PrintWriter;
import java.io.OutputStreamWriter;

/**
 * A generic (polymorphic) tester for candy machines.
 *
 * @author CSC223 2004F
 * @author Samuel A. Rebelsky
 * @version 1.0 of September 2006
 */
public class CandyMachineTester
{

// +--------+------------------------------------------------------------
// | Fields |
// +--------+

	/**
	 * The machine that we intend to test.
	 */
	CandyMachine testMe;

	/**
	 * The pen we use to write with.
	 */
	PrintWriter pen;
	
// +--------------+------------------------------------------------------
// | Constructors |
// +--------------+

	/**
	 * Create a new tester for a particular machine.
	 */
	public CandyMachineTester(CandyMachine testMe)
	{
		this.testMe = testMe;
		this.pen = new PrintWriter(System.out,true);
	} // CandyMachineTester(CandyMachine)

// +----------+----------------------------------------------------------
// | Mutators |
// +----------+

	public void runTest()
	{
		while (!this.testMe.isEmpty()) {
			try {
				this.pen.println(this.testMe.get());
			}
			catch (Exception e) {
				this.pen.println("Failed to get candy because " + e);
			}
		} // while
	} // runTest()

// +-----------+---------------------------------------------------------
// | Observers |
// +-----------+

} // class CandyMachineTester

