You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by he...@apache.org on 2002/12/14 13:07:01 UTC

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

henning     2002/12/14 04:07:01

  Modified:    configuration/conf test.properties
               configuration/src/java/org/apache/commons/configuration
                        BasePropertiesConfiguration.java
  Added:       configuration/src/test/org/apache/commons/configuration
                        TestEqualsProperty.java
  Log:
  Brought back the old split code for the property lines, else we would have
  gotten a regression with lines like   "foo.bar =   xxx=0" in the properties
  file.
  
  Added a test case for this.
  
  Revision  Changes    Path
  1.2       +7 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test.properties	10 Dec 2002 23:39:41 -0000	1.1
  +++ test.properties	14 Dec 2002 12:07:01 -0000	1.2
  @@ -4,3 +4,10 @@
   
   include = include.properties
   
  +#
  +# Other test properties
  +#
  +
  +test.equals = value=one
  +
  +
  
  
  
  1.2       +5 -6      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasePropertiesConfiguration.java	14 Dec 2002 11:33:46 -0000	1.1
  +++ BasePropertiesConfiguration.java	14 Dec 2002 12:07:01 -0000	1.2
  @@ -227,12 +227,11 @@
                   break; // EOF
               }
               
  -            String [] parts = StringUtils.split(line, "=");
  -            
  -            if (parts.length >= 2)
  +            int equalSign = line.indexOf('=');
  +            if (equalSign > 0)
               {
  -                String key   = parts[0].trim();
  -                String value = parts[1].trim();
  +                String key = line.substring(0, equalSign).trim();
  +                String value = line.substring(equalSign + 1).trim();
                   
                   /*
                    * Configure produces lines like this ... just
  
  
  
  1.1                  jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestEqualsProperty.java
  
  Index: TestEqualsProperty.java
  ===================================================================
  package org.apache.commons.configuration;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.File;
  import java.io.InputStream;
  
  import java.util.Vector;
  
  import junit.framework.TestCase;
  
  /**
   * test if properties that contain a "=" will be loaded correctly.
   *
   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
   * @version $Id: TestEqualsProperty.java,v 1.1 2002/12/14 12:07:01 henning Exp $
   */
  public class TestEqualsProperty
      extends TestCase
  {
      /** The File that we test with */
      private String testProperties = 
          new File("conf/test.properties").getAbsolutePath();
  
      public TestEqualsProperty(String s)
      {
          super(s);
      }
  
      public void testEquals()
        throws Exception
      {
          PropertiesConfiguration conf =
              new PropertiesConfiguration(testProperties);
  
          String equals = conf.getString("test.equals");
          assertEquals("value=one", equals);
      }
  }
  
  
  

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