Skip to content

Commit

Permalink
Merge pull request #52 from flipturnapps/junit2
Browse files Browse the repository at this point in the history
Java test import statements merge
  • Loading branch information
Kevin Kellar committed Aug 12, 2015
2 parents d064d02 + 92ece69 commit 05fa1a4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
54 changes: 53 additions & 1 deletion src/JUnitTestCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class JUnitTestCreator
private HashMap<Integer, ArrayList<String>> javaCodePiecesMap;
private HashMap<Integer, String> poolwideMap;
private SUTInterface sut;
private ArrayList<String> importLines;


public JUnitTestCreator(int[] actionIds, SUTInterface sut)
Expand Down Expand Up @@ -216,6 +217,46 @@ private void parsePoolEntryMap()
}
}
}

private void parseImportLines()
{
BufferedReader reader = null;
File importLineFile = new File(TstlConstants.fileInDir(TstlConstants.getTstlHomeDir(), TstlConstants.FILE_IMPORTS_SAVE));
importLines = new ArrayList<String>();
try
{
reader = new BufferedReader(new FileReader(importLineFile));
while(true)
{
String line = null;
line = reader.readLine();
if(line != null)
{
importLines.add(line);
}
else
break;
}
}
catch(Exception ex)
{
TstlConstants.log(Level.SEVERE,"Failed to read importlines from file!",ex);
}
finally
{
if(reader != null)
{
try
{
reader.close();
}
catch(Exception ex)
{
TstlConstants.log(Level.WARNING, "Failed to close importlines reader.",ex);
}
}
}
}

public void setActionIds(int[] actionIds)
{
Expand All @@ -226,6 +267,7 @@ public void writeTest()
{
parsePoolEntryMap();
parseJavaCodePiecesMap();
parseImportLines();
String[] initLines = generateLocalVariables();
String[] actionLines = genearateActionLines();
File failureClassFile = new File(TstlConstants.fileInDir(TstlConstants.getPath(TstlConstants.PATHKEY_WORKINGDIR), TstlConstants.FILE_FAILING_TEST_OUTPUT_SOURCE));
Expand All @@ -238,9 +280,17 @@ public void writeTest()
catch(IOException ex)
{
TstlConstants.log(Level.WARNING, "Failed to create failing test source file.", ex);
}
}
if(writer == null)
return;
for (int i = 0; i < importLines.size(); i++)
{
writer.println(importLines.get(i));
}
writer.println("public class " + TstlConstants.FILE_FAILING_TEST_OUTPUT_SOURCE.split(".")[0]);
writer.println("{");
writer.println("public static void main(String[] args0)");
writer.println("{");
for (int i = 0; i < initLines.length; i++)
{
writer.println(initLines[i]);
Expand All @@ -250,6 +300,8 @@ public void writeTest()
{
writer.println(actionLines[i]);
}
writer.println("}//main method closing");
writer.println("}//class closing");
writer.flush();
writer.close();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Repeatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public Repeatable()
public static void writePoolwideMapToFile()
{
File mapFile = new File(TstlConstants.fileInDir(TstlConstants.getTstlHomeDir(), TstlConstants.FILE_POOLWIDE_MAP));
PrintWriter writer = null;
PrintWriter mapWriter = null;
try
{
mapFile.createNewFile();
writer = new PrintWriter(mapFile);
mapWriter = new PrintWriter(mapFile);
}
catch (IOException e)
{
Expand All @@ -33,17 +33,17 @@ public static void writePoolwideMapToFile()
}
finally
{
if(writer == null)
if(mapWriter == null)
return;
}

Integer[] integerPoolIds = poolwideMap.keySet().toArray(new Integer[poolwideMap.size()]);
for (int i = 0; i < integerPoolIds.length; i++)
{
writer.println(integerPoolIds[i] + TstlConstants.SPLIT_SYNTAX_POOLENTRY_ID_AND_CLASSNAME +poolwideMap.get(integerPoolIds[i]));
mapWriter.println(integerPoolIds[i] + TstlConstants.SPLIT_SYNTAX_POOLENTRY_ID_AND_CLASSNAME +poolwideMap.get(integerPoolIds[i]));
}
writer.flush();
writer.close();
mapWriter.flush();
mapWriter.close();
}
public int getId()
{
Expand Down
1 change: 1 addition & 0 deletions src/TstlConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class TstlConstants
public static final int TESTER_CONFIG_DEFAULT_TIMEOUT = 60000;
public static final String TSTL_JAVA = "TSTL-Java";
public static final String VISIBILITY_LEVEL_POOL_VAR = "private";
public static final String FILE_IMPORTS_SAVE = "imports.imp";
public static void closeLogger()
{
if(logFileWriter != null)
Expand Down
23 changes: 22 additions & 1 deletion src/TstlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ private void createOutWriter()
}
private void readImports()
{
File importFile = new File(TstlConstants.fileInDir(TstlConstants.getTstlHomeDir(), TstlConstants.FILE_IMPORTS_SAVE));
PrintWriter importWriter = null;
try
{
importFile.createNewFile();
importWriter = new PrintWriter(importFile);
}
catch (IOException e)
{
TstlConstants.log(Level.SEVERE, "Failed to write import file!", e);
return;
}
finally
{
if(importWriter == null)
return;
}
for (int i = 0; i < tstl.size(); i++)
{
String line = tstl.get(i);
Expand All @@ -186,14 +203,18 @@ private void readImports()
String importObject = line.substring(TstlConstants.IDENTIFIER_IMPORT.length());
if(!(importObject.trim().equals(TstlConstants.IMPORT_ARRAY_LIST) || importObject.trim().equals(TstlConstants.IMPORT_LIST)))
{
writer.println("import " + importObject + ";"+TstlConstants.COMMENT_TSTL_SOURCE_IMPORT);
String importLine = "import " + importObject + ";"+TstlConstants.COMMENT_TSTL_SOURCE_IMPORT;
importWriter.println(importLine);
writer.println(importLine);
}
tstl.remove(i);
i--;
}
}
writer.println("import " + TstlConstants.IMPORT_LIST + ";"+TstlConstants.COMMENT_CORE_FUNCTIONALITY_IMPORT);
writer.println("import " + TstlConstants.IMPORT_ARRAY_LIST + ";"+TstlConstants.COMMENT_CORE_FUNCTIONALITY_IMPORT);
importWriter.flush();
importWriter.close();
}
private void generateClassDeclaration()
{
Expand Down

0 comments on commit 05fa1a4

Please sign in to comment.