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: TemplateTest now detects bugs where the output Writer is closed to early
Date Wed, 27 Sep 2017 22:05:36 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 f5a44238e -> 59d2f30b7


TemplateTest now detects bugs where the output Writer is closed to early


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

Branch: refs/heads/3
Commit: 59d2f30b72f0cb9e843646451563ff76d184455e
Parents: f5a4423
Author: ddekany <ddekany@apache.org>
Authored: Thu Sep 28 00:05:26 2017 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Thu Sep 28 00:05:26 2017 +0200

----------------------------------------------------------------------
 .../apache/freemarker/test/TemplateTest.java    | 35 +++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/59d2f30b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
----------------------------------------------------------------------
diff --git a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
index dce3719..00d9306 100644
--- a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
+++ b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
@@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.*;
 
 import java.io.FileNotFoundException;
+import java.io.FilterWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -135,7 +136,39 @@ public abstract class TemplateTest {
     
     protected String getOutput(Template t) throws TemplateException, IOException {
         StringWriter out = new StringWriter();
-        t.process(getDataModel(), out);
+        t.process(getDataModel(), new FilterWriter(out) {
+            private boolean closed;
+
+            @Override
+            public void write(int c) throws IOException {
+                checkNotClosed();
+                super.write(c);
+            }
+
+            @Override
+            public void write(char[] cbuf, int off, int len) throws IOException {
+                checkNotClosed();
+                super.write(cbuf, off, len);
+            }
+
+            @Override
+            public void write(String str, int off, int len) throws IOException {
+                checkNotClosed();
+                super.write(str, off, len);
+            }
+
+            @Override
+            public void close() throws IOException {
+                super.close();
+                closed = true;
+            }
+            
+            private void checkNotClosed() throws IOException {
+                if (closed) {
+                    throw new IOException("Writer is already closed");
+                }
+            }
+        });
         return out.toString();
     }
     


Mime
View raw message