This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 87bbf3fa7c8c291611d2837788ebccedf6f35e66 Author: Juan Pablo Santos RodrÃguez <juanpablo.san...@gmail.com> AuthorDate: Sat Nov 25 15:25:32 2023 +0100 Add some unit tests for URLConstructor#parsePageFromURL --- .../org/apache/wiki/url/UrlConstructorTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/jspwiki-main/src/test/java/org/apache/wiki/url/UrlConstructorTest.java b/jspwiki-main/src/test/java/org/apache/wiki/url/UrlConstructorTest.java new file mode 100644 index 000000000..1af5a9490 --- /dev/null +++ b/jspwiki-main/src/test/java/org/apache/wiki/url/UrlConstructorTest.java @@ -0,0 +1,28 @@ +package org.apache.wiki.url; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import javax.servlet.http.HttpServletRequest; +import java.nio.charset.StandardCharsets; + +class UrlConstructorTest { + + @Test + void testParsePageFromURLUsingPathInfo() { + final HttpServletRequest req = Mockito.mock( HttpServletRequest.class ); + Mockito.doReturn( "MyPage" ).when( req ).getPathInfo(); + Assertions.assertEquals( "MyPage", URLConstructor.parsePageFromURL( req, StandardCharsets.UTF_8 ) ); + } + + @Test + void testParsePageFromURLUsingRequestParam() { + final HttpServletRequest req = Mockito.mock( HttpServletRequest.class ); + Mockito.doReturn( null ).when( req ).getPathInfo(); + Mockito.doReturn( "MyPage", ( String )null ).when( req ).getParameter( "page" ); + Assertions.assertEquals( "MyPage", URLConstructor.parsePageFromURL( req, StandardCharsets.UTF_8 ) ); + Assertions.assertNull( URLConstructor.parsePageFromURL( req, StandardCharsets.UTF_8 ) ); // no req parameter should return null + } + +}