diff --git a/pom.xml b/pom.xml index c7be95a..782cb39 100644 --- a/pom.xml +++ b/pom.xml @@ -42,9 +42,15 @@ true - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-api + 5.5.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.5.2 test @@ -135,7 +141,11 @@ - + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/AbstractSitemapGeneratorTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/AbstractSitemapGeneratorTest.java index 07921b6..1ed7590 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/AbstractSitemapGeneratorTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/AbstractSitemapGeneratorTest.java @@ -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 = "\n" + " \n" + @@ -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); } diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/UrlUtilTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/UrlUtilTest.java index 4463102..bbac892 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/UrlUtilTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/UrlUtilTest.java @@ -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='test'&arg2=<test>&arg3="test"", UrlUtil.escapeXmlSpecialCharacters("/page?arg1='test'&arg2=&arg3=\"test\"")); assertNull(UrlUtil.escapeXmlSpecialCharacters(null)); } diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/WebPageTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/WebPageTest.java index 8987a3b..9607b0b 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/WebPageTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/WebPageTest.java @@ -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); + }); } } diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/RssGeneratorTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/RssGeneratorTest.java index fb07b14..e6c9973 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/RssGeneratorTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/RssGeneratorTest.java @@ -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; @@ -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)); @@ -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") @@ -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") @@ -76,12 +76,12 @@ public void testConstructRssWithItemsLocalDateTime() { "\n" + "\n" + "\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") @@ -106,7 +106,7 @@ public void testConstructRssWithItemsLocalDateTimeWithRedundantSlash() { "\n" + "\n" + "\n"; - assertEquals(expected, rss); + assertEquals(expected, actual); } } diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapGeneratorTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapGeneratorTest.java index f730282..0b18fd1 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapGeneratorTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapGeneratorTest.java @@ -5,8 +5,8 @@ import cz.jiripinkas.jsitemapgenerator.WebPage; import cz.jiripinkas.jsitemapgenerator.exception.GWTException; 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.mockito.Mockito; import java.io.ByteArrayInputStream; @@ -16,14 +16,14 @@ import java.time.LocalDateTime; import java.util.ArrayList; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SitemapGeneratorTest { +class SitemapGeneratorTest { private SitemapGenerator sitemapGenerator; - @Before - public void setUp() { + @BeforeEach + void setUp() { sitemapGenerator = SitemapGenerator.of("http://www.javavids.com"); sitemapGenerator.addPage(WebPage.builder().name("index.php").priority(1.0).changeFreqNever().lastMod(LocalDateTime.of(2019, 1, 1, 0, 0)).build()); sitemapGenerator.addPage(WebPage.builder().name("latest.php").build()); @@ -31,7 +31,7 @@ public void setUp() { } @Test - public void testConstructImage() { + void testConstructImage() { Image image = new Image(); image.setLoc("http://example.com/image"); String imageString = sitemapGenerator.constructImage(image); @@ -39,7 +39,7 @@ public void testConstructImage() { } @Test - public void testConstructImageWithBaseUrl() { + void testConstructImageWithBaseUrl() { Image image = new Image(); image.setLoc("/image"); String imageString = sitemapGenerator.constructImage(image); @@ -47,7 +47,7 @@ public void testConstructImageWithBaseUrl() { } @Test - public void testConstructSitemapWithImagesHeader() { + void testConstructSitemapWithImagesHeader() { SitemapGenerator sitemapGenerator = SitemapGenerator.of("http://www.javavids.com"); sitemapGenerator.addPage(WebPage.builder().images(new ArrayList<>()).build()); String sitemapString = sitemapGenerator.toString(); @@ -61,7 +61,7 @@ public void testConstructSitemapWithImagesHeader() { } @Test - public void testConstructSitemapWithImages() { + void testConstructSitemapWithImages() { sitemapGenerator = SitemapGenerator.of("http://www.javavids.com"); WebPage webPage = WebPage.builder().nameRoot().build(); webPage.addImage(WebPage.imageBuilder().loc("http://www.javavids.com/favicon.ico").build()); @@ -71,19 +71,19 @@ public void testConstructSitemapWithImages() { } @Test - public void testConstructUrlEmptyPage() { + void testConstructUrlEmptyPage() { String url = sitemapGenerator.constructUrl(new WebPage()); assertEquals("http://www.javavids.com/\n", url); } @Test - public void testConstructUrlNotEmptyPage() { + void testConstructUrlNotEmptyPage() { String url = sitemapGenerator.constructUrl(WebPage.builder().name("latest.php").build()); assertEquals("http://www.javavids.com/latest.php\n", url); } @Test - public void testConstructAlternateUrls() { + void testConstructAlternateUrls() { String url = SitemapGenerator.of("http://www.javavids.com") .constructUrl(WebPage.builder() .name("latest.php") @@ -95,7 +95,7 @@ public void testConstructAlternateUrls() { } @Test - public void testConstructAlternateUrls2() { + void testConstructAlternateUrls2() { String url = SitemapGenerator.of("http://www.javavids.com").constructUrl(WebPage.builder() .name("latest.php") .alternateName("de", () -> "latest-de.php") @@ -106,14 +106,14 @@ public void testConstructAlternateUrls2() { } @Test - public void testConstructSitemap() throws Exception { + void testConstructSitemap() throws Exception { String sitemap = sitemapGenerator.toString(); ByteArrayInputStream sitemapXml = new ByteArrayInputStream(sitemap.getBytes(StandardCharsets.UTF_8)); TestUtil.testSitemapXsd(sitemapXml, new File("src/test/resources/sitemap.xsd")); } @Test - public void testSaveSitemap() throws Exception { + void testSaveSitemap() throws Exception { File tmpFile = File.createTempFile("test", "sitemap"); sitemapGenerator.toFile(tmpFile); String actualSitemap = String.join("\n", Files.readAllLines(tmpFile.toPath())); @@ -141,7 +141,7 @@ public void testSaveSitemap() throws Exception { } @Test - public void testConstructAndSaveSitemap() throws Exception { + void testConstructAndSaveSitemap() throws Exception { File tmpFile = File.createTempFile("test", "sitemap"); sitemapGenerator.toFile(tmpFile); try { @@ -152,7 +152,7 @@ public void testConstructAndSaveSitemap() throws Exception { } @Test - public void test() { + void test() { String sitemap = SitemapGenerator.of("https://javalibs.com") .defaultDir("dir1") .defaultChangeFreqWeekly() @@ -194,7 +194,7 @@ public void test() { // public MockitoRule mockitoRule = MockitoJUnit.rule(); @Test - public void testPingGoogleSuccess() throws Exception { + void testPingGoogleSuccess() throws Exception { HttpClient httpClientMock = Mockito.mock(HttpClient.class); SitemapGenerator sitemapGenerator = SitemapGenerator.of("https://www.example.com/"); sitemapGenerator.setHttpClient(httpClientMock); @@ -206,19 +206,20 @@ public void testPingGoogleSuccess() throws Exception { Mockito.verify(httpClientMock).get("https://www.google.com/ping?sitemap=https%3A%2F%2Fwww.example.com%2Fsitemap.xml"); } - @Test(expected = GWTException.class) - public void testPingGoogleError() throws Exception { - HttpClient httpClientMock = Mockito.mock(HttpClient.class); - SitemapGenerator sitemapGenerator = SitemapGenerator.of("https://www.example.com/"); - sitemapGenerator.setHttpClient(httpClientMock); - Mockito.when(httpClientMock.get(Mockito.anyString())) - .thenReturn(500); -// Mockito.doReturn(500).when(httpClientMock).get(Mockito.any()); - sitemapGenerator.pingGoogle(); + @Test + void testPingGoogleError() throws Exception { + assertThrows(GWTException.class, () -> { + HttpClient httpClientMock = Mockito.mock(HttpClient.class); + SitemapGenerator sitemapGenerator = SitemapGenerator.of("https://www.example.com/"); + sitemapGenerator.setHttpClient(httpClientMock); + Mockito.when(httpClientMock.get(Mockito.anyString())) + .thenReturn(500); + sitemapGenerator.pingGoogle(); + }); } @Test - public void testRemoveRedundantSlashes1() { + void testRemoveRedundantSlashes1() { String actualSitemap = SitemapGenerator.of("https://javalibs.com/") .addPage(WebPage.of("/test")) .toString(); @@ -232,7 +233,7 @@ public void testRemoveRedundantSlashes1() { } @Test - public void testRemoveRedundantSlashes2() { + void testRemoveRedundantSlashes2() { String actualSitemap = SitemapGenerator.of("https://javalibs.com/") .defaultDir("testDir") .addPage(WebPage.of("/testPage")) diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapIndexGeneratorTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapIndexGeneratorTest.java index 257d2c6..d556122 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapIndexGeneratorTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapIndexGeneratorTest.java @@ -2,43 +2,43 @@ 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; import java.io.File; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SitemapIndexGeneratorTest { +class SitemapIndexGeneratorTest { private SitemapIndexGenerator sitemapIndexGenerator; - @Before - public void setUp() { + @BeforeEach + void setUp() { sitemapIndexGenerator = SitemapIndexGenerator.of("http://javalibs.com"); sitemapIndexGenerator.addPage(WebPage.of("sitemap-plugins.xml")); sitemapIndexGenerator.addPage(WebPage.of("sitemap-archetypes.xml")); } @Test - public void testConstructUrl() { + void testConstructUrl() { WebPage webPage = WebPage.builder().name("sitemap-plugins.xml").build(); String constructUrl = sitemapIndexGenerator.constructUrl(webPage); assertEquals("\nhttp://javalibs.com/sitemap-plugins.xml\n\n", constructUrl); } @Test - public void testConstructSitemapIndex() throws SAXException, IOException { + void testConstructSitemapIndex() throws SAXException, IOException { String sitemapIndex = sitemapIndexGenerator.toString(); ByteArrayInputStream sitemapXml = new ByteArrayInputStream(sitemapIndex.getBytes("UTF-8")); TestUtil.testSitemapXsd(sitemapXml, new File("src/test/resources/siteindex.xsd")); } @Test - public void testConstructAndSaveSitemap() throws SAXException, IOException { + void testConstructAndSaveSitemap() throws SAXException, IOException { File tmpFile = File.createTempFile("test", "sitemap"); sitemapIndexGenerator.toFile(tmpFile); try { @@ -49,7 +49,7 @@ public void testConstructAndSaveSitemap() throws SAXException, IOException { } @Test - public void testSitemapPathWithSpecialCharacters() { + void testSitemapPathWithSpecialCharacters() { sitemapIndexGenerator.addPage(WebPage.builder() .name("/page?arg1='test'&arg2=&arg3=\"test\"") .build()); @@ -72,7 +72,7 @@ public void testSitemapPathWithSpecialCharacters() { } @Test - public void testConstructSitemapIndexWithRedundantSlash() throws SAXException, IOException { + void testConstructSitemapIndexWithRedundantSlash() throws SAXException, IOException { sitemapIndexGenerator.addPage("/test"); String actualSitemapIndex = sitemapIndexGenerator.toString(); String expectedSitemapIndex = "\n" + diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapPathTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapPathTest.java index 627a025..46b08c2 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapPathTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/generator/SitemapPathTest.java @@ -2,25 +2,25 @@ import cz.jiripinkas.jsitemapgenerator.W3CDateFormat; import cz.jiripinkas.jsitemapgenerator.WebPage; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.text.DateFormat; import java.util.Date; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SitemapPathTest { +class SitemapPathTest { private DateFormat dateFormat; - @Before - public void setUp() { + @BeforeEach + void setUp() { dateFormat = new W3CDateFormat(); } @Test - public void testSitemapPaths() { + void testSitemapPaths() { SitemapGenerator sitemapGenerator = SitemapGenerator.of("http://www.javavids.com/"); Date lastModDate = new Date(); sitemapGenerator.addPage(WebPage.builder() @@ -51,7 +51,7 @@ public void testSitemapPaths() { } @Test - public void testSitemapPaths2() { + void testSitemapPaths2() { SitemapGenerator sitemapGenerator = SitemapGenerator.of("http://www.javavids.com/"); sitemapGenerator.addPage(WebPage.builder() .name("/x0") @@ -102,7 +102,7 @@ public void testSitemapPaths2() { } @Test - public void testSitemapPathWithSpecialCharacters() { + void testSitemapPathWithSpecialCharacters() { SitemapGenerator sitemapGenerator = SitemapGenerator.of("http://www.javavids.com/"); sitemapGenerator.addPage(WebPage.builder() .name("/page?arg1='test'&arg2=&arg3=\"test\"") diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsRuleTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsRuleTest.java index 9b91951..f7f5bee 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsRuleTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsRuleTest.java @@ -1,26 +1,30 @@ package cz.jiripinkas.jsitemapgenerator.robots; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class RobotsRuleTest { +class RobotsRuleTest { @Test - public void testBuilderOK() { + void testBuilderOK() { RobotsRule robotsRule = RobotsRule.builder().allowAll().userAgentAll().build(); assertEquals("/", robotsRule.getAllows().get(0)); assertEquals("*", robotsRule.getUserAgent()); assertTrue(robotsRule.getDisallows().isEmpty()); } - @Test(expected = RobotsRuleException.class) - public void testBuilderMissingUserAgent() { - RobotsRule.builder().allowAll().disallowAll().build(); + @Test + void testBuilderMissingUserAgent() { + assertThrows(RobotsRuleException.class, () -> { + RobotsRule.builder().allowAll().disallowAll().build(); + }); } - @Test(expected = RobotsRuleException.class) - public void testBuilderMissingAllowAndDisallow() { - RobotsRule.builder().userAgentAll().build(); + @Test + void testBuilderMissingAllowAndDisallow() { + assertThrows(RobotsRuleException.class, () -> { + RobotsRule.builder().userAgentAll().build(); + }); } } \ No newline at end of file diff --git a/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsTxtGeneratorTest.java b/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsTxtGeneratorTest.java index 01a05fe..dcb0c91 100644 --- a/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsTxtGeneratorTest.java +++ b/src/test/java/cz/jiripinkas/jsitemapgenerator/robots/RobotsTxtGeneratorTest.java @@ -1,33 +1,33 @@ package cz.jiripinkas.jsitemapgenerator.robots; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class RobotsTxtGeneratorTest { +class RobotsTxtGeneratorTest { @Test - public void constructRobotsTxtString() { - String robotsTxtString = RobotsTxtGenerator.of("https://example.com") + void constructRobotsTxtString() { + String actual = RobotsTxtGenerator.of("https://example.com") .addSitemap("sitemap.xml") .addRule(RobotsRule.builder().userAgentAll().allowAll().build()) .toString(); String expected = "Sitemap: https://example.com/sitemap.xml\n" + "User-agent: *\n" + "Allow: /"; - assertEquals(expected, robotsTxtString); + assertEquals(expected, actual); } @Test - public void constructRobotsTxtStringWithRedundantSlash() { - String robotsTxtString = RobotsTxtGenerator.of("https://example.com") + void constructRobotsTxtStringWithRedundantSlash() { + String actual = RobotsTxtGenerator.of("https://example.com") .addSitemap("/sitemap.xml") .addRule(RobotsRule.builder().userAgentAll().allowAll().build()) .toString(); String expected = "Sitemap: https://example.com/sitemap.xml\n" + "User-agent: *\n" + "Allow: /"; - assertEquals(expected, robotsTxtString); + assertEquals(expected, actual); } } \ No newline at end of file