You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dl...@apache.org on 2003/01/13 20:29:39 UTC

cvs commit: jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration TestBasePropertiesConfiguration.java

dlr         2003/01/13 11:29:39

  Modified:    configuration/conf test.properties
               configuration/src/java/org/apache/commons/configuration
                        BasePropertiesConfiguration.java
               configuration/src/test/org/apache/commons/configuration
                        TestBasePropertiesConfiguration.java
  Log:
  * conf/test.properties
    Added new test.empty property, with a value of the empty string.
  
  * src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
    Changed the behavior of the load(InputStream input, String enc)
    method to more closely emulate java.util.Properties' handling of
    empty property values.  Previously, properties with empty values
    were completely ignored, rather than being considered semantically
    equivalent to a property with no value (the semantics of a vanilla
    Properties object).  This is a backwards incompatible change, but in
    most cases should not be noticable.
  
    Changed writeProperty(String key, String value) to output the empty
    string for null property values.
  
  * src/test/org/apache/commons/configuration/TestBasePropertiesConfiguration.java
    Added tests for the new behavior of BasePropertiesConfiguration's
    load() method using the test.empty property.
  
  Revision  Changes    Path
  1.4       +2 -0      jakarta-commons-sandbox/configuration/conf/test.properties
  
  Index: test.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/conf/test.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- test.properties	21 Dec 2002 17:12:06 -0000	1.3
  +++ test.properties	13 Jan 2003 19:29:38 -0000	1.4
  @@ -10,6 +10,8 @@
   
   test.equals = value=one
   
  +test.empty=
  +
   #
   # Non String Properties
   #
  
  
  
  1.4       +11 -12    jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
  
  Index: BasePropertiesConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- BasePropertiesConfiguration.java	7 Jan 2003 22:53:36 -0000	1.3
  +++ BasePropertiesConfiguration.java	13 Jan 2003 19:29:38 -0000	1.4
  @@ -232,16 +232,12 @@
               {
                   String key = line.substring(0, equalSign).trim();
                   String value = line.substring(equalSign + 1).trim();
  -                
  -                /*
  -                 * Configure produces lines like this ... just
  -                 * ignore them.
  -                 */
  -                if (StringUtils.isEmpty(value))
  -                {
  -                    continue; // do .. while
  -                }
  -                
  +
  +                // Though some software (e.g. autoconf) may produce
  +                // empty values like foo=\n, emulate the behavior of
  +                // java.util.Properties by setting the value to the
  +                // empty string.
  +
                   if (StringUtils.isNotEmpty(getInclude())
                       && key.equalsIgnoreCase(getInclude()))
                   {
  @@ -425,7 +421,10 @@
           public void writeProperty(String key, String value)
               throws IOException
           {
  -            write(key + " = " + value + "\n");
  +            write(key);
  +            write(" = ");
  +            write(value != null ? value : "");
  +            write('\n');
           }
   
           /**
  
  
  
  1.2       +12 -0     jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestBasePropertiesConfiguration.java
  
  Index: TestBasePropertiesConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestBasePropertiesConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- TestBasePropertiesConfiguration.java	11 Jan 2003 00:55:02 -0000	1.1
  +++ TestBasePropertiesConfiguration.java	13 Jan 2003 19:29:38 -0000	1.2
  @@ -94,6 +94,18 @@
       }
   
       /**
  +     * Tests that empty properties are treated as the empty string
  +     * (rather than as null).
  +     */
  +    public void testEmpty()
  +      throws Exception
  +    {
  +        String empty = conf.getString("test.empty");
  +        assertNotNull(empty);
  +        assertEquals("", empty);
  +    }
  +
  +    /**
        * test if includes properties get loaded too
        */
       public void testLoadInclude()
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>