CVS: plexus-container-new/src/test/org/apache/plexus/util InterpolationFilterReaderTest.java,1.3,1.4

[email protected] Mon, 19 May 2003 14:03:28 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/util
In directory eng.werken.com:/tmp/cvs-serv28274

Modified Files:
	InterpolationFilterReaderTest.java 
Log Message:
o Adding tests for improvements to interpolator reader that allows arbitrary boundary tokens.
  Using model of qdox as mentioned by Jon Tirsen and making the
  test names very explicit.

Index: InterpolationFilterReaderTest.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/util/InterpolationFilterReaderTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- InterpolationFilterReaderTest.java	27 Apr 2003 16:27:43 -0000	1.3
+++ InterpolationFilterReaderTest.java	19 May 2003 19:03:22 -0000	1.4
@@ -39,7 +39,7 @@
     {
     }
 
-    public void testInterpolation()
+    public void testDefaultInterpolationWithNonInterpolatedValueAtEnd()
         throws Exception
     {
         Map m = new HashMap();
@@ -54,10 +54,25 @@
         IOUtil.copy( reader, writer );
 
         String bar = writer.toString();
+        assertEquals( "jason is an asshole. ${not.interpolated}", bar );
+    }
 
-        System.out.println( "interpolated string: " + bar );
+    public void testDefaultInterpolationWithInterpolatedValueAtEnd()
+        throws Exception
+    {
+        Map m = new HashMap();
+        m.put( "name", "jason" );
+        m.put( "noun", "asshole" );
 
-        assertEquals( "jason is an asshole. ${not.interpolated}", bar );
+        String foo = "${name} is an ${noun}";
+
+        InterpolationFilterReader reader = new InterpolationFilterReader( new StringReader( foo ), m );
+
+        StringWriter writer = new StringWriter();
+        IOUtil.copy( reader, writer );
+
+        String bar = writer.toString();
+        assertEquals( "jason is an asshole", bar );
     }
 
     public void testInterpolationWithContext()
@@ -76,9 +91,60 @@
         IOUtil.copy( reader, writer );
 
         String bar = writer.toString();
+        assertEquals( "jason is an asshole. ${not.interpolated}", bar );
+    }
 
-        System.out.println( "interpolated string: " + bar );
+    public void testInterpolationWithSpecifiedBoundaryTokens()
+        throws Exception
+    {
+        Map m = new HashMap();
+        m.put( "name", "jason" );
+        m.put( "noun", "asshole" );
 
-        assertEquals( "jason is an asshole. ${not.interpolated}", bar );
+        String foo = "@name@ is an @noun@. @not.interpolated@ baby @foo@. @bar@";
+
+        InterpolationFilterReader reader = new InterpolationFilterReader( new StringReader( foo ), m, "@", "@" );
+
+        StringWriter writer = new StringWriter();
+        IOUtil.copy( reader, writer );
+
+        String bar = writer.toString();
+        assertEquals( "jason is an asshole. @not.interpolated@ baby @foo@. @bar@", bar );
+    }
+
+    public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd()
+        throws Exception
+    {
+        Map m = new HashMap();
+        m.put( "name", "jason" );
+        m.put( "noun", "asshole" );
+
+        String foo = "@name@ is an @foobarred@";
+
+        InterpolationFilterReader reader = new InterpolationFilterReader( new StringReader( foo ), m, "@", "@" );
+
+        StringWriter writer = new StringWriter();
+        IOUtil.copy( reader, writer );
+
+        String bar = writer.toString();
+        assertEquals( "jason is an @foobarred@", bar );
+    }
+
+    public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd()
+        throws Exception
+    {
+        Map m = new HashMap();
+        m.put( "name", "jason" );
+        m.put( "noun", "asshole" );
+
+        String foo = "@name@ is an @noun@";
+
+        InterpolationFilterReader reader = new InterpolationFilterReader( new StringReader( foo ), m, "@", "@" );
+
+        StringWriter writer = new StringWriter();
+        IOUtil.copy( reader, writer );
+
+        String bar = writer.toString();
+        assertEquals( "jason is an asshole", bar );
     }
 }