commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevencasw...@apache.org
Subject svn commit: r234402 - /jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesTest.java
Date Mon, 22 Aug 2005 00:51:16 GMT
Author: stevencaswell
Date: Sun Aug 21 17:51:14 2005
New Revision: 234402

URL: http://svn.apache.org/viewcvs?rev=234402&view=rev
Log:
increase Entities test coverage as reported by clover

Modified:
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesTest.java

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesTest.java?rev=234402&r1=234401&r2=234402&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/EntitiesTest.java Sun
Aug 21 17:51:14 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.commons.lang;
 
+import java.io.StringWriter;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -55,13 +57,21 @@
 
     public void testEscapeNamedEntity() throws Exception
     {
-        assertEquals("&foo;", entities.escape("\u00A1"));
-        assertEquals("x&foo;", entities.escape("x\u00A1"));
-        assertEquals("&foo;x", entities.escape("\u00A1x"));
-        assertEquals("x&foo;x", entities.escape("x\u00A1x"));
-        assertEquals("&foo;&bar;", entities.escape("\u00A1\u00A2"));
+        doTestEscapeNamedEntity("&foo;", "\u00A1");
+        doTestEscapeNamedEntity("x&foo;", "x\u00A1");
+        doTestEscapeNamedEntity("&foo;x", "\u00A1x");
+        doTestEscapeNamedEntity("x&foo;x", "x\u00A1x");
+        doTestEscapeNamedEntity("&foo;&bar;", "\u00A1\u00A2");
     }
 
+    private void doTestEscapeNamedEntity(final String expected, final String entity) throws
Exception
+    {
+        assertEquals(expected, entities.escape(entity));
+        StringWriter writer = new StringWriter();
+        entities.escape(writer, entity);
+        assertEquals(expected, writer.toString());
+    }
+    
     public void testUnescapeNamedEntity() throws Exception
     {
         assertEquals("\u00A1", entities.unescape("&foo;"));
@@ -73,9 +83,26 @@
 
     public void testUnescapeUnknownEntity() throws Exception
     {
-        assertEquals("&zzzz;", entities.unescape("&zzzz;"));
+        doTestUnescapeEntity("&zzzz;", "&zzzz;");
     }
 
+    public void testUnescapeMiscellaneous() throws Exception
+    {
+      doTestUnescapeEntity("&hello", "&hello");
+      doTestUnescapeEntity("&;", "&;");
+      doTestUnescapeEntity("&#;", "&#;");
+      doTestUnescapeEntity("&#invalid;", "&#invalid;");
+      doTestUnescapeEntity("A", "A");
+    }
+    
+    private void doTestUnescapeEntity(final String expected, final String entity) throws
Exception
+    {
+        assertEquals(expected, entities.unescape(entity));
+        StringWriter writer = new StringWriter();
+        entities.unescape(writer, entity);
+        assertEquals(expected, writer.toString());
+    }
+    
     public void testAddEntitiesArray() throws Exception
     {
         String[][] array = {{"foo", "100"}, {"bar", "101"}};
@@ -98,6 +125,10 @@
     {
         Entities.ArrayEntityMap map = new Entities.ArrayEntityMap(2);
         checkSomeEntityMap(map);
+        Entities.ArrayEntityMap map1 = new Entities.ArrayEntityMap();
+        checkSomeEntityMap(map1);
+        assertEquals(-1, map.value("null"));
+        assertNull(map.name(-1));
     }
 
     public void testTreeIntMap() throws Exception
@@ -110,12 +141,34 @@
     {
         Entities.EntityMap map = new Entities.HashEntityMap();
         checkSomeEntityMap(map);
+        assertEquals(-1, map.value("noname"));
     }
 
     public void testBinaryIntMap() throws Exception
     {
         Entities.BinaryEntityMap map = new Entities.BinaryEntityMap(2);
         checkSomeEntityMap(map);
+        Entities.BinaryEntityMap map1 = new Entities.BinaryEntityMap();
+        checkSomeEntityMap(map1);
+        
+        // value cannot be added twice
+        map1.add("baz4a", 4);
+        map1.add("baz4b", 4);
+        assertEquals(-1, map1.value("baz4b"));
+        assertEquals("baz4a", map1.name(4));
+        assertNull(map1.name(99));
+        
+        Entities.BinaryEntityMap map2 = new Entities.BinaryEntityMap();
+        map2.add("val1", 1);
+        map2.add("val2", 2);
+        map2.add("val3", 3);
+        map2.add("val4", 4);
+        map2.add("val5", 5);
+        assertEquals("val5", map2.name(5));
+        assertEquals("val4", map2.name(4));
+        assertEquals("val3", map2.name(3));
+        assertEquals("val2", map2.name(2));
+        assertEquals("val1", map2.name(1));
     }
 
     public void testPrimitiveIntMap() throws Exception
@@ -133,7 +186,7 @@
         assertEquals(3, map.value("baz"));
         assertEquals("baz", map.name(3));
     }
-
+    
     public void testHtml40Nbsp() throws Exception
     {
         assertEquals(" ", Entities.HTML40.escape("\u00A0"));



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message