From c5f1b96aa22ed3dcc3c464654a5c75752a456f6c Mon Sep 17 00:00:00 2001 From: trangntt-016 Date: Wed, 10 Nov 2021 12:50:42 -0500 Subject: [PATCH] parent 48fad5bcd064e99da20be3a2d67df605a6f82a3a author trangntt-016 1636566642 -0500 committer trangntt-016 1636567642 -0500 Squash all commits into one --- .gitignore | 2 + CONTRIBUTING.md | 17 +- README.md | 2 +- src/main/java/test/com/os/jssg/TestUtils.java | 14 +- .../os/jssg/processor/HTMLProcessorTest.java | 73 ++++++- .../test/com/os/jssg/utils/HTMLUtilsTest.java | 6 +- .../test/com/os/jssg/utils/MDUtilsTest.java | 3 +- .../test/com/os/jssg/utils/TextUtilsTest.java | 2 +- .../{SilverBlaze.txt => Silver Blaze.txt} | 0 src/main/resources/index.html | 197 ++++++++++++++++++ src/main/resources/index_SORT_BY_BLOCK.html | 197 ++++++++++++++++++ .../resources/index_SORT_BY_BLOCK_DESC.html | 197 ++++++++++++++++++ src/main/resources/index_SORT_BY_CLASS.html | 197 ++++++++++++++++++ .../resources/index_SORT_BY_CLASS_DESC.html | 197 ++++++++++++++++++ src/main/resources/index_SORT_BY_LINE.html | 197 ++++++++++++++++++ .../resources/index_SORT_BY_LINE_DESC.html | 197 ++++++++++++++++++ src/main/resources/index_SORT_BY_METHOD.html | 197 ++++++++++++++++++ .../resources/index_SORT_BY_METHOD_DESC.html | 197 ++++++++++++++++++ .../resources/index_SORT_BY_NAME_DESC.html | 197 ++++++++++++++++++ 19 files changed, 2076 insertions(+), 13 deletions(-) rename src/main/resources/SherlockHolmesSelectedStories/{SilverBlaze.txt => Silver Blaze.txt} (100%) create mode 100644 src/main/resources/index.html create mode 100644 src/main/resources/index_SORT_BY_BLOCK.html create mode 100644 src/main/resources/index_SORT_BY_BLOCK_DESC.html create mode 100644 src/main/resources/index_SORT_BY_CLASS.html create mode 100644 src/main/resources/index_SORT_BY_CLASS_DESC.html create mode 100644 src/main/resources/index_SORT_BY_LINE.html create mode 100644 src/main/resources/index_SORT_BY_LINE_DESC.html create mode 100644 src/main/resources/index_SORT_BY_METHOD.html create mode 100644 src/main/resources/index_SORT_BY_METHOD_DESC.html create mode 100644 src/main/resources/index_SORT_BY_NAME_DESC.html diff --git a/.gitignore b/.gitignore index 549e00a..b6695a7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ +/src/main/resources/coverage-report/ +/src/main/resources/output/ ### STS ### .apt_generated diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ff8a7d7..50e554e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ We appreciate your effort and to make sure that your pull request is easy to rev guidelines including legal contributor agreement: * Use JDK 11, [IntelliJ](https://www.jetbrains.com/idea/download/), [Maven 3.8.1](https://maven.apache.org/download.cgi) - , [Picocli 4.6.1](https://picocli.info/) or newer to build the project + , [Picocli 4.6.1](https://picocli.info/), [JUnit5](https://junit.org/junit5/) or newer to build the project * To use Formatter and Eslint in this project, please read this detailed [instruction](https://tracy016.medium.com/osd600-adding-static-analysis-toolings-b8488bf239da) @@ -16,11 +16,22 @@ guidelines including legal contributor agreement: ![image](https://intellij-support.jetbrains.com/hc/user_images/35Aia3Dk3aHoTBe1gB8WIw.png) This will start auto testing. Although this works fine, it takes time to build the project even when my project is tiny so for larger projects it will certainly take very long time to complete the build and execute tests. +* This project has some basic unit tests and still not covers all. + Tests should conform to adequate practices in order to execute as expected, please read [Modern Best Practices for Testing in Java](https://phauer.com/2019/modern-best-practices-testing-java/). + + Tests are required at least for the following components: + + * HTMLProcessors + * HTMLUtils + * JSonUtils + * MDUtils + * TextUtil + +* In Intellij, to view the test coverage, create a folder in resources where you can store your report. Then right click on the root folder of test -> `More Run/Debug -> Run Tests in com.os.jssg with Coverage -> Click on Generate Coverage Report on the left side of popup modal` + ## Legal stuff As a contributor: * You will only submit contributions where you have authored 100% of the content. -* You will only submit contributions to which you have the necessary rights. This means that if you are employed, you - have received the necessary permissions from your employer to make the contributions. * Whatever content you contribute will be provided under the project license(s). \ No newline at end of file diff --git a/README.md b/README.md index 0858d5e..1ca2822 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A simple Static Site Generator (SSG) for generating a complete HTML website from * [Picocli 4.6.1](https://picocli.info/) * [Java 11](https://www.java.com/en/) * [Maven](https://maven.apache.org/) -* PowerShell +* [JUnit5](https://junit.org/junit5/) ## Getting Started ### Prerequisites diff --git a/src/main/java/test/com/os/jssg/TestUtils.java b/src/main/java/test/com/os/jssg/TestUtils.java index cc42d9c..5f12052 100644 --- a/src/main/java/test/com/os/jssg/TestUtils.java +++ b/src/main/java/test/com/os/jssg/TestUtils.java @@ -7,7 +7,7 @@ import java.util.stream.Collectors; public class TestUtils { - public static String generateRandomPath() throws IOException { + public static String generateRandomInputPath() throws IOException { Path filePath = Files.list(Paths.get("./src/main/resources/SherlockHolmesSelectedStories")).findFirst().get(); if (Files.exists(filePath)) { @@ -26,4 +26,16 @@ public static String generateConfigPath() throws IOException { return null; } + + public static String generateOutputPath() { + Path folderPath = Paths.get("./src/main/resources/output"); + + if (Files.exists(folderPath)) { + return folderPath.toString(); + } + + return null; + } + + } diff --git a/src/main/java/test/com/os/jssg/processor/HTMLProcessorTest.java b/src/main/java/test/com/os/jssg/processor/HTMLProcessorTest.java index 2fad753..73ba513 100644 --- a/src/main/java/test/com/os/jssg/processor/HTMLProcessorTest.java +++ b/src/main/java/test/com/os/jssg/processor/HTMLProcessorTest.java @@ -1,12 +1,81 @@ package test.com.os.jssg.processor; +import com.os.jssg.processor.HTMLProcessor; +import com.os.jssg.utils.HTMLUtils; import org.junit.jupiter.api.Test; +import test.com.os.jssg.TestUtils; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; public class HTMLProcessorTest { + private HTMLProcessor processor = new HTMLProcessor(); + private HTMLUtils utils = new HTMLUtils(); + + @Test + void shouldCreateNewFileFromValidPathAndValidOutputPathAndValidLanguage() throws IOException { + String inputPath = TestUtils.generateRandomInputPath(); + + String outputPath = TestUtils.generateOutputPath(); + + String language = "en"; + + // WHEN + processor.convertToHTML(inputPath, outputPath, language); + + // THEN + Path folderPath = Files.list(Paths.get("./src/main/resources/output")).findFirst().get(); + + assertThat(folderPath).exists().toString().endsWith(".html"); + + // clean directory after the test + utils.cleanDirectory(Paths.get(outputPath)); + } + + @Test + void shouldCreateNoFilesFromInValidPathAndValidOutputPathAndValidLanguage() throws IOException { + String inputPath = "invalid filepath"; + + String outputPath = TestUtils.generateOutputPath(); + + String language = "en"; + + // WHEN + processor.convertToHTML(inputPath, outputPath, language); + + // THEN + List filesPath= Files.list(Paths.get("./src/main/resources/output")).collect(Collectors.toList()); + + assertThat(filesPath).hasSize(0); + + // clean directory after the test + utils.cleanDirectory(Paths.get(outputPath)); + } + @Test - void shouldThrowNullPointerExceptionFromNullPath() { - System.out.println("hi"); + void shouldCreateNoFilesFromValidPathAndInvalidOutputPathAndValidLanguage() throws IOException { + String inputPath = TestUtils.generateRandomInputPath(); + + String outputPath = "invalid output"; + + String language = "en"; + + // WHEN + processor.convertToHTML(inputPath, outputPath, language); + + // THEN + List filesPath= Files.list(Paths.get("./src/main/resources/output")).collect(Collectors.toList()); + + assertThat(filesPath).hasSize(0); + + // clean directory after the test + utils.cleanDirectory(Paths.get(outputPath)); } } diff --git a/src/main/java/test/com/os/jssg/utils/HTMLUtilsTest.java b/src/main/java/test/com/os/jssg/utils/HTMLUtilsTest.java index 8f0d3b9..69822c8 100644 --- a/src/main/java/test/com/os/jssg/utils/HTMLUtilsTest.java +++ b/src/main/java/test/com/os/jssg/utils/HTMLUtilsTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import test.com.os.jssg.TestUtils; -import java.io.FileNotFoundException; + import java.io.IOException; import java.util.Map; @@ -18,7 +18,7 @@ public class HTMLUtilsTest { @Test public void shouldReturnMapFromValidPathAndValidLanguage() throws IOException { // GIVEN - String path = TestUtils.generateRandomPath(); + String path = TestUtils.generateRandomInputPath(); String language = "en"; // WHEN @@ -44,7 +44,7 @@ public void shouldReTurnNullFromInvalidPathAndValidLanguage() { @Test public void shouldReTurnNullFromValidPathAndInValidLanguage() throws IOException { // GIVEN - String path = TestUtils.generateRandomPath(); + String path = TestUtils.generateRandomInputPath(); String language = null; // WHEN diff --git a/src/main/java/test/com/os/jssg/utils/MDUtilsTest.java b/src/main/java/test/com/os/jssg/utils/MDUtilsTest.java index dd35b89..3d5c077 100644 --- a/src/main/java/test/com/os/jssg/utils/MDUtilsTest.java +++ b/src/main/java/test/com/os/jssg/utils/MDUtilsTest.java @@ -18,7 +18,7 @@ public class MDUtilsTest { @Test public void shouldReturnMapFromValidPath() throws IOException { // GIVEN - String path = TestUtils.generateRandomPath(); + String path = TestUtils.generateRandomInputPath(); // WHEN Map result = utils.convertMdToHTML(path); @@ -40,7 +40,6 @@ public void shouldReTurnNullFromInvalidPath(){ } - @Test public void shouldThrowsExceptionFromNullPath(){ // GIVEN diff --git a/src/main/java/test/com/os/jssg/utils/TextUtilsTest.java b/src/main/java/test/com/os/jssg/utils/TextUtilsTest.java index 2b4a31c..a23cd33 100644 --- a/src/main/java/test/com/os/jssg/utils/TextUtilsTest.java +++ b/src/main/java/test/com/os/jssg/utils/TextUtilsTest.java @@ -15,7 +15,7 @@ public class TextUtilsTest { @Test void shouldReturnConvertedTextFromAValidPath() throws IOException { // GIVEN - String path = TestUtils.generateRandomPath(); + String path = TestUtils.generateRandomInputPath(); // WHEN String convertedText = textUtils.readText(path); diff --git a/src/main/resources/SherlockHolmesSelectedStories/SilverBlaze.txt b/src/main/resources/SherlockHolmesSelectedStories/Silver Blaze.txt similarity index 100% rename from src/main/resources/SherlockHolmesSelectedStories/SilverBlaze.txt rename to src/main/resources/SherlockHolmesSelectedStories/Silver Blaze.txt diff --git a/src/main/resources/index.html b/src/main/resources/index.html new file mode 100644 index 0000000..d0af522 --- /dev/null +++ b/src/main/resources/index.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_BLOCK.html b/src/main/resources/index_SORT_BY_BLOCK.html new file mode 100644 index 0000000..58a69ff --- /dev/null +++ b/src/main/resources/index_SORT_BY_BLOCK.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_BLOCK_DESC.html b/src/main/resources/index_SORT_BY_BLOCK_DESC.html new file mode 100644 index 0000000..08e759b --- /dev/null +++ b/src/main/resources/index_SORT_BY_BLOCK_DESC.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_CLASS.html b/src/main/resources/index_SORT_BY_CLASS.html new file mode 100644 index 0000000..debe6e4 --- /dev/null +++ b/src/main/resources/index_SORT_BY_CLASS.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_CLASS_DESC.html b/src/main/resources/index_SORT_BY_CLASS_DESC.html new file mode 100644 index 0000000..6219ab2 --- /dev/null +++ b/src/main/resources/index_SORT_BY_CLASS_DESC.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_LINE.html b/src/main/resources/index_SORT_BY_LINE.html new file mode 100644 index 0000000..321a922 --- /dev/null +++ b/src/main/resources/index_SORT_BY_LINE.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_LINE_DESC.html b/src/main/resources/index_SORT_BY_LINE_DESC.html new file mode 100644 index 0000000..b37ea09 --- /dev/null +++ b/src/main/resources/index_SORT_BY_LINE_DESC.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_METHOD.html b/src/main/resources/index_SORT_BY_METHOD.html new file mode 100644 index 0000000..d6442bc --- /dev/null +++ b/src/main/resources/index_SORT_BY_METHOD.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_METHOD_DESC.html b/src/main/resources/index_SORT_BY_METHOD_DESC.html new file mode 100644 index 0000000..13271b0 --- /dev/null +++ b/src/main/resources/index_SORT_BY_METHOD_DESC.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + + diff --git a/src/main/resources/index_SORT_BY_NAME_DESC.html b/src/main/resources/index_SORT_BY_NAME_DESC.html new file mode 100644 index 0000000..7ffde6d --- /dev/null +++ b/src/main/resources/index_SORT_BY_NAME_DESC.html @@ -0,0 +1,197 @@ + + + + + + Coverage Report > Summary + + + + + +
+ + +

Overall Coverage Summary

+ + + + + + + + + + + + + +
Package + Class, % + + Method, % + + Line, % +
all classes + + 100% + + + (6/6) + + + + 95.8% + + + (23/24) + + + + 95.2% + + + (79/83) + +
+ +
+

Coverage Breakdown

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+Package + Class, % + + Method, % + + Line, % +
test.com.os.jssg.utils + + 100% + + + (4/4) + + + + 100% + + + (16/16) + + + + 100% + + + (46/46) + +
test.com.os.jssg.processor + + 100% + + + (1/1) + + + + 100% + + + (4/4) + + + + 100% + + + (24/24) + +
test.com.os.jssg + + 100% + + + (1/1) + + + + 75% + + + (3/4) + + + + 69.2% + + + (9/13) + +
+
+ + + + + + +