Skip to content

Commit

Permalink
move to junit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Nov 9, 2019
1 parent f8c41ad commit 888c27b
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 123 deletions.
18 changes: 14 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -135,7 +141,11 @@
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package cz.jiripinkas.jsitemapgenerator;

import cz.jiripinkas.jsitemapgenerator.generator.SitemapIndexGenerator;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

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

public class AbstractSitemapGeneratorTest {

class AbstractSitemapGeneratorTest {

private SitemapIndexGenerator sitemapIndexGenerator;

@Before
public void setUp() {
@BeforeEach
void setUp() {
sitemapIndexGenerator = SitemapIndexGenerator.of("http://javalibs.com");
sitemapIndexGenerator.addPage(WebPage.builder().name("sitemap-plugins.xml").lastMod(LocalDateTime.of(2018, 1, 1, 0, 0)).build());
sitemapIndexGenerator.addPage(WebPage.builder().name("sitemap-archetypes.xml").lastMod(LocalDateTime.of(2018, 1, 1, 0, 0)).build());
}

@Test
public void toPrettyString() {
void toPrettyString() {
String actualSitemapIndex = sitemapIndexGenerator.toPrettyString(2);
String expectedSitemapIndex = "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n" +
" <sitemap>\n" +
Expand All @@ -36,19 +37,19 @@ public void toPrettyString() {
}

@Test
public void getAbsoluteUrlRelativeCheck() {
void getAbsoluteUrlRelativeCheck() {
String absoluteUrl = sitemapIndexGenerator.getAbsoluteUrl("relativeUrl");
assertEquals("http://javalibs.com/relativeUrl", absoluteUrl);
}

@Test
public void getAbsoluteUrlAbsoluteCheck() {
void getAbsoluteUrlAbsoluteCheck() {
String absoluteUrl = sitemapIndexGenerator.getAbsoluteUrl("https://cdn.com");
assertEquals("https://cdn.com", absoluteUrl);
}

@Test
public void getAbsoluteUrlBaseUrlCheck() {
void getAbsoluteUrlBaseUrlCheck() {
String absoluteUrl = sitemapIndexGenerator.getAbsoluteUrl(null);
assertEquals("http://javalibs.com/", absoluteUrl);
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/cz/jiripinkas/jsitemapgenerator/UrlUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package cz.jiripinkas.jsitemapgenerator;

import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public class UrlUtilTest {
class UrlUtilTest {

@Test
public void connectUrlParts() {
void connectUrlParts() {
assertEquals("https://javalibs.com", UrlUtil.connectUrlParts("https://javalibs.com", null));
assertEquals("https://javalibs.com/page", UrlUtil.connectUrlParts("https://javalibs.com", "page"));
assertEquals("https://javalibs.com/page", UrlUtil.connectUrlParts("https://javalibs.com", "/page"));
}

@Test
public void escapeXmlSpecialCharacters() {
void escapeXmlSpecialCharacters() {
assertEquals("/page?arg1=&apos;test&apos;&amp;arg2=&lt;test&gt;&amp;arg3=&quot;test&quot;", UrlUtil.escapeXmlSpecialCharacters("/page?arg1='test'&arg2=<test>&arg3=\"test\""));
assertNull(UrlUtil.escapeXmlSpecialCharacters(null));
}
Expand Down
50 changes: 29 additions & 21 deletions src/test/java/cz/jiripinkas/jsitemapgenerator/WebPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,70 @@
import cz.jiripinkas.jsitemapgenerator.exception.InvalidPriorityException;
import cz.jiripinkas.jsitemapgenerator.exception.InvalidUrlException;
import cz.jiripinkas.jsitemapgenerator.generator.SitemapGenerator;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class WebPageTest {
class WebPageTest {

@Test(expected = InvalidUrlException.class)
public void testConstruct() {
SitemapGenerator.of("www.javavids.com");
@Test
void testConstruct() {
assertThrows(InvalidUrlException.class, () -> {
SitemapGenerator.of("www.javavids.com");
});
}

@Test(expected = InvalidPriorityException.class)
public void testLowPriority() {
new WebPage().setPriority(-1.0);
@Test
void testLowPriority() {
assertThrows(InvalidPriorityException.class, () -> {
new WebPage().setPriority(-1.0);
});
}

@Test(expected = InvalidPriorityException.class)
public void testHighPriority() {
new WebPage().setPriority(10.0);
@Test
void testHighPriority() {
assertThrows(InvalidPriorityException.class, () -> {
new WebPage().setPriority(10.0);
});
}

@Test
public void testPrefixDirAndSuffix() {
void testPrefixDirAndSuffix() {
WebPage build = WebPage.builder().dir("dir").name("name").extension("html").build();
assertEquals("dir/name.html", build.constructName());
}

@Test
public void testPrefixDirs() {
void testPrefixDirs() {
WebPage build = WebPage.builder().dir("dir1", "dir2", "dir3").name("name").extension("html").build();
assertEquals("dir1/dir2/dir3/name.html", build.constructName());
}

@Test
public void testDirs() {
void testDirs() {
WebPage build = WebPage.builder().name("dir1", "dir2", "dir3", "name").build();
assertEquals("dir1/dir2/dir3/name", build.constructName());
}

@Test
public void testNameRoot() {
void testNameRoot() {
WebPage build = WebPage.builder().nameRoot().build();
assertEquals("", build.constructName());
}

@Test
public void of_name_is_not_null() {
void of_name_is_not_null() {
WebPage webPage = WebPage.of("test");
assertThat(webPage.getName()).isEqualTo("test");
}

@Test(expected = NullPointerException.class)
public void of_name_cannot_be_null() {
String nullString = null;
WebPage webPage = WebPage.of(nullString);
@Test
void of_name_cannot_be_null() {
assertThrows(NullPointerException.class, () -> {
String nullString = null;
WebPage.of(nullString);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import cz.jiripinkas.jsitemapgenerator.WebPage;
import cz.jiripinkas.jsitemapgenerator.util.TestUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import java.io.ByteArrayInputStream;
Expand All @@ -13,19 +13,19 @@
import java.time.LocalDateTime;
import java.util.Date;

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

public class RssGeneratorTest {
class RssGeneratorTest {

private RssGenerator rssGenerator;

@Before
public void setUp() {
@BeforeEach
void setUp() {
rssGenerator = RssGenerator.of("http://www.topjavablogs.com", "Top Java Blogs", "News from Java community");
}

@Test
public void testConstructRssEmptyItemsShouldThrowException() {
void testConstructRssEmptyItemsShouldThrowException() {
try {
String rss = rssGenerator.toString();
ByteArrayInputStream xml = new ByteArrayInputStream(rss.getBytes(StandardCharsets.UTF_8));
Expand All @@ -36,7 +36,7 @@ public void testConstructRssEmptyItemsShouldThrowException() {
}

@Test
public void testConstructRssWithItems() throws SAXException, IOException {
void testConstructRssWithItems() throws SAXException, IOException {
rssGenerator.addPage(WebPage.rssBuilder()
.title("latest news")
.description("description")
Expand All @@ -50,8 +50,8 @@ public void testConstructRssWithItems() throws SAXException, IOException {
}

@Test
public void testConstructRssWithItemsLocalDateTime() {
String rss = RssGenerator.of("http://www.topjavablogs.com", "Top Java Blogs", "News from Java community")
void testConstructRssWithItemsLocalDateTime() {
String actual = RssGenerator.of("http://www.topjavablogs.com", "Top Java Blogs", "News from Java community")
.addPage(WebPage.rssBuilder()
.title("latest news")
.description("description")
Expand All @@ -76,12 +76,12 @@ public void testConstructRssWithItemsLocalDateTime() {
"</item>\n" +
"</channel>\n" +
"</rss>\n";
assertEquals(expected, rss);
assertEquals(expected, actual);
}

@Test
public void testConstructRssWithItemsLocalDateTimeWithRedundantSlash() {
String rss = RssGenerator.of("http://www.topjavablogs.com", "Top Java Blogs", "News from Java community")
void testConstructRssWithItemsLocalDateTimeWithRedundantSlash() {
String actual = RssGenerator.of("http://www.topjavablogs.com", "Top Java Blogs", "News from Java community")
.addPage(WebPage.rssBuilder()
.title("latest news")
.description("description")
Expand All @@ -106,7 +106,7 @@ public void testConstructRssWithItemsLocalDateTimeWithRedundantSlash() {
"</item>\n" +
"</channel>\n" +
"</rss>\n";
assertEquals(expected, rss);
assertEquals(expected, actual);
}

}
Loading

0 comments on commit 888c27b

Please sign in to comment.