Author: sback
Date: 2007-06-27 23:28:00 +0000 (Wed, 27 Jun 2007)
New Revision: 13792

Modified:
   trunk/freenet/test/freenet/support/SimpleFieldSetTest.java
Log:
Added tests for SFS constructor that take a String to parse as an argument

Modified: trunk/freenet/test/freenet/support/SimpleFieldSetTest.java
===================================================================
--- trunk/freenet/test/freenet/support/SimpleFieldSetTest.java  2007-06-27 
23:26:52 UTC (rev 13791)
+++ trunk/freenet/test/freenet/support/SimpleFieldSetTest.java  2007-06-27 
23:28:00 UTC (rev 13792)
@@ -16,6 +16,8 @@

 package freenet.support;

+import java.io.IOException;
+
 import freenet.node.FSParseException;
 import junit.framework.TestCase;

@@ -26,6 +28,8 @@
  */
 public class SimpleFieldSetTest extends TestCase {

+       private static final char KEY_VALUE_SEPARATOR = '='; 
+       
        /**
         * Test putSingle(String,String) method
         * trying to store a key with two paired
@@ -263,4 +267,53 @@
                                fail("Not expected exception thrown : " + 
aException.getMessage()); }
                }
        }
+       
+       /**
+        * Generates a string for the SFS parser in the canonical form:
+        *  key=value
+        *  END
+        * @param aStringPairsArray
+        * @return a String ready to be read by a SFS parser
+        */
+       private String sfsReadyString(String[][] aStringPairsArray) {
+               String endMarker = "\nEND";
+               String methodStringToReturn = "";
+               for(int i = 0; i < aStringPairsArray.length; i++)
+                       methodStringToReturn += 
aStringPairsArray[i][0]+KEY_VALUE_SEPARATOR+aStringPairsArray[i][1]+'\n';
+               methodStringToReturn += endMarker;
+               return methodStringToReturn;
+       }
+       
+       /**
+        * Test SimpleFieldSet(String,boolean,boolean) constructor,
+        * with a simple string
+        */
+       public void testSimpleFieldSet_StringBooleanBoolean() {
+               String[][] methodStringPair = { {"foo","bar"}};
+               String methodStringToParse = sfsReadyString(methodStringPair);
+               try {
+                       SimpleFieldSet methodSFS = new 
SimpleFieldSet(methodStringToParse,false,false);
+                       
assertEquals(methodSFS.get(methodStringPair[0][0]),methodStringPair[0][1]);
+               } catch (IOException aException) {
+                       fail("Not expected exception thrown : " + 
aException.getMessage()); }
+       }
+       
+       /**
+        * Test SimpleFieldSet(String,boolean,boolean) constructor,
+        * with border cases of the canonical form.
+        */
+       public void testSimpleFieldSet_StringBooleanBoolean_NotCanonical() {
+               String[][] methodStringPairs = 
+                       {  {"foo.bar","foobar"},
+                          {"foo.bar.boo.far","foobar"},
+                          {"foo","foobar.fooboo.foofar.foofoo"},
+                          {"foo2",KEY_VALUE_SEPARATOR+"bar"} };
+               String methodStringToParse = sfsReadyString(methodStringPairs);
+               try {
+                       SimpleFieldSet methodSFS = new 
SimpleFieldSet(methodStringToParse,false,false);
+                       for (int i=0; i < methodStringPairs.length; i++)
+                               
assertEquals(methodSFS.get(methodStringPairs[i][0]),methodStringPairs[i][1]);
+               } catch (IOException aException) {
+                       fail("Not expected exception thrown : " + 
aException.getMessage()); }
+       }
 }


Reply via email to