avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: avalon-sandbox/merlin/meta-spi/src/test/org/apache/avalon/meta/model/test EntryTestCase.java ParameterTestCase.java
Date Tue, 08 Jul 2003 20:44:37 GMT
bloritsch    2003/07/08 13:44:37

  Modified:    merlin/meta-spi/src/java/org/apache/avalon/meta/model
                        Parameter.java
  Added:       merlin/meta-spi/src/test/org/apache/avalon/meta/model/test
                        EntryTestCase.java ParameterTestCase.java
  Log:
  Test the Paramter classes
  
  Revision  Changes    Path
  1.3       +10 -18    avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Parameter.java
  
  Index: Parameter.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Parameter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Parameter.java	4 Apr 2003 12:19:19 -0000	1.2
  +++ Parameter.java	8 Jul 2003 20:44:36 -0000	1.3
  @@ -86,7 +86,7 @@
    * @see Import
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$ $Date$
  - * @todo Fix usage of basic type (int, float, long, etc.) - how do we return 
  + * @todo Fix usage of basic type (int, float, long, etc.) - how do we return
    *   basic types - can't use getValue() becuase it returns an Object unless
    *   have some way of packing the basic type into a carrier
    */
  @@ -121,6 +121,8 @@
        */
       public Parameter( final String value )
       {
  +        if ( null == value ) throw new NullPointerException("value");
  +
           m_parameters = new Parameter[ 0 ];
           m_classname = "java.lang.String";
           m_argument = value;
  @@ -160,6 +162,11 @@
               throw new NullPointerException( "classname" );
           }
   
  +        if( null == parameters )
  +        {
  +            throw new NullPointerException( "parameters" );
  +        }
  +
           m_classname = classname;
           m_parameters = parameters;
       }
  @@ -293,7 +300,7 @@
                   //
   
                   Class clazz = getParameterClass( loader );
  -                
  +
                   try
                   {
                       final Class[] params = new Class[]{String.class};
  @@ -434,20 +441,6 @@
           }
       }
   
  -    private String getClassesAsString( Class[] classes )
  -    {
  -        StringBuffer buffer = new StringBuffer();
  -        for( int i = 0; i < classes.length; i++ )
  -        {
  -            buffer.append( classes[ i ].getName() );
  -            if( ( i + 1 ) < classes.length )
  -            {
  -                buffer.append( "," );
  -            }
  -        }
  -        return buffer.toString();
  -    }
  -
       /**
        * Returns a string representation of the parameter.
        * @return the parameter as a string
  @@ -466,7 +459,6 @@
        */
       protected void asString( StringBuffer buffer, String lead )
       {
  -        String classname = m_classname;
           buffer.append(
               lead + "[\n"
               + lead + "   type: " + this.getClass().getName() + "\n"
  
  
  
  1.1                  avalon-sandbox/merlin/meta-spi/src/test/org/apache/avalon/meta/model/test/EntryTestCase.java
  
  Index: EntryTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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/>.
  
  */
  package org.apache.avalon.meta.model.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.meta.model.ModelException;
  import org.apache.avalon.meta.model.Parameter;
  import org.apache.avalon.meta.model.Entry;
  
  import java.util.HashMap;
  
  /**
   * EntryTestCase does XYZ
   *
   * @author <a href="bloritsch.at.apache.org">Berin Loritsch</a>
   * @version CVS $ Revision: 1.1 $
   */
  public class EntryTestCase extends TestCase
  {
      public EntryTestCase( String name )
      {
          super( name );
      }
  
  
      public void testEntry() throws ModelException
      {
          String key = "key";
          String className = ParameterTestCase.TestClass1.class.getName();
          String value = "val";
          Parameter[] params = new Parameter[]{
              new Parameter( ParameterTestCase.TestClass2.class.getName(), value ),
              new Parameter( ParameterTestCase.TestClass2.class.getName(), value )
          };
  
          try
          {
              new Entry( null, className, value );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          try
          {
              new Entry( key, null, value );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          try
          {
              new Entry( key, className, (String)null );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          Entry entry = new Entry( key, className, value );
          Object majorVal = new ParameterTestCase.TestClass1(value);
          assertEquals( key, entry.getKey() );
          assertEquals( className, entry.getClassname() );
          assertEquals( majorVal, entry.getValue( Thread.currentThread().getContextClassLoader(),
new HashMap() ) );
  
          entry = new Entry( key, className, params );
          majorVal = new ParameterTestCase.TestClass1( new ParameterTestCase.TestClass2(value),
                                                       new ParameterTestCase.TestClass2(value)
);
      }
  }
  
  
  1.1                  avalon-sandbox/merlin/meta-spi/src/test/org/apache/avalon/meta/model/test/ParameterTestCase.java
  
  Index: ParameterTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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/>.
  
  */
  package org.apache.avalon.meta.model.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.meta.model.Parameter;
  import org.apache.avalon.meta.model.ModelException;
  
  import java.util.Map;
  import java.util.HashMap;
  import java.lang.reflect.Constructor;
  
  /**
   * ParameterTestCase does XYZ
   *
   * @author <a href="bloritsch.at.apache.org">Berin Loritsch</a>
   * @version CVS $ Revision: 1.1 $
   */
  public class ParameterTestCase extends TestCase
  {
      public static final class TestClass1
      {
          private final String m_val;
  
          public TestClass1( String val )
          {
              m_val = val;
          }
  
          public TestClass1( TestClass2 one, TestClass2 two)
          {
              this( one.toString() + two.toString());
          }
  
          public boolean equals(Object other)
          {
              return other instanceof TestClass1 && m_val.equals(((TestClass1)other).m_val);
          }
  
          public String toString()
          {
              return "TestClass1: " + m_val;
          }
      }
  
      public static final class TestClass2
      {
          private final String m_val;
  
          public TestClass2( String val )
          {
              m_val = val;
          }
  
          public boolean equals( Object other )
          {
              return other instanceof TestClass2 && m_val.equals( ( (TestClass2) other
).m_val );
          }
  
          public String toString()
          {
              return "TestClass2: " + m_val;
          }
      }
  
      public ParameterTestCase( String name )
      {
          super( name );
      }
  
      public void testParameters() throws ModelException
      {
          String className = TestClass1.class.getName();
          String value = "val";
          Parameter[] params = new Parameter[] {
              new Parameter( TestClass2.class.getName(), value),
              new Parameter(TestClass2.class.getName(), value)
          };
  
          try
          {
              new Parameter(null);
              fail("Did not throw expected NullPointerException");
          }
          catch (NullPointerException npe)
          {
              // Success!!
          }
  
          try
          {
              new Parameter( null, value );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          try
          {
              new Parameter( className, (String)null );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          try
          {
              new Parameter( null, params );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          try
          {
              new Parameter( className, (Parameter[]) null );
              fail( "Did not throw expected NullPointerException" );
          }
          catch ( NullPointerException npe )
          {
              // Success!!
          }
  
          Parameter param = new Parameter( value );
          assertEquals( String.class.getName(), param.getClassname());
          assertEquals( value, param.getValue(Thread.currentThread().getContextClassLoader(),
new HashMap()));
  
          Object majorVal = new TestClass1(value);
          param = new Parameter( className, value );
          assertEquals( className, param.getClassname() );
          assertEquals( majorVal, param.getValue( Thread.currentThread().getContextClassLoader(),
new HashMap() ) );
  
          param = new Parameter( className, params );
          assertEquals( className, param.getClassname() );
          majorVal = new TestClass1( new TestClass2( value ), new TestClass2( value ) );
          assertEquals( majorVal, param.getValue( Thread.currentThread().getContextClassLoader(),
new HashMap() ) );
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message