Skip to content

Instantly share code, notes, and snippets.

@ejknapp
Created October 13, 2010 19:40
Show Gist options
  • Save ejknapp/624736 to your computer and use it in GitHub Desktop.
Save ejknapp/624736 to your computer and use it in GitHub Desktop.
SupperAbbrevs script for making a test class
package java112.tests;
import java.util.*;
import java.io.*;
import java112.analyzer.*;
/**
* @author <#=AUTHOR#>
* class Test$1
*
*/
public class Test${1:name} {
public void run() {
Properties properties = createAndConfigureProperties();
Analyzer analyzer = createAnalyzerAndAddTokens(properties);
createOutputForAnalyzer(analyzer);
testAnalyzerOutput(properties);
tearDownTest(properties);
}
private Properties createAndConfigureProperties() {
Properties properties = new Properties();
properties.setProperty("file.name.${2:fileName}", "testOutput/$3.txt");
properties.setProperty("directory.output", "output/");
return properties;
}
private Analyzer createAnalyzerAndAddTokens(Properties properties) {
Analyzer analyzer = new $1(properties);
analyzer.processToken("one");
analyzer.processToken("two");
analyzer.processToken("three");
return analyzer;
}
private void createOutputForAnalyzer(Analyzer analyzer) {
String inputFilePath = "testInputFile";
analyzer.writeOutput(inputFilePath);
}
private void testAnalyzerOutput(Properties properties) {
//open generated test output file
BufferedReader testIn = null;
String outputFilePath = properties.getProperty("directory.output")
+ properties.getProperty("file.name.$2");
try {
testIn = new BufferedReader(new FileReader(outputFilePath));
System.out.println("$1 Test file created - Success");
if (testIn.ready()){
System.out.println("$1 Test File Readable - Success");
testOutputFileContent(testIn);
} else {
System.out.println("$1 Test File Readable - Failure");
}
} catch (java.io.FileNotFoundException fnfe) {
System.out.println("name Test file created - Failure");
} catch (java.io.IOException ioe) {
System.out.println("name Test file created - Failure");
}
finally {
try {
if (testIn != null) {
testIn.close();
}
System.out.println("$1 Test File Closes - Success");
} catch (Exception e) {
System.out.println("$1 Test File Closes - Failure");
}
}
}
private void testOutputFileContent(BufferedReader testIn) throws IOException {
//tests go here
$end
}
private void tearDownTest(Properties properties) {
String outputFilePath = properties.getProperty("directory.output")
+ properties.getProperty("file.name.$2");
File testFile = new File(outputFilePath);
testFile.delete();
}
public static void main(String[] args) {
Test$1 test = new Test$1();
test.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment