freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [09/50] [abbrv] incubator-freemarker git commit: Improved TemplateLoader tests a bit.
Date Wed, 01 Mar 2017 14:21:07 GMT
Improved TemplateLoader tests a bit.


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

Branch: refs/heads/2.3
Commit: 2065c57993d083efb2fa3e9785e59cc3bc1a7a38
Parents: d661acc
Author: ddekany <ddekany@apache.org>
Authored: Sun Feb 5 19:17:53 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Sun Feb 5 19:17:53 2017 +0100

----------------------------------------------------------------------
 .../freemarker/cache/TemplateCacheTest.java     |  38 +++-
 .../cache/TemplateNameFormatTest.java           |  16 +-
 .../freemarker/template/ConfigurationTest.java  |  22 +-
 .../template/TemplateLookupStrategyTest.java    | 124 +++++-----
 .../test/MonitoredTemplateLoader.java           | 226 ++++++++++++++++++-
 5 files changed, 338 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2065c579/src/test/java/freemarker/cache/TemplateCacheTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/cache/TemplateCacheTest.java b/src/test/java/freemarker/cache/TemplateCacheTest.java
index b1988b2..417921a 100644
--- a/src/test/java/freemarker/cache/TemplateCacheTest.java
+++ b/src/test/java/freemarker/cache/TemplateCacheTest.java
@@ -19,7 +19,11 @@
 
 package freemarker.cache;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.io.Reader;
@@ -29,12 +33,19 @@ import java.util.Locale;
 import org.hamcrest.Matchers;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 import freemarker.core.ParseException;
 import freemarker.template.Configuration;
 import freemarker.template.MalformedTemplateNameException;
 import freemarker.template.Template;
 import freemarker.template.TemplateNotFoundException;
 import freemarker.template.Version;
+import freemarker.test.MonitoredTemplateLoader;
+import freemarker.test.MonitoredTemplateLoader.CloseTemplateSourceEvent;
+import freemarker.test.MonitoredTemplateLoader.FindTemplateSourceEvent;
+import freemarker.test.MonitoredTemplateLoader.GetLastModifiedEvent;
+import freemarker.test.MonitoredTemplateLoader.GetReaderEvent;
 
 public class TemplateCacheTest {
 
@@ -269,7 +280,7 @@ public class TemplateCacheTest {
         Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
         cfg.setLocale(Locale.US);
         
-        StringTemplateLoader tl = new StringTemplateLoader();
+        MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
         tl.putTemplate("utf-8_en.ftl", "<#ftl encoding='utf-8'>Foo");
         tl.putTemplate("utf-8.ftl", "Bar");
         cfg.setTemplateLoader(tl);
@@ -280,17 +291,38 @@ public class TemplateCacheTest {
             assertEquals("utf-8_en.ftl", t.getSourceName());
             assertEquals("Utf-8", t.getEncoding());
             assertEquals("Foo", t.toString());
+            
+            assertEquals(
+                    ImmutableList.of(
+                            new FindTemplateSourceEvent("utf-8_en_US.ftl", false),
+                            new FindTemplateSourceEvent("utf-8_en.ftl", true),
+                            new GetLastModifiedEvent("utf-8_en.ftl"),
+                            new GetReaderEvent("utf-8_en.ftl"), // Attempt 1
+                            new CloseTemplateSourceEvent("utf-8_en.ftl")),              
 
+                    tl.getEvents());
         }
         
         {
+            tl.clearEvents();
+            
             Template t = cfg.getTemplate("utf-8.ftl", "Utf-16");
             assertEquals("utf-8.ftl", t.getName());
             assertEquals("utf-8_en.ftl", t.getSourceName());
             assertEquals("utf-8", t.getEncoding());
             assertEquals("Foo", t.toString());
+            
+            assertEquals(
+                    ImmutableList.of(
+                            new FindTemplateSourceEvent("utf-8_en_US.ftl", false),
+                            new FindTemplateSourceEvent("utf-8_en.ftl", true),
+                            new GetLastModifiedEvent("utf-8_en.ftl"),
+                            new GetReaderEvent("utf-8_en.ftl"), // Attempt 1
+                            new GetReaderEvent("utf-8_en.ftl"), // Attempt 2
+                            new CloseTemplateSourceEvent("utf-8_en.ftl")),              
 
+                    tl.getEvents());
         }
     }
-
+    
     @Test
     public void testEncodingSelection() throws IOException {
         Locale hungary = new Locale("hu", "HU"); 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2065c579/src/test/java/freemarker/cache/TemplateNameFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/cache/TemplateNameFormatTest.java b/src/test/java/freemarker/cache/TemplateNameFormatTest.java
index 499e751..d001965 100644
--- a/src/test/java/freemarker/cache/TemplateNameFormatTest.java
+++ b/src/test/java/freemarker/cache/TemplateNameFormatTest.java
@@ -19,9 +19,11 @@
 
 package freemarker.cache;
 
-import static freemarker.test.hamcerst.Matchers.*;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static freemarker.test.hamcerst.Matchers.containsStringIgnoringCase;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.util.Locale;
@@ -241,8 +243,8 @@ public class TemplateNameFormatTest {
                             "foo\\bar_en_US.ftl",
                             "foo\\bar_en.ftl",
                             name),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
         }
 
         try {
@@ -255,8 +257,8 @@ public class TemplateNameFormatTest {
                             "foo\\missing_en_US.ftl",
                             "foo\\missing_en.ftl",
                             "foo\\missing.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2065c579/src/test/java/freemarker/template/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/ConfigurationTest.java b/src/test/java/freemarker/template/ConfigurationTest.java
index 585940a..2cba054 100644
--- a/src/test/java/freemarker/template/ConfigurationTest.java
+++ b/src/test/java/freemarker/template/ConfigurationTest.java
@@ -640,28 +640,28 @@ public class ConfigurationTest extends TestCase {
         t.process(null, sw);
         assertEquals(expectedContent, sw.toString());
     }
-    
+
     public void testSetTemplateLoaderAndCache() throws Exception {
         Configuration cfg = new Configuration();
         
-        CacheStorageWithGetSize cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
-        assertEquals(0, cache.getSize());
+        CacheStorageWithGetSize cacheStorage = (CacheStorageWithGetSize) cfg.getCacheStorage();
+        assertEquals(0, cacheStorage.getSize());
         cfg.setCacheStorage(new StrongCacheStorage());
-        cache = (CacheStorageWithGetSize) cfg.getCacheStorage();
-        assertEquals(0, cache.getSize());
+        cacheStorage = (CacheStorageWithGetSize) cfg.getCacheStorage();
+        assertEquals(0, cacheStorage.getSize());
         
         cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
-        assertEquals(0, cache.getSize());
+        assertEquals(0, cacheStorage.getSize());
         cfg.getTemplate("toCache1.ftl");
-        assertEquals(1, cache.getSize());
+        assertEquals(1, cacheStorage.getSize());
         cfg.getTemplate("toCache2.ftl");
-        assertEquals(2, cache.getSize());
+        assertEquals(2, cacheStorage.getSize());
         cfg.setClassForTemplateLoading(ConfigurationTest.class, "");
-        assertEquals(0, cache.getSize());
+        assertEquals(0, cacheStorage.getSize());
         cfg.getTemplate("toCache1.ftl");
-        assertEquals(1, cache.getSize());
+        assertEquals(1, cacheStorage.getSize());
         cfg.setTemplateLoader(cfg.getTemplateLoader());
-        assertEquals(1, cache.getSize());
+        assertEquals(1, cacheStorage.getSize());
     }
 
     public void testChangingLocalizedLookupClearsCache() throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2065c579/src/test/java/freemarker/template/TemplateLookupStrategyTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/TemplateLookupStrategyTest.java b/src/test/java/freemarker/template/TemplateLookupStrategyTest.java
index 2a40c62..7d2f922 100644
--- a/src/test/java/freemarker/template/TemplateLookupStrategyTest.java
+++ b/src/test/java/freemarker/template/TemplateLookupStrategyTest.java
@@ -19,7 +19,11 @@
 
 package freemarker.template;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.io.StringWriter;
@@ -67,8 +71,8 @@ public class TemplateLookupStrategyTest {
             fail();
         } catch (TemplateNotFoundException e) {
             assertEquals("missing.ftl", e.getTemplateName());
-            assertEquals(ImmutableList.of("aa/missing.ftl", "missing.ftl"), tl.getTemplatesTried());
-            tl.clear();
+            assertEquals(ImmutableList.of("aa/missing.ftl", "missing.ftl"), tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -78,8 +82,8 @@ public class TemplateLookupStrategyTest {
             assertEquals("aa/test.ftl", t.getSourceName());
             assertEquals(locale, t.getLocale());
             assertNull(t.getCustomLookupCondition());
-            assertEquals(ImmutableList.of("aa/test.ftl"), tl.getTemplatesTried());
-            tl.clear();
+            assertEquals(ImmutableList.of("aa/test.ftl"), tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
     }
@@ -108,8 +112,8 @@ public class TemplateLookupStrategyTest {
                             "missing_aa_BB.ftl",
                             "missing_aa.ftl",
                             "missing.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -121,8 +125,8 @@ public class TemplateLookupStrategyTest {
             assertEquals("missing.ftl", e.getTemplateName());
             assertEquals(
                     ImmutableList.of("missing_xx.ftl", "missing.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -134,8 +138,8 @@ public class TemplateLookupStrategyTest {
             assertEquals("missing.ftl", e.getTemplateName());
             assertEquals(
                     ImmutableList.of("missing.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         cfg.setLocalizedLookup(true);
@@ -147,8 +151,8 @@ public class TemplateLookupStrategyTest {
             assertEquals("_a_b_.ftl", e.getTemplateName());
             assertEquals(
                     ImmutableList.of("_a_b__xx_YY.ftl", "_a_b__xx.ftl", "_a_b_.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
 
@@ -160,9 +164,9 @@ public class TemplateLookupStrategyTest {
                 assertEquals("test_aa_BB_CC_DD.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
-                assertEquals(ImmutableList.of("test_aa_BB_CC_DD.ftl"), tl.getTemplatesTried());
+                assertEquals(ImmutableList.of("test_aa_BB_CC_DD.ftl"), tl.getNamesSearched());
                 assertNull(t.getCustomLookupCondition());
-                tl.clear();
+                tl.clearEvents();
                 cfg.clearTemplateCache();
             }
             
@@ -173,8 +177,8 @@ public class TemplateLookupStrategyTest {
                 assertEquals("test_aa_BB_CC.ftl", t.getSourceName());
                 assertEquals(locale, t.getLocale());
                 assertNull(t.getCustomLookupCondition());
-                assertEquals(ImmutableList.of("test_aa_BB_CC_XX.ftl", "test_aa_BB_CC.ftl"),
tl.getTemplatesTried());
-                tl.clear();
+                assertEquals(ImmutableList.of("test_aa_BB_CC_XX.ftl", "test_aa_BB_CC.ftl"),
tl.getNamesSearched());
+                tl.clearEvents();
                 cfg.clearTemplateCache();
             }
             
@@ -187,8 +191,8 @@ public class TemplateLookupStrategyTest {
                 assertNull(t.getCustomLookupCondition());
                 assertEquals(
                         ImmutableList.of("test_aa_BB_XX_XX.ftl", "test_aa_BB_XX.ftl", "test_aa_BB.ftl"),
-                        tl.getTemplatesTried());
-                tl.clear();
+                        tl.getNamesSearched());
+                tl.clearEvents();
                 cfg.clearTemplateCache();
             }
     
@@ -202,8 +206,8 @@ public class TemplateLookupStrategyTest {
                 assertNull(t.getCustomLookupCondition());
                 assertEquals(
                         ImmutableList.of("test.ftl"),
-                        tl.getTemplatesTried());
-                tl.clear();
+                        tl.getNamesSearched());
+                tl.clearEvents();
                 cfg.clearTemplateCache();
                 cfg.setLocalizedLookup(true);
             }
@@ -217,8 +221,8 @@ public class TemplateLookupStrategyTest {
                 assertNull(t.getCustomLookupCondition());
                 assertEquals(
                         ImmutableList.of("test_aa_XX_XX_XX.ftl", "test_aa_XX_XX.ftl", "test_aa_XX.ftl",
"test_aa.ftl"),
-                        tl.getTemplatesTried());
-                tl.clear();
+                        tl.getNamesSearched());
+                tl.clearEvents();
                 cfg.clearTemplateCache();
             }
             
@@ -232,8 +236,8 @@ public class TemplateLookupStrategyTest {
                 assertEquals(
                         ImmutableList.of(
                                 "test_xx_XX_XX_XX.ftl", "test_xx_XX_XX.ftl", "test_xx_XX.ftl",
"test_xx.ftl", "test.ftl"),
-                        tl.getTemplatesTried());
-                tl.clear();
+                        tl.getNamesSearched());
+                tl.clearEvents();
                 cfg.clearTemplateCache();
             }
             
@@ -247,8 +251,8 @@ public class TemplateLookupStrategyTest {
                 assertEquals(
                         ImmutableList.of(
                             "test_xx_BB_CC_DD.ftl", "test_xx_BB_CC.ftl", "test_xx_BB.ftl",
"test_xx.ftl", "test.ftl"),
-                        tl.getTemplatesTried());
-                tl.clear();
+                        tl.getNamesSearched());
+                tl.clearEvents();
                 cfg.clearTemplateCache();
             }
         }
@@ -276,8 +280,8 @@ public class TemplateLookupStrategyTest {
                     ImmutableList.of(
                         "x/y/sub/i_xx.ftl", "x/sub/i_xx.ftl", "sub/i_xx.ftl",
                         "x/y/sub/i.ftl", "x/sub/i.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
 
@@ -291,8 +295,8 @@ public class TemplateLookupStrategyTest {
                     ImmutableList.of(
                         "a/b/sub/i_xx.ftl", "a/sub/i_xx.ftl", "sub/i_xx.ftl",
                         "a/b/sub/i.ftl", "a/sub/i.ftl", "sub/i.ftl"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
     }
@@ -344,15 +348,15 @@ public class TemplateLookupStrategyTest {
             assertEquals(tAtFooComContent, t.toString());
             assertEquals(
                     ImmutableList.of("@foo.com/t_xx.ftl", "@foo.com/t.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             assertOutputEquals(tAtFooComWithoutIncludeContent + iAtFooComContent, t);
             assertEquals(
                     ImmutableList.of("@foo.com/i_xx.ftl", "@foo.com/i.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
 
@@ -367,17 +371,17 @@ public class TemplateLookupStrategyTest {
             assertEquals(tAtBarComContent, t.toString());
             assertEquals(
                     ImmutableList.of("@bar.com/t_xx.ftl", "@bar.com/t.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             assertOutputEquals(tAtBarComWithoutIncludeContent + iXxAtDefaultContent, t);
             assertEquals(
                     ImmutableList.of(
                             "@bar.com/i_xx.ftl", "@bar.com/i.ftl",
                             "@default/i_xx.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -394,15 +398,15 @@ public class TemplateLookupStrategyTest {
                     ImmutableList.of(
                             "@baaz.com/t_xx_YY.ftl", "@baaz.com/t_xx.ftl", "@baaz.com/t.ftl",
                             "@default/t_xx_YY.ftl", "@default/t_xx.ftl", "@default/t.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             assertOutputEquals(tAtDefaultWithoutIncludeContent + iAtBaazComContent, t);
             assertEquals(
                     ImmutableList.of("@baaz.com/i_xx_YY.ftl", "@baaz.com/i_xx.ftl", "@baaz.com/i.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -419,9 +423,9 @@ public class TemplateLookupStrategyTest {
                     ImmutableList.of(
                             "@nosuch.com/i_xx_YY.ftl", "@nosuch.com/i_xx.ftl", "@nosuch.com/i.ftl",
                             "@default/i_xx_YY.ftl", "@default/i_xx.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
 
@@ -437,9 +441,9 @@ public class TemplateLookupStrategyTest {
             assertEquals(iAtDefaultContent, t.toString());
             assertEquals(
                     ImmutableList.of("@nosuch.com/i.ftl", "@default/i.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.setLocalizedLookup(true);
             cfg.clearTemplateCache();
         }
@@ -454,9 +458,9 @@ public class TemplateLookupStrategyTest {
                             "@foo.com/t2_xx.ftl", "@foo.com/t2.ftl",
                             "@foo.com/i2_xx.ftl", "@foo.com/i2.ftl", "@default/i2_xx.ftl",
"@default/i2.ftl",
                             "@foo.com/i3_xx.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -470,9 +474,9 @@ public class TemplateLookupStrategyTest {
                             "@foo.com/t2_yy.ftl", "@foo.com/t2.ftl",
                             "@foo.com/i2_yy.ftl", "@foo.com/i2.ftl", "@default/i2_yy.ftl",
"@default/i2.ftl",
                             "@foo.com/i3_yy.ftl", "@foo.com/i3.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -487,9 +491,9 @@ public class TemplateLookupStrategyTest {
                             "@foo.com/t2.ftl",
                             "@foo.com/i2.ftl", "@default/i2.ftl",
                             "@foo.com/i3.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.setLocalizedLookup(true);
             cfg.clearTemplateCache();
         }
@@ -500,9 +504,9 @@ public class TemplateLookupStrategyTest {
             cfg.getTemplate("i3.ftl", locale, domain, "utf-8", true, false); 
             assertEquals(
                     ImmutableList.of("@foo.com/i3_xx.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -519,9 +523,9 @@ public class TemplateLookupStrategyTest {
                     ImmutableList.of(
                             "@bar.com/i3_xx.ftl", "@bar.com/i3.ftl",
                             "@default/i3_xx.ftl", "@default/i3.ftl"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
             
-            tl.clear();
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -546,8 +550,8 @@ public class TemplateLookupStrategyTest {
                             "missing_aa_BB.txt",
                             "missing_aa.txt",
                             "missing.txt"),
-                    tl.getTemplatesTried());
-            tl.clear();
+                    tl.getNamesSearched());
+            tl.clearEvents();
             cfg.clearTemplateCache();
         }
         
@@ -559,7 +563,7 @@ public class TemplateLookupStrategyTest {
                     ImmutableList.of(
                             "test_aa_BB.txt",
                             "test_aa.txt"),
-                    tl.getTemplatesTried());
+                    tl.getNamesSearched());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2065c579/src/test/java/freemarker/test/MonitoredTemplateLoader.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/test/MonitoredTemplateLoader.java b/src/test/java/freemarker/test/MonitoredTemplateLoader.java
index e088ab3..f51b109 100644
--- a/src/test/java/freemarker/test/MonitoredTemplateLoader.java
+++ b/src/test/java/freemarker/test/MonitoredTemplateLoader.java
@@ -19,28 +19,240 @@
 
 package freemarker.test;
 
+import java.io.Reader;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import freemarker.cache.StringTemplateLoader;
 
 public class MonitoredTemplateLoader extends StringTemplateLoader {
     
-    private final List<String> templatesTried = new ArrayList<String>();
+    List<AbstractTemplateLoaderEvent> events = Collections.synchronizedList(new ArrayList<AbstractTemplateLoaderEvent>());
     
     @Override
     public Object findTemplateSource(String name) {
-        templatesTried.add(name);
-        return super.findTemplateSource(name);
+        FindTemplateSourceEvent event = new FindTemplateSourceEvent(name, null);
+        events.add(event);
+        Object result = super.findTemplateSource(name);
+        event.setFound(result != null);
+        return result;
     }
 
-    public List<String> getTemplatesTried() {
-        return templatesTried;
+    public void clearEvents() {
+        events.clear();
     }
     
-    public void clear() {
-        templatesTried.clear();
+    @Override
+    public void closeTemplateSource(Object templateSource) {
+        events.add(new CloseTemplateSourceEvent(templateSource.toString()));
+        super.closeTemplateSource(templateSource);
+    }
+
+    @Override
+    public Reader getReader(Object templateSource, String encoding) {
+        events.add(new GetReaderEvent(templateSource.toString()));
+        return super.getReader(templateSource, encoding);
+    }
+
+    @Override
+    public long getLastModified(Object templateSource) {
+        events.add(new GetLastModifiedEvent(templateSource.toString()));
+        return super.getLastModified(templateSource);
+    }
+    
+    public List<AbstractTemplateLoaderEvent> getEvents() {
+        return events;
+    }
+    
+    public List<String> getNamesSearched() {
+        ArrayList<String> result = new ArrayList<String>();
+        for (AbstractTemplateLoaderEvent event : events) {
+            if (event instanceof FindTemplateSourceEvent) {
+                result.add(((FindTemplateSourceEvent) event).getName());
+            }
+        }
+        return result;
+    }
+
+    public static abstract class AbstractTemplateLoaderEvent {
+        // empty
+    }
+    
+    public static class FindTemplateSourceEvent extends AbstractTemplateLoaderEvent {
+        private final String name;
+        private Boolean found;
+        
+        public FindTemplateSourceEvent(String name, Boolean found) {
+            this.name = name;
+            this.found = found;
+        }
+        
+        public void setFound(boolean found) {
+            this.found = found;
+        }
+        
+        public Boolean getFound() {
+            return found;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((found == null) ? 0 : found.hashCode());
+            result = prime * result + ((name == null) ? 0 : name.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            FindTemplateSourceEvent other = (FindTemplateSourceEvent) obj;
+            if (found == null) {
+                if (other.found != null)
+                    return false;
+            } else if (!found.equals(other.found))
+                return false;
+            if (name == null) {
+                if (other.name != null)
+                    return false;
+            } else if (!name.equals(other.name))
+                return false;
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            return "FindTemplateSourceEvent [name=" + name + ", found=" + found + "]";
+        }
+        
     }
+
+    public static class GetLastModifiedEvent extends AbstractTemplateLoaderEvent {
+        private final String sourceName;
+    
+        public GetLastModifiedEvent(String sourceName) {
+            this.sourceName = sourceName;
+        }
+    
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((sourceName == null) ? 0 : sourceName.hashCode());
+            return result;
+        }
+    
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            GetLastModifiedEvent other = (GetLastModifiedEvent) obj;
+            if (sourceName == null) {
+                if (other.sourceName != null)
+                    return false;
+            } else if (!sourceName.equals(other.sourceName))
+                return false;
+            return true;
+        }
     
+        @Override
+        public String toString() {
+            return "GetLastModifiedEvent [sourceName=" + sourceName + "]";
+        }
+        
+    }
+    
+    public static class GetReaderEvent extends AbstractTemplateLoaderEvent {
+        private final String sourceName;
+
+        public GetReaderEvent(String sourceName) {
+            this.sourceName = sourceName;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((sourceName == null) ? 0 : sourceName.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            GetReaderEvent other = (GetReaderEvent) obj;
+            if (sourceName == null) {
+                if (other.sourceName != null)
+                    return false;
+            } else if (!sourceName.equals(other.sourceName))
+                return false;
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            return "GetReaderEvent [sourceName=" + sourceName + "]";
+        }
+        
+    }
+
+    public static class CloseTemplateSourceEvent extends AbstractTemplateLoaderEvent {
+        private final String sourceName;
+
+        public CloseTemplateSourceEvent(String sourceName) {
+            this.sourceName = sourceName;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((sourceName == null) ? 0 : sourceName.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            CloseTemplateSourceEvent other = (CloseTemplateSourceEvent) obj;
+            if (sourceName == null) {
+                if (other.sourceName != null)
+                    return false;
+            } else if (!sourceName.equals(other.sourceName))
+                return false;
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            return "CloseTemplateSourceEvent [sourceName=" + sourceName + "]";
+        }
+        
+    }
     
 }
\ No newline at end of file


Mime
View raw message