// confirm input from stdin
if (confirmToExecute() > 0) {
return;
}
FileReader fileReader = new CommonsIOFileReader();
TestCaseGenerator testCaseGenerator = new DefaultTestCaseGenerator(config);
for (File javaFile : javaFiles) {
if (isNeedToExclude(javaFile)) {
continue;
}
File testFile = null;
String currentTestCaseSourceCode = null;
try {
testFile = new File(javaFile
.getAbsolutePath()
.replaceAll("\\\\", "/")
.replaceFirst(getDirectoryPathOfProductSourceCode(config),
getDirectoryPathOfTestSourceCode(config)).replaceFirst("\\.java", "Test.java"));
currentTestCaseSourceCode = fileReader.readAsString(testFile);
} catch (Exception e) {
}
testCaseGenerator.initialize(fileReader.readAsString(javaFile));
String testCodeString = null;
if (currentTestCaseSourceCode != null) {
testCodeString = testCaseGenerator
.getTestCaseSourceCodeWithLackingTestMethod(currentTestCaseSourceCode);
if (!testCodeString.equals(currentTestCaseSourceCode)) {
Stdout.p(" Modified: " + testFile.getAbsolutePath());
new CommonsIOFileWriter(testFile).writeText(testCodeString);
}
} else {
testCodeString = testCaseGenerator.getNewTestCaseSourceCode();
Stdout.p(" Created: " + testFile.getAbsolutePath());
new CommonsIOFileWriter(testFile).writeText(testCodeString);
}
}
}