freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: DefaultEnumerationAdapter cleanup and test
Date Sun, 12 Mar 2017 14:24:55 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 2bd41412e -> f2f2bf056


DefaultEnumerationAdapter cleanup and test


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/f2f2bf05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/f2f2bf05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/f2f2bf05

Branch: refs/heads/3
Commit: f2f2bf056ba08e5c7d8117d65bd73f728212afd4
Parents: 2bd4141
Author: ddekany <ddekany@apache.org>
Authored: Sun Mar 12 15:24:50 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Sun Mar 12 15:24:50 2017 +0100

----------------------------------------------------------------------
 .../model/impl/DefaultEnumerationAdapter.java   | 14 +++++-----
 .../model/impl/DefaultObjectWrapperTest.java    | 27 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f2f2bf05/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
b/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
index f895bda..d56e635 100644
--- a/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
+++ b/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
@@ -39,25 +39,25 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
  * {@link TemplateCollectionModel}. Putting aside that it wraps an {@link Enumeration} instead
of an {@link Iterator},
  * this is identical to {@link DefaultIteratorAdapter}, so see further details there.
  */
-// TODO JUnit
+@SuppressWarnings("serial")
 public class DefaultEnumerationAdapter extends WrappingTemplateModel implements TemplateCollectionModel,
         AdapterTemplateModel, WrapperTemplateModel, Serializable {
 
     @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's Seralizable")
-    private final Enumeration enumeration;
+    private final Enumeration<?> enumeration;
     private boolean enumerationOwnedBySomeone;
 
     /**
      * Factory method for creating new adapter instances.
      *
-     * @param iterator
+     * @param enumeration
      *            The enumeration to adapt; can't be {@code null}.
      */
-    public static DefaultEnumerationAdapter adapt(Enumeration iterator, ObjectWrapper wrapper)
{
-        return new DefaultEnumerationAdapter(iterator, wrapper);
+    public static DefaultEnumerationAdapter adapt(Enumeration<?> enumeration, ObjectWrapper
wrapper) {
+        return new DefaultEnumerationAdapter(enumeration, wrapper);
     }
 
-    private DefaultEnumerationAdapter(Enumeration enumeration, ObjectWrapper wrapper) {
+    private DefaultEnumerationAdapter(Enumeration<?> enumeration, ObjectWrapper wrapper)
{
         super(wrapper);
         this.enumeration = enumeration;
     }
@@ -68,7 +68,7 @@ public class DefaultEnumerationAdapter extends WrappingTemplateModel implements
     }
 
     @Override
-    public Object getAdaptedObject(Class hint) {
+    public Object getAdaptedObject(Class<?> hint) {
         return getWrappedObject();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f2f2bf05/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
b/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
index deefd32..26857b2 100644
--- a/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
+++ b/src/test/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperTest.java
@@ -653,7 +653,32 @@ public class DefaultObjectWrapperTest {
 
         assertTemplateOutput(OW, iterable, listingFTL, "a, b, c");
     }
-    
+
+    @Test
+    public void testEnumerationAdapter() throws TemplateModelException {
+        DefaultObjectWrapper ow = new DefaultObjectWrapperBuilder(Configuration.VERSION_3_0_0).build();
+        Vector<String> vector = new Vector<String>();
+        vector.add("a");
+        vector.add("b");
+
+        TemplateModel wrappedEnumeration = ow.wrap(vector.elements());
+        assertThat(wrappedEnumeration, instanceOf(DefaultEnumerationAdapter.class));
+        DefaultEnumerationAdapter enumAdapter = (DefaultEnumerationAdapter) wrappedEnumeration;
+        TemplateModelIterator iterator = enumAdapter.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals("a", ((TemplateScalarModel) iterator.next()).getAsString());
+        assertTrue(iterator.hasNext());
+        assertEquals("b", ((TemplateScalarModel) iterator.next()).getAsString());
+        assertFalse(iterator.hasNext());
+
+        iterator = enumAdapter.iterator();
+        try {
+            iterator.hasNext();
+        } catch (TemplateException e) {
+            assertThat(e.getMessage(), containsStringIgnoringCase("only once"));
+        }
+    }
+
     @Test
     public void assertCanWrapDOM() throws SAXException, IOException, ParserConfigurationException,
             TemplateModelException {


Mime
View raw message