diff --git a/TestSmellExamples.md b/TestSmellExamples.md
index 4bb411f..af09ddf 100644
--- a/TestSmellExamples.md
+++ b/TestSmellExamples.md
@@ -26,7 +26,7 @@ Provided below are examples of test smells that were detected in open source And
- [Sensitive Equality](#sensitive-equality)
-- [Unknown Test](#unknown-test) TODO: repleace with: net.cyclestreets / libraries/cyclestreets-core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientIntegrationTest.java
+- [Unknown Test](#unknown-test) TODO: repleace with: net.cyclestreets / libraries/cyclestreets-testsmell.core/src/test/java/net/cyclestreets/api/client/RetrofitApiClientIntegrationTest.java
- [Verbose Test (Long Test)](#verbose-test-long-test)
@@ -34,7 +34,7 @@ Provided below are examples of test smells that were detected in open source And
- TODO: Default Test (com.app.missednotificationsreminder / app/src/test/java/com/app/missednotificationsreminder/ExampleUnitTest.java)
-- TODO: Constructor Initialization (org.briarproject.briar.beta / bramble-core/src/test/java/org/briarproject/bramble/crypto/TagEncodingTest.java)
+- TODO: Constructor Initialization (org.briarproject.briar.beta / bramble-testsmell.core/src/test/java/org/briarproject/bramble/crypto/TagEncodingTest.java)
- TODO: Ignored Test
@@ -369,9 +369,9 @@ The test method, `testTrue()`, will always pass as since the assert statement co
App: [com.liveplayergames.finneypoker](https://github.com/liveplayergames/UFP)
-Test File: [RLPTest.java](https://github.com/liveplayergames/UFP/blob/master/android/ethereumj-core/src/test/java/org/ethereum/util/RLPTest.java)
+Test File: [RLPTest.java](https://github.com/liveplayergames/UFP/blob/master/android/ethereumj-testsmell.core/src/test/java/org/ethereum/util/RLPTest.java)
-Production File: [RLP.java](https://github.com/liveplayergames/UFP/blob/master/android/ethereumj-core/src/main/java/org/ethereum/util/RLP.java)
+Production File: [RLP.java](https://github.com/liveplayergames/UFP/blob/master/android/ethereumj-testsmell.core/src/main/java/org/ethereum/util/RLP.java)
##### Code Snippet
diff --git a/pom.xml b/pom.xml
index a1fa17c..633bc78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -160,6 +160,11 @@
3.2.4
test
+
+ commons-io
+ commons-io
+ 2.4
+
-
\ No newline at end of file
+
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index eacb5b7..1e7b4da 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,112 +1,13 @@
-import testsmell.AbstractSmell;
-import testsmell.ResultsWriter;
-import testsmell.TestFile;
-import testsmell.TestSmellDetector;
-import thresholds.DefaultThresholds;
-import thresholds.Thresholds;
+import testsmell.core.QualityMonitoringApplication;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+/**
+ * entry point when executing via command line
+ */
public class Main {
- public static void main(String[] args) throws IOException {
- if (args == null) {
- System.out.println("Please provide the file containing the paths to the collection of test files");
- return;
- }
- if (!args[0].isEmpty()) {
- File inputFile = new File(args[0]);
- if (!inputFile.exists() || inputFile.isDirectory()) {
- System.out.println("Please provide a valid file containing the paths to the collection of test files");
- return;
- }
- }
-
- TestSmellDetector testSmellDetector = new TestSmellDetector(new DefaultThresholds());
-
- /*
- Read the input file and build the TestFile objects
- */
- BufferedReader in = new BufferedReader(new FileReader(args[0]));
- String str;
-
- String[] lineItem;
- TestFile testFile;
- List testFiles = new ArrayList<>();
- while ((str = in.readLine()) != null) {
- // use comma as separator
- lineItem = str.split(",");
-
- //check if the test file has an associated production file
- if (lineItem.length == 2) {
- testFile = new TestFile(lineItem[0], lineItem[1], "");
- } else {
- testFile = new TestFile(lineItem[0], lineItem[1], lineItem[2]);
- }
-
- testFiles.add(testFile);
- }
-
- /*
- Initialize the output file - Create the output file and add the column names
- */
- ResultsWriter resultsWriter = ResultsWriter.createResultsWriter();
- List columnNames;
- List columnValues;
-
- columnNames = testSmellDetector.getTestSmellNames();
- columnNames.add(0, "App");
- columnNames.add(1, "TestClass");
- columnNames.add(2, "TestFilePath");
- columnNames.add(3, "ProductionFilePath");
- columnNames.add(4, "RelativeTestFilePath");
- columnNames.add(5, "RelativeProductionFilePath");
- columnNames.add(6, "NumberOfMethods");
- resultsWriter.writeColumnName(columnNames);
-
- /*
- Iterate through all test files to detect smells and then write the output
- */
- TestFile tempFile;
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- Date date;
- for (TestFile file : testFiles) {
- date = new Date();
- System.out.println(dateFormat.format(date) + " Processing: " + file.getTestFilePath());
- System.out.println("Processing: " + file.getTestFilePath());
-
- //detect smells
- tempFile = testSmellDetector.detectSmells(file);
-
- //write output
- columnValues = new ArrayList<>();
- columnValues.add(file.getApp());
- columnValues.add(file.getTestFileName());
- columnValues.add(file.getTestFilePath());
- columnValues.add(file.getProductionFilePath());
- columnValues.add(file.getRelativeTestFilePath());
- columnValues.add(file.getRelativeProductionFilePath());
- columnValues.add(String.valueOf(file.getNumberOfTestMethods()));
- for (AbstractSmell smell : tempFile.getTestSmells()) {
- try {
- columnValues.add(String.valueOf(smell.getNumberOfSmellyTests()));
- } catch (NullPointerException e) {
- columnValues.add("");
- }
- }
- resultsWriter.writeLine(columnValues);
- }
-
- System.out.println("end");
+ public static void main(String[] args) throws IOException {
+ QualityMonitoringApplication.main(args);
}
-
-
}
diff --git a/src/main/java/testsmell/AbstractSmell.java b/src/main/java/testsmell/AbstractSmell.java
index 5ecd65f..bb1bb03 100644
--- a/src/main/java/testsmell/AbstractSmell.java
+++ b/src/main/java/testsmell/AbstractSmell.java
@@ -8,8 +8,8 @@
import java.util.Set;
public abstract class AbstractSmell {
- protected Thresholds thresholds;
- protected Set smellyElementsSet;
+ protected final Thresholds thresholds;
+ protected final Set smellyElementsSet;
public AbstractSmell(Thresholds thresholds) {
this.thresholds = thresholds;
diff --git a/src/main/java/testsmell/DetectionThresholds.java b/src/main/java/testsmell/DetectionThresholds.java
index db1aefd..f11ae9a 100644
--- a/src/main/java/testsmell/DetectionThresholds.java
+++ b/src/main/java/testsmell/DetectionThresholds.java
@@ -6,13 +6,13 @@
*/
public class DetectionThresholds {
- public static int EAGER_TEST = 4;
- public static int ASSERTION_ROULETTE = 3;
- public static int VERBOSE_TEST = 13;
- public static int CONDITIONAL_TEST_LOGIC = 0;
- public static int MAGIC_NUMBER_TEST = 0;
- public static int GENERAL_FIXTURE = 0;
- public static int MYSTERY_GUEST = 0;
- public static int RESOURCE_OPTIMISM = 0;
- public static int SLEEPY_TEST = 0;
+ public static final int EAGER_TEST = 4;
+ public static final int ASSERTION_ROULETTE = 3;
+ public static final int VERBOSE_TEST = 13;
+ public static final int CONDITIONAL_TEST_LOGIC = 0;
+ public static final int MAGIC_NUMBER_TEST = 0;
+ public static final int GENERAL_FIXTURE = 0;
+ public static final int MYSTERY_GUEST = 0;
+ public static final int RESOURCE_OPTIMISM = 0;
+ public static final int SLEEPY_TEST = 0;
}
diff --git a/src/main/java/testsmell/ResultsWriter.java b/src/main/java/testsmell/ResultsWriter.java
index e980397..fa97be7 100644
--- a/src/main/java/testsmell/ResultsWriter.java
+++ b/src/main/java/testsmell/ResultsWriter.java
@@ -1,8 +1,11 @@
package testsmell;
+import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.text.DateFormat;
import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
@@ -10,18 +13,30 @@
* This class is utilized to write output to a CSV file
*/
public class ResultsWriter {
+ private static final DateFormat dateFormatForOutput = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
+
+ private final File outputFile;
+ private final StringBuilder output = new StringBuilder();
- private String outputFile;
- private FileWriter writer;
/**
* Creates the file into which output it to be written into. Results from each file will be stored in a new file
* @throws IOException
*/
- private ResultsWriter() throws IOException {
- String time = String.valueOf(Calendar.getInstance().getTimeInMillis());
- outputFile = MessageFormat.format("{0}_{1}_{2}.{3}", "Output","TestSmellDetection",time, "csv");
- writer = new FileWriter(outputFile,false);
+ private ResultsWriter() {
+ String time = dateFormatForOutput.format(Calendar.getInstance().getTime());
+ outputFile = new File(".", MessageFormat.format("{0}_{1}_{2}.{3}", "Output","TestSmellDetection",time, "csv"));
+ }
+
+ public void save(){
+
+ try (FileWriter writer = new FileWriter(outputFile,false)){
+ writer.write(output.toString());
+ writer.flush();
+ System.out.println("saved: " + outputFile.getCanonicalPath());
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
/**
@@ -57,18 +72,19 @@ public void writeLine(List columnValues) throws IOException {
* @throws IOException
*/
private void writeOutput(List dataValues)throws IOException {
- writer = new FileWriter(outputFile,true);
for (int i=0; i data;
+ private final Map data;
public TestClass(String className) {
this.className = className;
diff --git a/src/main/java/testsmell/TestFile.java b/src/main/java/testsmell/TestFile.java
index 9404bc0..f226943 100644
--- a/src/main/java/testsmell/TestFile.java
+++ b/src/main/java/testsmell/TestFile.java
@@ -7,10 +7,30 @@
import java.util.List;
public class TestFile {
- private String app, testFilePath, productionFilePath;
- private List testSmells;
+ private final String app, testFilePath, productionFilePath;
+ private final List testSmells;
private int numberOfTestMethods = 0;
+ public TestFile(String app, String testFilePath) {
+ this(app, testFilePath, "");
+ }
+ public TestFile(String app, String testFilePath, String productionFilePath) {
+ if (new File(app).exists()) {
+ File appFile = createFromExistingFile(new File(app));
+ this.app = appFile.getName();
+ this.testFilePath = createFromExistingFile(new File(appFile, testFilePath)).getPath();
+ if (productionFilePath.isEmpty()) {
+ this.productionFilePath = "";
+ } else {
+ this.productionFilePath = createFromExistingFile(new File(appFile , productionFilePath)).getPath();
+ }
+ } else {
+ this.app = app;
+ this.testFilePath = testFilePath;
+ this.productionFilePath = productionFilePath;
+ }
+ this.testSmells = new ArrayList<>();
+ }
public String getApp() {
return app;
}
@@ -31,11 +51,14 @@ public boolean getHasProductionFile() {
return ((productionFilePath != null && !productionFilePath.isEmpty()));
}
- public TestFile(String app, String testFilePath, String productionFilePath) {
- this.app = app;
- this.testFilePath = testFilePath;
- this.productionFilePath = productionFilePath;
- this.testSmells = new ArrayList<>();
+
+ private static File createFromExistingFile(File file) {
+ try {
+ return file.getCanonicalFile();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException("should not occur");
+ }
}
public void addSmell(AbstractSmell smell) {
@@ -121,4 +144,4 @@ public int getNumberOfTestMethods() {
public void setNumberOfTestMethods(int numberOfTestMethods) {
this.numberOfTestMethods = numberOfTestMethods;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/testsmell/TestMethod.java b/src/main/java/testsmell/TestMethod.java
index 8c2732d..c7772f4 100644
--- a/src/main/java/testsmell/TestMethod.java
+++ b/src/main/java/testsmell/TestMethod.java
@@ -5,9 +5,9 @@
public class TestMethod extends SmellyElement {
- private String methodName;
+ private final String methodName;
private boolean hasSmell;
- private Map data;
+ private final Map data;
public TestMethod(String methodName) {
this.methodName = methodName;
diff --git a/src/main/java/testsmell/TestSmellDetector.java b/src/main/java/testsmell/TestSmellDetector.java
index a067e2f..bc660f2 100644
--- a/src/main/java/testsmell/TestSmellDetector.java
+++ b/src/main/java/testsmell/TestSmellDetector.java
@@ -17,7 +17,7 @@
public class TestSmellDetector {
private List testSmells;
- private Thresholds thresholds;
+ private final Thresholds thresholds;
/**
* Instantiates the various test smell analyzer classes and loads the objects into an list.
@@ -27,11 +27,11 @@ public class TestSmellDetector {
*/
public TestSmellDetector(Thresholds thresholds) {
this.thresholds = thresholds;
- initializeSmells();
+ testSmells = createTestSmells();
}
- private void initializeSmells() {
- testSmells = new ArrayList<>();
+ private List createTestSmells() {
+ List testSmells = new ArrayList<>();
testSmells.add(new AssertionRoulette(thresholds));
testSmells.add(new ConditionalTestLogic(thresholds));
testSmells.add(new ConstructorInitialization(thresholds));
@@ -53,6 +53,7 @@ private void initializeSmells() {
testSmells.add(new ResourceOptimism(thresholds));
testSmells.add(new MagicNumberTest(thresholds));
testSmells.add(new DependentTest(thresholds));
+ return testSmells;
}
public void setTestSmells(List testSmells) {
diff --git a/src/main/java/testsmell/core/ProjectMonitoringInputGenerator.java b/src/main/java/testsmell/core/ProjectMonitoringInputGenerator.java
new file mode 100644
index 0000000..01d5f2c
--- /dev/null
+++ b/src/main/java/testsmell/core/ProjectMonitoringInputGenerator.java
@@ -0,0 +1,44 @@
+package testsmell.core;
+
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * can generate input for monitoring from any given project root directory (assuming default Java project structure)
+ */
+public class ProjectMonitoringInputGenerator {
+ private final List sourceFileList = new ArrayList<>();
+ private final List inputList = new ArrayList<>();
+ private final StringBuilder text = new StringBuilder();
+
+ public ProjectMonitoringInputGenerator(File directory) throws IOException {
+
+ sourceFileList.addAll(FileUtils.listFiles(new File(directory, "src/test"), "java".split(","), true));
+ for (File sourceFile : sourceFileList) {
+ String localSource = sourceFile.getPath().substring(directory.getPath().length()).replace("\\", "/").replace("/src/test/java/", "");
+ localSource = localSource.replace("Test.java", ".java");
+ File file = new File(directory, "src/main/java/" + localSource);
+
+ String line;
+ if (file.exists()) {
+ line = directory.getName() + "," + sourceFile.getPath().replace("\\", "/") + "," + file.getPath().replace("\\", "/");
+ } else {
+ line = directory.getName() + "," + sourceFile.getPath().replace("\\", "/");
+ }
+ inputList.add(line);
+ text.append(line).append("\n");
+ }
+ }
+
+ public List getInputList() {
+ return inputList;
+ }
+
+ public String getText() {
+ return text.toString();
+ }
+}
diff --git a/src/main/java/testsmell/core/ProjectsCsvReader.java b/src/main/java/testsmell/core/ProjectsCsvReader.java
new file mode 100644
index 0000000..e06ddae
--- /dev/null
+++ b/src/main/java/testsmell/core/ProjectsCsvReader.java
@@ -0,0 +1,42 @@
+package testsmell.core;
+
+import testsmell.TestFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Read the input file and build the TestFile objects
+ */
+public class ProjectsCsvReader {
+ private final List testFiles = new ArrayList<>();
+
+ public ProjectsCsvReader(File filePath) throws IOException {
+ this(Files.readAllLines(filePath.toPath()));
+ }
+ public ProjectsCsvReader(List lines ) {
+ for (String line: lines) {
+ testFiles.add(createTestFileFromCsvLine(line));
+ }
+ }
+ public TestFile createTestFileFromCsvLine(String line) {
+ // use comma as separator
+
+ String[] lineItem = line.split(",");
+ TestFile testFile;
+ //check if the test file has an associated production file
+ if (lineItem.length == 2) {
+ testFile = new TestFile(lineItem[0], lineItem[1]);
+ } else {
+ testFile = new TestFile(lineItem[0], lineItem[1], lineItem[2]);
+ }
+ return testFile;
+ }
+
+ public List getTestFiles() {
+ return testFiles;
+ }
+}
diff --git a/src/main/java/testsmell/core/QualityMonitoringApplication.java b/src/main/java/testsmell/core/QualityMonitoringApplication.java
new file mode 100644
index 0000000..38a95d9
--- /dev/null
+++ b/src/main/java/testsmell/core/QualityMonitoringApplication.java
@@ -0,0 +1,61 @@
+package testsmell.core;
+
+import testsmell.ResultsWriter;
+import testsmell.TestFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.List;
+
+/**
+ * Application generates a CSV report with data on the code smells in the unit tests of a selected project.
+ */
+public class QualityMonitoringApplication {
+
+ public static void main(String[] args) {
+ File inputFile = new File(".");
+ boolean isArgumentWithTargetName = args != null && args.length > 0 && args[0].isEmpty();
+ if (isArgumentWithTargetName) {
+ inputFile = new File(args[0]);
+ }
+
+ QualityMonitoringApplication application = new QualityMonitoringApplication();
+ if (!inputFile.exists()) {
+ throw new RuntimeException("Please provide a valid file containing the paths to the collection of test files");
+ }
+ if (inputFile.isDirectory()) {
+ application.processProject(inputFile);
+ } else {
+ application.processProjectViaCsvFile(inputFile);
+ }
+ }
+
+ public void processProject(File directory) {
+ try {
+ ProjectMonitoringInputGenerator inputGenerator = new ProjectMonitoringInputGenerator(directory);
+ ResultsWriter writer = createProcessedResultsWriter(inputGenerator.getInputList());
+ writer.save();
+ } catch (Exception ex) {
+ throw new RuntimeException("Error: " + ex.getMessage());
+ }
+ }
+
+ public void processProjectViaCsvFile(File file) {
+ try {
+ ResultsWriter writer = createProcessedResultsWriter(Files.readAllLines(file.toPath()));
+ writer.save();
+ System.out.println("processed: " + file);
+ } catch (Exception ex) {
+ throw new RuntimeException("Error: " + ex.getMessage());
+ }
+ }
+
+ List createTestFilesFromLines(List lines) {
+ return new ProjectsCsvReader(lines).getTestFiles();
+ }
+
+ ResultsWriter createProcessedResultsWriter(List lines) throws IOException {
+ return new SmellDetectionWriter(createTestFilesFromLines(lines)).createProcessedResultsWriter();
+ }
+}
diff --git a/src/main/java/testsmell/core/SmellDetectionWriter.java b/src/main/java/testsmell/core/SmellDetectionWriter.java
new file mode 100644
index 0000000..3b981c0
--- /dev/null
+++ b/src/main/java/testsmell/core/SmellDetectionWriter.java
@@ -0,0 +1,89 @@
+package testsmell.core;
+
+import testsmell.AbstractSmell;
+import testsmell.ResultsWriter;
+import testsmell.TestFile;
+import testsmell.TestSmellDetector;
+import thresholds.DefaultThresholds;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Iterates through all given test files to detect smells
+ * Can save output to a file
+ */
+public class SmellDetectionWriter {
+ private static final DateFormat dateFormatForOutput = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
+
+ private final TestSmellDetector testSmellDetector ;
+ private final List monitoredJavaFiles;
+
+ public SmellDetectionWriter(List testFiles) {
+ this(testFiles, new TestSmellDetector(new DefaultThresholds()));
+ }
+ public SmellDetectionWriter(List testFiles, TestSmellDetector testSmellDetector ) {
+ this.monitoredJavaFiles = testFiles;
+ this.testSmellDetector = testSmellDetector;
+ }
+
+ private ResultsWriter createStartingResultsWriter() throws IOException{
+ ResultsWriter resultsWriter = ResultsWriter.createResultsWriter();
+ List columnNames;
+ columnNames = testSmellDetector.getTestSmellNames();
+ columnNames.add(0, "App");
+ columnNames.add(1, "TestClass");
+ columnNames.add(2, "TestFilePath");
+ columnNames.add(3, "ProductionFilePath");
+ columnNames.add(4, "RelativeTestFilePath");
+ columnNames.add(5, "RelativeProductionFilePath");
+ columnNames.add(6, "NumberOfMethods");
+ resultsWriter.writeColumnName(columnNames);
+ return resultsWriter;
+ }
+
+ public ResultsWriter createProcessedResultsWriter() throws IOException {
+
+ ResultsWriter resultsWriter = createStartingResultsWriter();
+
+ /*
+ Iterate through all test files to detect smells
+ */
+
+ for (TestFile file : monitoredJavaFiles) {
+ resultsWriter.writeLine(createColumnValues(file));
+ }
+ return resultsWriter;
+ }
+
+ private List createColumnValues(TestFile file) throws IOException{
+ Date date = new Date();
+ System.out.println(dateFormatForOutput.format(date) + " Processing: " + file.getTestFilePath());
+ System.out.println("Processing: " + file.getTestFilePath());
+
+ //detect smells
+ TestFile tempFile = testSmellDetector.detectSmells(file);
+
+ //write output
+ List columnValues = new ArrayList<>();
+ columnValues.add(file.getApp());
+ columnValues.add(file.getTestFileName());
+ columnValues.add(file.getTestFilePath());
+ columnValues.add(file.getProductionFilePath());
+ columnValues.add(file.getRelativeTestFilePath());
+ columnValues.add(file.getRelativeProductionFilePath());
+ columnValues.add(String.valueOf(file.getNumberOfTestMethods()));
+ for (AbstractSmell smell : tempFile.getTestSmells()) {
+ try {
+ columnValues.add(String.valueOf(smell.getNumberOfSmellyTests()));
+ } catch (NullPointerException e) {
+ columnValues.add("");
+ }
+ }
+ return columnValues;
+ }
+}
diff --git a/src/test/java/testsmell/TestFileTest.java b/src/test/java/testsmell/TestFileTest.java
index b05a487..44de733 100644
--- a/src/test/java/testsmell/TestFileTest.java
+++ b/src/test/java/testsmell/TestFileTest.java
@@ -1,10 +1,13 @@
package testsmell;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
+import java.io.File;
+
import static org.junit.jupiter.api.Assertions.*;
class TestFileTest {
@@ -89,4 +92,35 @@ public void testGetRelativeTestFilePathWindows() {
String output = testFileWindows.getRelativeTestFilePath();
assertEquals(oracle, output);
}
-}
\ No newline at end of file
+
+ @Test
+ public void testWhenTestFileCreated() {
+ // given
+ String mainJava = TestFile.class.getName().replace(".","/") + ".java";
+ String testJava = TestFileTest.class.getName().replace(".","/")+ ".java";
+ String inputMain = "./src/main/java/" +mainJava;
+ String inputTest = "./src/test/java/" +testJava;
+ String relativeMainPath = inputMain.replace("./","").replace("/",File.separator);
+ String relativeTestPath = inputTest.replace("./","").replace("/",File.separator);
+
+ // when
+ TestFile testFile = new TestFile(".", inputTest, inputMain );
+
+ // then
+ File actualProdFile = new File(testFile.getProductionFilePath());
+ File actualTestFile = new File(testFile.getTestFilePath());
+ Assertions.assertTrue(actualProdFile.exists());
+ Assertions.assertTrue(actualTestFile.exists());
+ Assertions.assertNotEquals(testFile.getApp(),".");
+ Assertions.assertTrue(testFile.getHasProductionFile());
+ Assertions.assertEquals(testFile.getNumberOfTestMethods(), 0);
+ Assertions.assertEquals(testFile.getTestSmells().size(),0);
+ Assertions.assertEquals(testFile.getTestFileNameWithoutExtension(),TestFileTest.class.getSimpleName());
+ Assertions.assertEquals(testFile.getProductionFileNameWithoutExtension(),TestFile.class.getSimpleName());
+ Assertions.assertEquals(testFile.getProductionFileName(),actualProdFile.getName());
+ Assertions.assertEquals(testFile.getTestFileName(),actualTestFile.getName());
+ Assertions.assertEquals(testFile.getRelativeProductionFilePath(),relativeMainPath);
+ Assertions.assertEquals(testFile.getRelativeTestFilePath(),relativeTestPath);
+
+ }
+}
diff --git a/src/test/java/testsmell/core/QualityMonitoringApplicationTest.java b/src/test/java/testsmell/core/QualityMonitoringApplicationTest.java
new file mode 100644
index 0000000..b5e2826
--- /dev/null
+++ b/src/test/java/testsmell/core/QualityMonitoringApplicationTest.java
@@ -0,0 +1,63 @@
+package testsmell.core;
+
+import testsmell.ResultsWriter;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Logger;
+
+
+public class QualityMonitoringApplicationTest {
+ private Logger logger = Logger.getAnonymousLogger();
+ private QualityMonitoringApplication mainApplication = new QualityMonitoringApplication();
+
+ @Test
+ public void whenInvalidInputNoCsvProcessing() {
+ Assertions.assertThrows(RuntimeException.class, ()->{
+ mainApplication.processProjectViaCsvFile(new File("."));
+ });
+ }
+
+ @Test
+ public void whenInvalidInputNoProjectProcessing() {
+ Assertions.assertThrows(RuntimeException.class, ()->{
+ mainApplication.processProject(new File("./TESTING"));
+ });
+ }
+
+ @Test
+ public void when3SampleLinesThen3Files() {
+ List sampleLines = Arrays.asList("p,a1,a2\np,b1\np,c1,c2".split("\n"));
+ Assertions.assertEquals(mainApplication.createTestFilesFromLines(sampleLines).size(), 3);
+ }
+
+ @Test
+ public void whenEmptyProjectThenEmptyOutcomes() throws IOException {
+
+ ResultsWriter resultsWriter = mainApplication.createProcessedResultsWriter(new ArrayList<>());
+
+ Assertions.assertEquals(resultsWriter.getOutput().split("\n").length, 1);
+ }
+
+ @Test
+ public void whenRealLinesThenRealOutcomes() throws IOException {
+ // given:
+ ProjectMonitoringInputGenerator inputGenerator = new ProjectMonitoringInputGenerator(new File("."));
+ List inputList = inputGenerator.getInputList();
+ logger.info("input: "+inputGenerator.getText());
+
+ // when:
+ ResultsWriter resultsWriter = mainApplication.createProcessedResultsWriter(inputList);
+ logger.info("output: "+resultsWriter.getOutput());
+
+ // then:
+ Assertions.assertEquals(resultsWriter.getOutput().split("\n").length, 1+inputList.size());
+ }
+
+
+}