commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt TestDescriptors.java
Date Fri, 16 May 2003 13:32:00 GMT
rdonkin     2003/05/16 06:32:00

  Modified:    betwixt/src/java/org/apache/commons/betwixt
                        ElementDescriptor.java
  Added:       betwixt/src/test/org/apache/commons/betwixt
                        TestDescriptors.java
  Log:
  Fixed bug involving some properties not correctly dealing with lazily loading of lists.
Also added test case. Submitted by Neeme Praks.
  
  Revision  Changes    Path
  1.9       +13 -7     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java
  
  Index: ElementDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ElementDescriptor.java	19 Mar 2003 22:59:01 -0000	1.8
  +++ ElementDescriptor.java	16 May 2003 13:32:00 -0000	1.9
  @@ -80,18 +80,24 @@
   
       /** 
        * Descriptors for attributes this element contains.
  -     * Constructed lazily on demand from a List
  +     * <strong>Note:</strong> Constructed lazily on demand from a List.
  +     * {@link #getAttributeDescriptor()} should be called rather than accessing this
  +     * field directly.
        */
       private AttributeDescriptor[] attributeDescriptors;
       /** 
        * Descriptors for child elements.
  -     * Constructed lazily on demand from a List
  +     * <strong>Note:</strong> Constructed lazily on demand from a List.
  +     * {@link #getElementDescriptor()} should be called rather than accessing this
  +     * field directly.
        */
       private ElementDescriptor[] elementDescriptors;
       
       /** 
  -     * Descriptors for child content
  -     * Constructed lazily on demand from a List.
  +     * Descriptors for child content.
  +     * <strong>Note:</strong> Constructed lazily on demand from a List.
  +     * {@link #getContentDescriptor()} should be called rather than accessing this
  +     * field directly.
        */
       private Descriptor[] contentDescriptors;
       
  @@ -168,7 +174,7 @@
        * @see #getElementDescriptors
        */
       public boolean hasChildren() {
  -        return elementDescriptors != null && elementDescriptors.length > 0;
  +        return getElementDescriptors().length > 0;
       }
       
       /** 
  @@ -177,7 +183,7 @@
        * @see #getAttributeDescriptors
        */
       public boolean hasAttributes() {
  -        return attributeDescriptors != null && attributeDescriptors.length >
0;
  +        return getAttributeDescriptors().length > 0;
       }
       
       /** 
  @@ -186,7 +192,7 @@
        * @see #getContentDescriptors
        */
       public boolean hasContent() {
  -        return contentDescriptors != null && contentDescriptors.length > 0;

  +        return getContentDescriptors().length > 0; 
        } 
       
       
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestDescriptors.java
  
  Index: TestDescriptors.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestDescriptors.java,v
1.1 2003/05/16 13:32:00 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/05/16 13:32:00 $
   *
   * ====================================================================
   *
   * 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/>.
   * 
   * $Id: TestDescriptors.java,v 1.1 2003/05/16 13:32:00 rdonkin Exp $
   */
  package org.apache.commons.betwixt;
  
  import java.io.ByteArrayOutputStream;
  import java.io.PrintStream;
  import java.io.StringWriter;
  
  import java.util.ArrayList;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.betwixt.io.BeanWriter;
  import org.apache.commons.betwixt.io.CyclicReferenceException;
  import org.apache.commons.logging.impl.SimpleLog;
  import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
  import org.apache.commons.betwixt.strategy.CapitalizeNameMapper;
  import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
  
  /** Test harness for the Descriptors (ElementDescriptor and so on).
    *
    * @author Robert Burrell Donkin
    * @version $Revision: 1.1 $
    */
  public class TestDescriptors extends AbstractTestCase {
      
      public static void main( String[] args ) {
          TestRunner.run( suite() );
      }
      
      public static Test suite() {
          return new TestSuite(TestDescriptors.class);
      }
      
      public TestDescriptors(String testName) {
          super(testName);
      }
      
      public void testElementDescriptorLazyInit() {
          ElementDescriptor descriptor = new ElementDescriptor();
          
          // check for NPEs
          assertTrue("Empty descriptor has no children", !descriptor.hasChildren());
          assertTrue("Empty descriptor has no content", !descriptor.hasContent());
          assertTrue("Empty descriptor has no attributes", !descriptor.hasAttributes());
          
          // add an attribute and make sure everything works
          descriptor.addAttributeDescriptor(new AttributeDescriptor("test:one"));
          assertTrue("Empty descriptor has no children", !descriptor.hasChildren());
          assertTrue("Empty descriptor has no content", !descriptor.hasContent());
          assertTrue("Descriptor has attributes (1)", descriptor.hasAttributes());       

                  
          // add an element and make sure everything works
          descriptor.addElementDescriptor(new ElementDescriptor("test:two"));
          assertTrue("Descriptor has children (1)", descriptor.hasChildren());
          assertTrue("Descriptor has content (1)", descriptor.hasContent());
          assertTrue("Descriptor has attributes (2)", descriptor.hasAttributes());       

          
          // start again and test in reverse order
          descriptor = new ElementDescriptor();
          
          // add an element and make sure everything works
          descriptor.addElementDescriptor(new ElementDescriptor("test:one"));
          assertTrue("Descriptor has children (2)", descriptor.hasChildren());
          assertTrue("Descriptor has content (2)", descriptor.hasContent());
          assertTrue("Descriptor has no attributes (1)", !descriptor.hasAttributes());   
  
          
          // add an attribute and make sure everything works
          descriptor.addAttributeDescriptor(new AttributeDescriptor("test:two"));
          assertTrue("Descriptor has children (3)", descriptor.hasChildren());
          assertTrue("Descriptor has content (3)", descriptor.hasContent());
          assertTrue("Descriptor has attributes (2)", descriptor.hasAttributes());       

          
          // try adding content
          descriptor = new ElementDescriptor();
          descriptor.addContentDescriptor(new AttributeDescriptor("test:one"));
          assertTrue("Descriptor has no children (1)", !descriptor.hasChildren());
          assertTrue("Descriptor has content (3)", descriptor.hasContent());
          assertTrue("Descriptor has no attributes (2)", !descriptor.hasAttributes());   
    
          
          // add an element and make sure everything works
          descriptor.addElementDescriptor(new ElementDescriptor("test:two"));
          assertTrue("Descriptor has children (4)", descriptor.hasChildren());
          assertTrue("Descriptor has content (4)", descriptor.hasContent());
          assertTrue("Descriptor has no attributes (3)", !descriptor.hasAttributes());   
  
          
          // add an attribute and make sure everything works
          descriptor.addAttributeDescriptor(new AttributeDescriptor("test:three"));
          assertTrue("Descriptor has children (5)", descriptor.hasChildren());
          assertTrue("Descriptor has content (5)", descriptor.hasContent());
          assertTrue("Descriptor has attributes (3)", descriptor.hasAttributes());       
      }
  }
  
  
  
  

---------------------------------------------------------------------
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