freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject [freemarker-generator] branch FREEMARKER-129 updated: FREEMARKER-129 Improve tests and Maven build
Date Tue, 11 Feb 2020 05:39:34 GMT
This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch FREEMARKER-129
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git


The following commit(s) were added to refs/heads/FREEMARKER-129 by this push:
     new 394756b  FREEMARKER-129 Improve tests and Maven build
394756b is described below

commit 394756b1ad06a9467c491552dbbadcdc1a8de2d7
Author: Siegfried Goeschl <siegfried.goeschl@gmail.com>
AuthorDate: Tue Feb 11 06:39:18 2020 +0100

    FREEMARKER-129 Improve tests and Maven build
---
 freemarker-generator-base/pom.xml                  |  2 +-
 .../generator/base/document/Document.java          |  3 +-
 .../generator/base/util/LocaleUtils.java           |  2 --
 .../generator/document/DocumentFactoryTest.java    |  2 +-
 .../generator/document/DocumentTest.java           | 37 ++++++++++++++++++++--
 .../generator/document/DocumentsSupplierTest.java  |  2 +-
 .../generator/document/DocumentsTest.java          | 29 +++++++++++------
 freemarker-generator-cli/pom.xml                   |  2 +-
 freemarker-generator-maven-plugin/pom.xml          |  4 +--
 freemarker-generator-tools/pom.xml                 |  2 +-
 .../generator/tools/jsonpath/JsonPathToolTest.java | 27 +++++++++++++---
 pom.xml                                            | 18 +++++++++--
 12 files changed, 100 insertions(+), 30 deletions(-)

diff --git a/freemarker-generator-base/pom.xml b/freemarker-generator-base/pom.xml
index e67c1a3..9d33aa9 100644
--- a/freemarker-generator-base/pom.xml
+++ b/freemarker-generator-base/pom.xml
@@ -21,7 +21,7 @@
 
     <parent>
         <groupId>org.apache.freemarker.generator</groupId>
-        <artifactId>parent</artifactId>
+        <artifactId>freemarker-generator</artifactId>
         <version>0.1.0-SNAPSHOT</version>
     </parent>
 
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java
b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java
index 6d9959d..263f71b 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/document/Document.java
@@ -167,8 +167,7 @@ public class Document implements Closeable {
 
     /**
      * Returns an Iterator for the lines in an <code>InputStream</code>, using
-     * the character encoding specified. The caller is responsible to close
-     * the line iterator.
+     * the character encoding specified.
      *
      * @param charsetName The name of the requested charset
      * @return line iterator
diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/LocaleUtils.java
b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/LocaleUtils.java
index e7a3fc2..0131568 100644
--- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/LocaleUtils.java
+++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/util/LocaleUtils.java
@@ -16,8 +16,6 @@
  */
 package org.apache.freemarker.generator.base.util;
 
-import org.apache.freemarker.generator.base.util.StringUtils;
-
 import java.util.Locale;
 
 public class LocaleUtils {
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java
b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java
index 35fb4e4..21f7061 100644
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentFactoryTest.java
@@ -45,7 +45,7 @@ public class DocumentFactoryTest {
         assertEquals(ANY_FILE_NAME, document.getName());
         assertEquals(UTF_8, document.getCharset());
         assertEquals(ANY_FILE.getAbsolutePath(), document.getLocation());
-        assertTrue(document.getLines().size() > 0);
+        assertTrue(!document.getLines().isEmpty());
     }
 
     @Test
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java
b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java
index bc343fa..468f431 100644
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentTest.java
@@ -21,6 +21,7 @@ import org.apache.freemarker.generator.base.document.Document;
 import org.apache.freemarker.generator.base.document.DocumentFactory;
 import org.junit.Test;
 
+import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.Charset;
@@ -62,7 +63,7 @@ public class DocumentTest {
 
     @Test
     public void shouldSupportLineIterator() throws IOException {
-        try (Document document = DocumentFactory.create("test", ANY_TEXT)) {
+        try (Document document = textDocument()) {
             try (LineIterator iterator = document.getLineIterator(ANY_CHAR_SET.name())) {
                 assertEquals(1, count(iterator));
             }
@@ -71,7 +72,7 @@ public class DocumentTest {
 
     @Test
     public void shouldReadLines() throws IOException {
-        try (Document document = DocumentFactory.create("test", ANY_TEXT)) {
+        try (Document document = textDocument()) {
             assertEquals(1, document.getLines().size());
             assertEquals(ANY_TEXT, document.getLines().get(0));
         }
@@ -79,11 +80,23 @@ public class DocumentTest {
 
     @Test
     public void shouldGetBytes() throws IOException {
-        try (Document document = DocumentFactory.create("test", ANY_TEXT)) {
+        try (Document document = textDocument()) {
             assertEquals(11, document.getBytes().length);
         }
     }
 
+    @Test
+    public void shouldCloseDocument() {
+        final Document document = textDocument();
+        final TestClosable closable1 = document.addClosable(new TestClosable());
+        final TestClosable closable2 = document.addClosable(new TestClosable());
+
+        document.close();
+
+        assertTrue(closable1.isClosed());
+        assertTrue(closable2.isClosed());
+    }
+
     private static int count(Iterator<String> iterator) {
         int count = 0;
         while (iterator.hasNext()) {
@@ -92,4 +105,22 @@ public class DocumentTest {
         }
         return count;
     }
+
+    private static Document textDocument() {
+        return DocumentFactory.create("stdin", ANY_TEXT);
+    }
+
+    private static final class TestClosable implements Closeable {
+
+        private boolean closed = false;
+
+        @Override
+        public void close() throws IOException {
+            closed = true;
+        }
+
+        public boolean isClosed() {
+            return closed;
+        }
+    }
 }
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java
b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java
index 16385b2..28c601b 100644
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsSupplierTest.java
@@ -76,7 +76,7 @@ public class DocumentsSupplierTest {
     @Test
     public void shouldResolveLargeDirectory() {
         final List<Document> documents = supplier(".", null).get();
-        assertTrue(documents.size() > 0);
+        assertTrue(!documents.isEmpty());
     }
 
     @Test(expected = RuntimeException.class)
diff --git a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java
b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java
index 496a594..640cc12 100644
--- a/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java
+++ b/freemarker-generator-base/src/test/java/org/apache/freemarker/generator/document/DocumentsTest.java
@@ -28,6 +28,7 @@ import java.net.URL;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.Arrays.asList;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
 public class DocumentsTest {
@@ -66,6 +67,24 @@ public class DocumentsTest {
         assertNotNull(documents().get(ANY_FILE_NAME));
     }
 
+    @Test
+    public void shouldGetAllDocuments() {
+        final Documents documents = documents();
+
+        assertEquals("unknown", documents().get(0).getName());
+        assertEquals("pom.xml", documents().get(1).getName());
+        assertEquals("url", documents().get(2).getName());
+        assertEquals("unknown", documents().getFirst().getName());
+        assertEquals(3, documents.getList().size());
+        assertEquals(3, documents.size());
+        assertFalse(documents.isEmpty());
+    }
+
+    @Test
+    public void shouldGetNames() {
+        assertEquals(asList("unknown", "pom.xml", "url"), documents().getNames());
+    }
+
     @Test(expected = IllegalArgumentException.class)
     public void shouldThrowExceptionWhenGetDoesNotFindDocument() {
         documents().get("file-does-not-exist");
@@ -76,16 +95,6 @@ public class DocumentsTest {
         documents().get("*");
     }
 
-    @Test
-    public void shouldGetAllDocuments() {
-        assertEquals(3, documents().getList().size());
-    }
-
-    @Test
-    public void shouldGetNames() {
-        assertEquals(asList("unknown", "pom.xml", "url"), documents().getNames());
-    }
-
     private static Documents documents() {
         return new Documents(asList(textDocument(), fileDocument(), urlDocument()));
     }
diff --git a/freemarker-generator-cli/pom.xml b/freemarker-generator-cli/pom.xml
index 520a00b..8b4413f 100644
--- a/freemarker-generator-cli/pom.xml
+++ b/freemarker-generator-cli/pom.xml
@@ -21,7 +21,7 @@
 
     <parent>
         <groupId>org.apache.freemarker.generator</groupId>
-        <artifactId>parent</artifactId>
+        <artifactId>freemarker-generator</artifactId>
         <version>0.1.0-SNAPSHOT</version>
     </parent>
 
diff --git a/freemarker-generator-maven-plugin/pom.xml b/freemarker-generator-maven-plugin/pom.xml
index a17ddc9..a2cdf5f 100644
--- a/freemarker-generator-maven-plugin/pom.xml
+++ b/freemarker-generator-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
 
     <parent>
         <groupId>org.apache.freemarker.generator</groupId>
-        <artifactId>parent</artifactId>
+        <artifactId>freemarker-generator</artifactId>
         <version>0.1.0-SNAPSHOT</version>
     </parent>
 
@@ -153,7 +153,7 @@
                             <targetPercentage>${clover-target-percentage}</targetPercentage>
                             <generateHtml>true</generateHtml>
                             <generateXml>true</generateXml>
-                            <jdk>${target-jdk-version}</jdk>
+                            <jdk>${maven.compiler.source}</jdk>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/freemarker-generator-tools/pom.xml b/freemarker-generator-tools/pom.xml
index 4b67e50..0a9ecd6 100644
--- a/freemarker-generator-tools/pom.xml
+++ b/freemarker-generator-tools/pom.xml
@@ -21,7 +21,7 @@
 
     <parent>
         <groupId>org.apache.freemarker.generator</groupId>
-        <artifactId>parent</artifactId>
+        <artifactId>freemarker-generator</artifactId>
         <version>0.1.0-SNAPSHOT</version>
     </parent>
 
diff --git a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathToolTest.java
b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathToolTest.java
index 3d9d8d0..aaed1b5 100644
--- a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathToolTest.java
+++ b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/jsonpath/JsonPathToolTest.java
@@ -47,16 +47,35 @@ public class JsonPathToolTest {
             "   ]\n" +
             "}";
 
+    private static final String JSON_WITH_COMMENTS = "{\n" +
+            "    // Single line comment\n" +
+            "    \"fruit\": \"Apple\",\n" +
+            "    \"size\": \"Large\",\n" +
+            "    \"color\": \"Red\"\n" +
+            "}";
+
     @Test
     public void shallParseJsonObject() {
-        assertEquals(parse(JSON_OBJECT_STRING).read("$.language"), "Python");
-        assertEquals(parse(JSON_OBJECT_STRING).read("$['language']"), "Python");
+        final DocumentContext json = parse(JSON_OBJECT_STRING);
+
+        assertEquals(json.read("$.language"), "Python");
+        assertEquals(json.read("$['language']"), "Python");
     }
 
     @Test
     public void shallParseJsonArray() {
-        assertEquals(parse(JSON_ARRAY_STRING).read("$.eBooks[0].language"), "Pascal");
-        assertEquals(parse(JSON_ARRAY_STRING).read("$['eBooks'][0]['language']"), "Pascal");
+        final DocumentContext json = parse(JSON_ARRAY_STRING);
+
+        assertEquals(json.read("$.eBooks[0].language"), "Pascal");
+        assertEquals(json.read("$['eBooks'][0]['language']"), "Pascal");
+    }
+
+    @Test
+    public void failsToParseJsonComments() {
+        final DocumentContext json = parse(JSON_WITH_COMMENTS);
+
+        assertNull(json.read("$.fruit"));
+        assertEquals("Large", json.read("$.size"));
     }
 
     @Test
diff --git a/pom.xml b/pom.xml
index 85a9340..ee52da6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
     </parent>
 
     <groupId>org.apache.freemarker.generator</groupId>
-    <artifactId>parent</artifactId>
+    <artifactId>freemarker-generator</artifactId>
     <packaging>pom</packaging>
     <version>0.1.0-SNAPSHOT</version>
     <name>Apache FreeMarker Generator: Parent</name>
@@ -61,7 +61,6 @@
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <freemarker.version>2.3.29</freemarker.version>
-        <target-jdk-version>1.8</target-jdk-version>
     </properties>
 
     <developers>
@@ -189,4 +188,19 @@
             </plugin>
         </plugins>
     </build>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-pmd-plugin</artifactId>
+                <configuration>
+                    <linkXRef>false</linkXRef>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
 </project>
\ No newline at end of file


Mime
View raw message