You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2022/03/11 13:43:20 UTC

[jspwiki] 04/15: Make HtmlStringToWikiTranslatorTest use a mocked Engine instead of building a TestEngine

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 8f2cac2fac185f692267ce0ab079146d1803f0ff
Author: Juan Pablo Santos Rodríguez <ju...@gmail.com>
AuthorDate: Mon Mar 7 14:51:18 2022 +0100

    Make HtmlStringToWikiTranslatorTest use a mocked Engine instead of building a TestEngine
---
 jspwiki-main/pom.xml                               | 113 +++++++++++----------
 .../htmltowiki/HtmlStringToWikiTranslatorTest.java |  18 ++--
 2 files changed, 72 insertions(+), 59 deletions(-)

diff --git a/jspwiki-main/pom.xml b/jspwiki-main/pom.xml
index b8c0e84..205cb4c 100644
--- a/jspwiki-main/pom.xml
+++ b/jspwiki-main/pom.xml
@@ -55,60 +55,58 @@
     </dependency>
 
     <dependency>
-      <groupId>xmlrpc</groupId>
-      <artifactId>xmlrpc</artifactId>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-collections4</artifactId>
+      <groupId>commons-fileupload</groupId>
+      <artifactId>commons-fileupload</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-analyzers-common</artifactId>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-backward-codecs</artifactId>
+      <groupId>net.sourceforge</groupId>
+      <artifactId>akismet-java</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-highlighter</artifactId>
+      <groupId>net.sourceforge</groupId>
+      <artifactId>sandler</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-queryparser</artifactId>
+      <groupId>javax.servlet</groupId>
+      <artifactId>jstl</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>javax.servlet-api</artifactId>
-      <scope>provided</scope>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>javax.servlet.jsp</groupId>
-      <artifactId>javax.servlet.jsp-api</artifactId>
-      <scope>provided</scope>
+      <groupId>jaxen</groupId>
+      <artifactId>jaxen</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>net.sourceforge</groupId>
-      <artifactId>sandler</artifactId>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>oro</groupId>
-      <artifactId>oro</artifactId>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-collections4</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>javax.mail</groupId>
-      <artifactId>mail</artifactId>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-text</artifactId>
     </dependency>
 
     <dependency>
@@ -122,28 +120,28 @@
     </dependency>
 
     <dependency>
-      <groupId>com.google.code.gson</groupId>
-      <artifactId>gson</artifactId>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-analyzers-common</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.jvnet.hudson</groupId>
-      <artifactId>org.suigeneris.jrcs.diff</artifactId>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-backward-codecs</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>org.jdom</groupId>
-      <artifactId>jdom2</artifactId>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-highlighter</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>jaxen</groupId>
-      <artifactId>jaxen</artifactId>
+      <groupId>org.apache.lucene</groupId>
+      <artifactId>lucene-queryparser</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>jstl</artifactId>
+      <groupId>org.codelibs</groupId>
+      <artifactId>nekohtml</artifactId>
     </dependency>
 
     <dependency>
@@ -152,40 +150,41 @@
     </dependency>
 
     <dependency>
-      <groupId>commons-fileupload</groupId>
-      <artifactId>commons-fileupload</artifactId>
+      <groupId>org.jdom</groupId>
+      <artifactId>jdom2</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>net.sourceforge</groupId>
-      <artifactId>akismet-java</artifactId>
+      <groupId>org.jvnet.hudson</groupId>
+      <artifactId>org.suigeneris.jrcs.diff</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>commons-httpclient</groupId>
-      <artifactId>commons-httpclient</artifactId>
+      <groupId>oro</groupId>
+      <artifactId>oro</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>net.sourceforge.nekohtml</groupId>
-      <artifactId>nekohtml</artifactId>
-      <scope>runtime</scope>
+      <groupId>xmlrpc</groupId>
+      <artifactId>xmlrpc</artifactId>
     </dependency>
 
     <dependency>
-      <groupId>net.sourceforge.stripes</groupId>
-      <artifactId>stripes</artifactId>
-      <scope>test</scope>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <scope>provided</scope>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
+      <groupId>javax.servlet.jsp</groupId>
+      <artifactId>javax.servlet.jsp-api</artifactId>
+      <scope>provided</scope>
     </dependency>
 
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-text</artifactId>
+      <groupId>net.sourceforge.stripes</groupId>
+      <artifactId>stripes</artifactId>
+      <scope>test</scope>
     </dependency>
 
     <dependency>
@@ -232,6 +231,18 @@
       <artifactId>junit-jupiter-engine</artifactId>
       <scope>test</scope>
     </dependency>
+
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-junit-jupiter</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -269,7 +280,7 @@
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <systemPropertyVariables>
-              <java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
+            <java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
           </systemPropertyVariables>          
           <excludes>
             <!-- time-consuming tests excluded by default -->
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslatorTest.java b/jspwiki-main/src/test/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslatorTest.java
index 4dc6920..d1fa42e 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslatorTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/htmltowiki/HtmlStringToWikiTranslatorTest.java
@@ -18,11 +18,13 @@
  */
 package org.apache.wiki.htmltowiki;
 
-import org.apache.wiki.TestEngine;
 import org.apache.wiki.api.core.Engine;
 import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.util.Properties;
 
 /**
  * JUnit test cases for Converting Html to Wiki Markup.
@@ -30,11 +32,13 @@ import org.junit.jupiter.api.Test;
  */
 public class HtmlStringToWikiTranslatorTest {
 
-    static Engine e = TestEngine.build();
-    HtmlStringToWikiTranslator html2wiki;
+    static Engine e;
+    static HtmlStringToWikiTranslator html2wiki;
 
-    @BeforeEach
-    public void setUp() {
+    @BeforeAll
+    public static void setUp() {
+        e = Mockito.mock( Engine.class );
+        Mockito.doReturn( new Properties() ).when( e ).getWikiProperties();
         html2wiki = new HtmlStringToWikiTranslator( e );
     }
 
@@ -63,7 +67,6 @@ public class HtmlStringToWikiTranslatorTest {
         // footnote links
         Assertions.assertEquals( "[23]", html2wiki.translate( "<a class=\"footnoteref\" href=\"#ref-PageName-23\">[23]</a>" ) );
         Assertions.assertEquals( "[something|23]", html2wiki.translate( "<a class=\"footnoteref\" href=\"#ref-PageName-23\">[something]</a>" ) );
-
     }
 
     @Test
@@ -100,7 +103,6 @@ public class HtmlStringToWikiTranslatorTest {
     public void testRulers() throws Exception {
         Assertions.assertEquals( "a\n----\nb", html2wiki.translate( "a<hr/>b" ) );
         Assertions.assertEquals( "by\n" + "----\n" + "Dies", html2wiki.translate( "by\n" + "<hr>\n" + "Dies" ) );
-
     }
 
     @Test