Skip to content

Commit

Permalink
Adding test framework and Unit test for Core functionality:
Browse files Browse the repository at this point in the history
*Added first test with Junit
*Added core test with Junit
*Updated CONTRIBUTING.md with testing instruction
  • Loading branch information
irenejoeunpark committed Nov 12, 2021
1 parent be449b1 commit cb9a626
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 6 deletions.
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -52,6 +52,23 @@ java -jar out\artifacts\ssgApplication_jar\ssgApplication.jar -c <configFileName
>2. Install and enable the plugin
>3. Reformat the Code by "CTRL+ALT+L" in the file you worked on
### Testing

To test the code :
1. Run "testProcessInput" in HTMLBuilderTest.java

2. Fix any error that does not pass the testing

3. Click [here](https://junit.org/junit5/docs/current/user-guide/) for more information for Junit testing framework

To create a unit test :

Right click the class name in the code, and select Show Context Action
Select >Create Test< and select the function you want to add
Add testing to the corresponding testclass



### Fix Linter

>1. Run ```mvn spotbugs:gui``` to spot the area of improvement in a SpotBug UI
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Expand Up @@ -45,6 +45,18 @@
<version>4.13.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>20030203.000550</version>
<scope>compile</scope>
</dependency>
</dependencies>


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/company/HTMLBuilder.java
Expand Up @@ -11,7 +11,7 @@

public class HTMLBuilder {

static void processInput(String inputFile, String output) {
public static void processInput(String inputFile, String output) {
if (inputFile.endsWith(".txt")) {
//Single file
File file = new File(inputFile);
Expand Down Expand Up @@ -39,7 +39,7 @@ static void processInput(String inputFile, String output) {
}
}

static String fileNameReader(String[] str) {
public static String fileNameReader(String[] str) {
//convert string array to string with the space
StringBuilder s = new StringBuilder();
for (String arg : str) {
Expand Down
21 changes: 17 additions & 4 deletions src/test/java/HTMLBuilderTest.java
@@ -1,22 +1,35 @@
import com.company.HTMLBuilder;
import org.junit.jupiter.api.Test;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

class HTMLBuilderTest {

@Test
void processInput() {
void testProcessInput() throws IOException {
HTMLBuilder.processInput("sources/Sample.txt","testDir");
File target = new File("dist/Sample.html");
assertTrue(FileUtils.contentEquals(target,new File("testDir/Sample.html")));
}

@Test
void fileNameReader() {
void testFileNameReader() {
String[] fileName1 = {"example", "file", "name.txt"};
assertEquals("example file name.txt",HTMLBuilder.fileNameReader(fileName1));

String[] fileName2 = {"sample.md"};
assertEquals("sample.md",HTMLBuilder.fileNameReader(fileName2));
}

@Test
void writeHtmlHeader() {
void testWriteHtmlHeader() {
}

@Test
void writeHtmlFoot() {
void testWriteHtmlFoot() {
}
}
34 changes: 34 additions & 0 deletions src/test/java/com/company/TextUtilsTest.java
@@ -0,0 +1,34 @@
package com.company;

import org.junit.jupiter.api.Test;

import java.io.*;

import static org.junit.jupiter.api.Assertions.*;

class TextUtilsTest {

@Test
void createHtmlFromTxt() throws IOException {
File targetText = new File("/testDir/targetText.txt");
File txtFile = new File("/testDir/sample.txt");
File htmlFile = new File("/testDir/sample.html");
htmlFile.createNewFile();
BufferedWriter writeSample = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(txtFile), "UTF-8"));
writeSample.write("This is a Title of the Sample Text");
writeSample.newLine();
writeSample.newLine();
writeSample.write("First Paragraph.");
writeSample.write("This is a sample test");
writeSample.newLine();
writeSample.write("2. Sample text");
writeSample.newLine();
writeSample.close();

TextUtils.createHtmlFromTxt(txtFile,"");


BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("testDir/sample.html"), "UTF-8"));
System.out.println(reader.readLine());
}
}
Empty file added testDir/sample.html
Empty file.
4 changes: 4 additions & 0 deletions testDir/sample.txt
@@ -0,0 +1,4 @@
This is a Title of the Sample Text

First Paragraph.This is a sample test
2. Sample text

0 comments on commit cb9a626

Please sign in to comment.