mvn eclipse:eclipse
I opened the projet in eclipse. For the Junit tests I created some test input files here:
src\test\resources\TestData.txt
src\test\resources\BadInput.txt
I then created the unit test java file here:
src\test\java\com\tynt\app\AppTest.java
Here is the source for my unit test:
I created an interface I called InputReader to help me test the different assignments against the same input files.package com.tynt.app;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.*;
import java.util.*;
import com.tynt.app.util.*;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Test each assignment with input files
*/
public void testApp()
{
Listreaders = new ArrayList ();
Assignment1 assignment1 = new Assignment1();
Assignment2 assignment2 = new Assignment2();
Assignment3 assignment3 = new Assignment3();
Assignment4 assignment4 = new Assignment4();
Assignment5 assignment5 = new Assignment5();
readers.add(assignment1);
readers.add(assignment2);
readers.add(assignment3);
readers.add(assignment4);
readers.add(assignment5);
readerTest(readers,"TestData.txt");
try {
readerTest(readers,"BadInput.txt");
fail("Bad input should throw RuntimeException");
} catch (RuntimeException e) {
assertTrue(true);
}
}
public void readerTest(Listreaders, String resource) {
for (InputReader inputReader : readers) {
InputStream is = getClass().getClassLoader().getResourceAsStream(resource);
String result = inputReader.readFile(is);
System.out.println(result);
}
}
}
I then stubbed out the Assignment1-5 java classes which implement the InputReader interface and ran the package goal for maven using a maven eclipse plugin to fix any typos and get a baseline for beginning implementation.package com.tynt.app.util;
import java.io.*;
public interface InputReader {
public static final String INPUT_FILE = "THire_input.txt";
public static final String OUTPUT_FILE = "THire_histogram.txt";
public static final String NEW_LINE = System.getProperty("line.separator");
/**
* Reads the InputStream parameter and returns a string of the contents
*
* @param is
* InputStream to read from
* @return String of the processed contents of InputStream
*/
public String readFile(InputStream is);
}
No comments:
Post a Comment