Skip to content

Commit 57f74a4

Browse files
committed
feat: add unit tests for sanity check
Signed-off-by: jogerj <30559735+jogerj@users.noreply.github.com>
1 parent 56d17ef commit 57f74a4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

minify-html-java/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
<properties>
4848
<java.version>1.8</java.version>
49+
<junit.version>5.9.3</junit.version>
4950
<lombok.version>1.18.38</lombok.version>
5051
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5152
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@@ -58,6 +59,12 @@
5859
<version>${lombok.version}</version>
5960
<scope>provided</scope>
6061
</dependency>
62+
<dependency>
63+
<groupId>org.junit.jupiter</groupId>
64+
<artifactId>junit-jupiter</artifactId>
65+
<version>${junit.version}</version>
66+
<scope>test</scope>
67+
</dependency>
6168
</dependencies>
6269

6370
<build>
@@ -110,6 +117,12 @@
110117
</executions>
111118
</plugin>
112119

120+
<plugin>
121+
<groupId>org.apache.maven.plugins</groupId>
122+
<artifactId>maven-surefire-plugin</artifactId>
123+
<version>3.5.2</version>
124+
</plugin>
125+
113126
<plugin>
114127
<groupId>org.apache.maven.plugins</groupId>
115128
<artifactId>maven-gpg-plugin</artifactId>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package in.wilsonl.minifyhtml;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
import static org.junit.jupiter.api.Assertions.assertThrows;
7+
8+
class MinifyHtmlTest {
9+
10+
static final Configuration DEFAULT_CONFIG = new Configuration.Builder().build();
11+
12+
@Test
13+
void testMinifyHtmlCallsNativeFunction() {
14+
final String input = "<html> <body> Hello World! </body> </html>";
15+
final String expected = "<body>Hello World!";
16+
assertEquals(expected, MinifyHtml.minify(input, DEFAULT_CONFIG), "Basic HTML minification failed");
17+
assertEquals("", MinifyHtml.minify("", DEFAULT_CONFIG));
18+
}
19+
20+
@Test
21+
void testNullParametersHandled() {
22+
assertThrows(IllegalArgumentException.class, () -> MinifyHtml.minify(null, DEFAULT_CONFIG));
23+
assertThrows(IllegalArgumentException.class, () -> MinifyHtml.minify("<html></html>", null));
24+
assertThrows(IllegalArgumentException.class, () -> MinifyHtml.minify(null, null));
25+
}
26+
}

0 commit comments

Comments
 (0)