Skip to content

Commit

Permalink
parent 48fad5b
Browse files Browse the repository at this point in the history
author trangntt-016 <trangntt.016@gmail.com> 1636566642 -0500
committer trangntt-016 <trangntt.016@gmail.com> 1636567642 -0500

Squash all commits into one
  • Loading branch information
trangntt-016 committed Nov 10, 2021
1 parent 48fad5b commit c5f1b96
Show file tree
Hide file tree
Showing 19 changed files with 2,076 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -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)
Expand All @@ -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).
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/test/com/os/jssg/TestUtils.java
Expand Up @@ -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)) {
Expand All @@ -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;
}


}
73 changes: 71 additions & 2 deletions 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<Path> 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<Path> 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));
}

}
6 changes: 3 additions & 3 deletions src/main/java/test/com/os/jssg/utils/HTMLUtilsTest.java
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/test/com/os/jssg/utils/MDUtilsTest.java
Expand Up @@ -18,7 +18,7 @@ public class MDUtilsTest {
@Test
public void shouldReturnMapFromValidPath() throws IOException {
// GIVEN
String path = TestUtils.generateRandomPath();
String path = TestUtils.generateRandomInputPath();

// WHEN
Map<String, String> result = utils.convertMdToHTML(path);
Expand All @@ -40,7 +40,6 @@ public void shouldReTurnNullFromInvalidPath(){
}



@Test
public void shouldThrowsExceptionFromNullPath(){
// GIVEN
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/test/com/os/jssg/utils/TextUtilsTest.java
Expand Up @@ -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);
Expand Down

0 comments on commit c5f1b96

Please sign in to comment.