Code Search for Developers
 
 
  

TestRunner.java from MASE: Agile Software Engineering at Krugle


Show TestRunner.java syntax highlighted

// Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
// Copyright (c) 2002 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.
// Copyright (C) 2003,2004 by Robert C. Martin and Micah D. Martin. All rights reserved.
// Released under the terms of the GNU General Public License version 2 or later.
package fit;

import java.io.*;




public class TestRunner
{
	private PrintWriter out = null;
	public String input;
	public Parse tables;
	public Fixture fixture = new Fixture();
	public FixtureListener fixtureListener = new FilePrintingFixtureListener();
	private Counts counts = new Counts();


  
  	private String sourceFile = "";
  	private String destFile = "";
  	public TestRunner(){
  		
  	}
	public static void main(String argv[]) throws Exception
	{
		TestRunner testRunner = new TestRunner();
		

		testRunner.run(argv);
		
		System.exit(0);
	}

	public void run(String argv[]) throws Exception
	{
		args(argv);
		this.out = new PrintWriter(this.destFile);
		process();

		exit();
	}



  public void process()
	{

				try
				{

					FileManager manager = new FileManager();
					String document = manager.readFile(this.sourceFile);
					
					//TODO MDM if the page name was always the first line of the body, it could be printed here.
					tables = new Parse(document);
					newFixture().doTables(tables);
//					System.out.println("\tresults: " + fixture.counts.toString() + "\n");
//					counts.tally(fixture.counts);
				}
				catch(Exception e)
				{
					exception(e);
				}

	}



	private Fixture newFixture()
	{
		fixture = new Fixture();
		fixture.listener = fixtureListener;
		return fixture;
	}

	public void args(String[] argv)
	{
		if(argv.length != 2){
			usage();
		}
		this.sourceFile = argv[0];
		this.destFile = argv[1];
	}

  private void usage()
  {
    System.out.println("usage: java runner.TestRunner sourceFile destFile");
    System.exit(-1);
  }

	protected void exception(Exception e)
	{
//		print("Exception occurred!" + "\n");
//		print("\t" + e.getMessage() + "\n");
		tables = new Parse("span", "Exception occurred: ", null, null);
		fixture.exception(tables, e);
		counts.exceptions += 1;
		fixture.listener.tableFinished(tables);
		fixture.listener.tablesFinished(counts); //TODO shouldn't this be fixture.counts
	}

	public void exit() throws Exception
	{
//		print("exiting" + "\n");
//		print("\tend results: " + counts.toString() + "\n");
	}


	public Counts getCounts()
	{
		return counts;
	}

	

	
	public void writeTable(Parse table) throws Exception{
		
		Parse more = table.more;
		table.more = null;
		if(table.trailer == null)
			table.trailer = "";
		table.print(out);
		table.more = more;
//		writer.close();
		
	}

//	class TablePrintingFixtureListener implements FixtureListener
//	{
//		public void tableFinished(Parse table)
//		{
//			try
//			{
//				byte[] bytes = readTable(table);
//				if(bytes.length > 0)
//					FitProtocol.writeData(bytes, socketOutput);
//			}
//			catch(Exception e)
//			{
//				e.printStackTrace();
//			}
//		}
//
//		public void tablesFinished(Counts count)
//		{
//			try
//			{
//				FitProtocol.writeCounts(count, socketOutput);
//			}
//			catch(IOException e)
//			{
//				e.printStackTrace();
//			}
//		}
//	}
	
	class FilePrintingFixtureListener implements FixtureListener{

		public void tableFinished(Parse table) {
			// TODO Auto-generated method stub
			try{
			writeTable(table);
			}catch(Exception e){e.printStackTrace();}
		}

		public void tablesFinished(Counts count) {
			// TODO Auto-generated method stub
//			System.out.println(counts.toString());
			System.err.println(fixture.counts.toString());
			out.close();
			
		} 
		
		
	}
	
	private class FileManager{
		
		
		public String createFile(String fileName, String content){
		
			File file = new File(fileName);
			try {
				file.createNewFile();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
//				e1.printStackTrace();
			}
			try {
				PrintWriter out = new PrintWriter(new FileOutputStream(file));
				out.print(content);
				out.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return fileName;
		}
		
		public void deleteFile(String fileName){
			File file = new File(fileName);
			file.delete();
			
		}
		
		public String readFile(String fileName) throws FileNotFoundException, IOException{
			File file = new File(fileName);
			StringBuffer result = new StringBuffer();
			BufferedReader in = new BufferedReader(new FileReader(file));
			
			String line = "";
			while((line=in.readLine())!= null){
				result.append(line).append('\n');
			}
			
			return result.toString();
			
		}
		
	}
}





See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  exception/
    AmbiguousActionException.java
    AmbiguousNameFailureException.java
    BooleanMethodFitFailureException.java
    ClassIsNotFixtureException.java
    CouldNotLoadComponentFitFailureException.java
    CouldNotParseFitFailureException.java
    CycleException.java
    ExtraCellsFailureException.java
    FitFailureException.java
    FitFailureExceptionWithHelp.java
    FitMatcherException.java
    FitParseException.java
    FixtureException.java
    IgnoredException.java
    MissingCellsFailureException.java
    MissingFieldFitFailureException.java
    MissingMethodException.java
    MissingRowFailureException.java
    NestedTableExpected.java
    NoDefaultConstructorFixtureException.java
    NoSuchFieldFitFailureException.java
    NoSuchFixtureException.java
    NoSuchMethodFitFailureException.java
    RowWrongWidthException.java
    VoidMethodFitFailureException.java
  ActionFixture.java
  Binding.java
  ColumnFixture.java
  ColumnFixtureTest.java
  Comment.java
  Counts.java
  CountsTest.java
  FileRunner.java
  FitMatcher.java
  FitMatcherTest.java
  Fixture.java
  FixtureClass.java
  FixtureListener.java
  FixtureLoader.java
  FixtureLoaderTest.java
  FixtureName.java
  GracefulNamer.java
  GracefulNamerTest.java
  ImportFixture.java
  NullFixtureListener.java
  Parse.java
  ParseTest.java
  PrimitiveFixture.java
  RowFixture.java
  RowFixtureTest.java
  ScientificDouble.java
  ScientificDoubleTest.java
  SummaryFixture.java
  TestRunner.java
  TimedActionFixture.java
  TypeAdapter.java
  TypeAdapterTest.java
  WikiRunner.java