leosimons 2004/01/11 14:17:19
Added: framework/api/src/test/org/apache/avalon/framework/test
CascadingErrorTestCase.java
CascadingExceptionTestCase.java
CascadingRuntimeExceptionTestCase.java
EnumTestCase.java VersionTestCase.java
Log:
start whipping more solid tests for avalon-framework.
Revision Changes Path
1.1
avalon/framework/api/src/test/org/apache/avalon/framework/test/CascadingErrorTestCase.java
Index: CascadingErrorTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2004 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 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", 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 [EMAIL PROTECTED]
*
* 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 (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/>.
*/
package org.apache.avalon.framework.test;
import org.apache.avalon.framework.CascadingError;
import org.apache.avalon.framework.CascadingThrowable;
import junit.framework.TestCase;
/**
* TestCase for [EMAIL PROTECTED] CascadingError}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/01/11 22:17:19 $
*/
public class CascadingErrorTestCase extends TestCase
{
public void testConstructor()
{
assertNotNull( new CascadingError( null, null ) );
assertNotNull( new CascadingError( "msg", null ) );
assertNotNull( new CascadingError( "msg", new RuntimeException() ) );
assertNotNull( new CascadingError( null, new RuntimeException() ) );
//assertNotNull( new CascadingError( "msg" ) );
//ambiguous assertNotNull( new CascadingError( null ) );
//assertNotNull( new CascadingError() );
}
public void testGetCause()
{
RuntimeException re = new RuntimeException();
CascadingError e = new CascadingError( "msg", re );
assertEquals( re, e.getCause() );
e = new CascadingError( "msg", null );
assertNull( e.getCause() );
// default to jdk 1.3 cause (not that it seems to help,
// but it still makes sense)
/*Exception exc = new Exception("blah");
try
{
try
{
throw exc;
}
catch( Exception ex )
{
throw new CascadingError();
}
}
catch( CascadingError ex )
{
ex.getCause();
}*/
}
public void testCasts()
{
CascadingError e = new CascadingError( "msg", null );
assertTrue( e instanceof Error );
assertTrue( e instanceof CascadingThrowable );
}
}
1.1
avalon/framework/api/src/test/org/apache/avalon/framework/test/CascadingExceptionTestCase.java
Index: CascadingExceptionTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2004 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 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", 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 [EMAIL PROTECTED]
*
* 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 (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/>.
*/
package org.apache.avalon.framework.test;
import org.apache.avalon.framework.CascadingException;
import org.apache.avalon.framework.CascadingThrowable;
import junit.framework.TestCase;
/**
* TestCase for [EMAIL PROTECTED] CascadingException}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/01/11 22:17:19 $
*/
public class CascadingExceptionTestCase extends TestCase
{
public void testConstructor()
{
assertNotNull( new CascadingException( null, null ) );
assertNotNull( new CascadingException( "msg", null ) );
assertNotNull(
new CascadingException( "msg", new RuntimeException() ) );
assertNotNull( new CascadingException( null, new RuntimeException() ) );
assertNotNull( new CascadingException( "msg" ) );
// ambiguous assertNotNull( new CascadingException( null ) );
//assertNotNull( new CascadingException() );
}
public void testGetCause()
{
RuntimeException re = new RuntimeException();
CascadingException e = new CascadingException( "msg", re );
assertEquals( re, e.getCause() );
e = new CascadingException( "msg", null );
assertNull( e.getCause() );
// default to jdk 1.3 cause (not that it seems to help,
// but it still makes sense)
/*Exception exc = new Exception("blah");
try
{
try
{
throw exc;
}
catch( Exception ex )
{
throw new CascadingException();
}
}
catch( CascadingException ex )
{
ex.getCause();
}*/
}
public void testCasts()
{
CascadingException e = new CascadingException( "msg", null );
assertTrue( e instanceof Exception );
assertTrue( e instanceof CascadingThrowable );
}
}
1.1
avalon/framework/api/src/test/org/apache/avalon/framework/test/CascadingRuntimeExceptionTestCase.java
Index: CascadingRuntimeExceptionTestCase.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 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", 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 [EMAIL PROTECTED]
*
* 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 (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/>.
*/
package org.apache.avalon.framework.test;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.CascadingThrowable;
import junit.framework.TestCase;
/**
* TestCase for [EMAIL PROTECTED] CascadingRuntimeException}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/01/11 22:17:19 $
*/
public class CascadingRuntimeExceptionTestCase extends TestCase
{
public void testConstructor()
{
assertNotNull( new CascadingRuntimeException( null, null ) );
assertNotNull( new CascadingRuntimeException( "msg", null ) );
assertNotNull(
new CascadingRuntimeException( "msg", new RuntimeException() ) );
assertNotNull(
new CascadingRuntimeException( null, new RuntimeException() ) );
}
public void testGetCause()
{
RuntimeException re = new RuntimeException();
CascadingRuntimeException e = new CascadingRuntimeException( "msg",
re );
assertEquals( re, e.getCause() );
e = new CascadingRuntimeException( "msg", null );
assertNull( e.getCause() );
// default to jdk 1.3 cause (not that it seems to help,
// but it still makes sense)
/*Exception exc = new Exception("blah");
try
{
try
{
throw exc;
}
catch( Exception ex )
{
throw new CascadingRuntimeException();
}
}
catch( CascadingRuntimeException ex )
{
ex.getCause();
}*/
}
public void testCasts()
{
CascadingRuntimeException e = new CascadingRuntimeException( "msg",
null );
assertTrue( e instanceof RuntimeException );
assertTrue( e instanceof CascadingThrowable );
}
}
1.1
avalon/framework/api/src/test/org/apache/avalon/framework/test/EnumTestCase.java
Index: EnumTestCase.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 2002,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", "Apache Avalon", "Avalon Excalibur", "Avalon
Framework" 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 [EMAIL PROTECTED]
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 and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.framework.test;
import junit.framework.TestCase;
import org.apache.avalon.framework.Enum;
import java.util.Map;
/**
* TestCase for [EMAIL PROTECTED] Enum}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/01/11 22:17:19 $
*/
public class EnumTestCase
extends TestCase
{
private final static class Color extends Enum
{
public static final Color RED = new Color( "Red" );
public static final Color GREEN = new Color( "Green" );
public static final Color BLUE = new Color( "Blue" );
public Color( final String color )
{
super( color );
}
public Color( final String color, Map stuff )
{
super( color, stuff );
}
}
private final static class OtherColor extends Enum
{
public static final OtherColor RED = new OtherColor( "Red" );
public static final OtherColor GREEN = new OtherColor( "Green" );
public static final OtherColor BLUE = new OtherColor( "Blue" );
public OtherColor( final String color )
{
super( color );
}
public OtherColor( final String color, Map stuff )
{
super( color, stuff );
}
}
public EnumTestCase( final String name )
{
super( name );
}
public void testConstructor()
{
assertNotNull( new Color( "blah", null) );
}
public void testEquals()
{
assertTrue( Color.RED.equals( Color.RED ) );
assertTrue( Color.GREEN.equals( Color.GREEN ) );
assertTrue( Color.BLUE.equals( Color.BLUE ) );
assertTrue( !OtherColor.RED.equals( Color.RED ) );
assertTrue( !OtherColor.GREEN.equals( Color.GREEN ) );
assertTrue( !OtherColor.BLUE.equals( Color.BLUE ) );
assertTrue( !Color.RED.equals( OtherColor.RED ) );
assertTrue( !Color.GREEN.equals( OtherColor.GREEN ) );
assertTrue( !Color.BLUE.equals( OtherColor.BLUE ) );
assertTrue( !Color.RED.equals( Color.GREEN ) );
assertTrue( !Color.GREEN.equals( Color.BLUE ) );
assertTrue( !Color.BLUE.equals( Color.RED ) );
assertTrue( !Color.BLUE.equals( null ) );
assertTrue( new Color(null).equals( new Color( null ) ) );
assertFalse( new Color(null).equals( new Color( "hi" ) ) );
assertFalse( new Color("hi").equals( new Color( null ) ) );
}
public void testHashCode()
{
assertTrue( Color.RED.hashCode() == Color.RED.hashCode() );
assertTrue( Color.GREEN.hashCode() == Color.GREEN.hashCode() );
assertTrue( Color.BLUE.hashCode() == Color.BLUE.hashCode() );
assertTrue( OtherColor.RED.hashCode() != Color.RED.hashCode() );
assertTrue( OtherColor.GREEN.hashCode() != Color.GREEN.hashCode() );
assertTrue( OtherColor.BLUE.hashCode() != Color.BLUE.hashCode() );
assertTrue( Color.RED.hashCode() != OtherColor.RED.hashCode() );
assertTrue( Color.GREEN.hashCode() != OtherColor.GREEN.hashCode() );
assertTrue( Color.BLUE.hashCode() != OtherColor.BLUE.hashCode() );
assertTrue( Color.RED.hashCode() != Color.GREEN.hashCode() );
assertTrue( Color.GREEN.hashCode() != Color.BLUE.hashCode() );
assertTrue( Color.BLUE.hashCode() != Color.RED.hashCode() );
}
public void testGet()
{
assertEquals( "Red", Color.RED.getName() );
assertNull( (new Color(null)).getName() );
}
public void testToString()
{
assertTrue( Color.RED.toString().indexOf( "Red") != -1 );
assertTrue( Color.RED.toString().indexOf( Color.class.getName() ) != -1 );
Color c = new Color(null);
assertTrue( c.toString().indexOf( "null") != -1 );
}
}
1.1
avalon/framework/api/src/test/org/apache/avalon/framework/test/VersionTestCase.java
Index: VersionTestCase.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 2002,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", "Apache Avalon", "Avalon Excalibur", "Avalon
Framework" 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 [EMAIL PROTECTED]
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 and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.framework.test;
import junit.framework.TestCase;
import org.apache.avalon.framework.Version;
/**
* TestCase for [EMAIL PROTECTED] Version}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/01/11 22:17:19 $
*/
public class VersionTestCase
extends TestCase
{
public VersionTestCase( final String name )
{
super( name );
}
public void testValidVersionString()
{
final Version v1 = Version.getVersion( "1" );
assertTrue( new Version( 1, 0, 0 ).equals( v1 ) );
final Version v2 = Version.getVersion( "0.3" );
assertTrue( new Version( 0, 3, 0 ).equals( v2 ) );
final Version v3 = Version.getVersion( "78.10.03" );
assertTrue( new Version( 78, 10, 3 ).equals( v3 ) );
}
public void testInvalidVersionString()
{
try
{
assertEquals( -1, Version.getVersion( "" ).getMajor() );
}
catch ( final IllegalArgumentException iae )
{
fail( "Empty string is legal version string" );
}
try
{
Version.getVersion( "1.F" );
Version.getVersion( "1.0-dev" );
fail( "Version string do contains only '.' and number" );
}
catch ( final NumberFormatException nfe )
{
//OK
}
}
public void testComplies()
{
final Version v0 = new Version( -1, 0 , 0 );
final Version v1 = new Version( 1, 3 , 6 );
final Version v2 = new Version( 1, 3 , 7 );
final Version v3 = new Version( 1, 4 , 0 );
final Version v4 = new Version( 2, 0 , 1 );
assertTrue( v1.complies( v0 ) );
assertTrue( v4.complies( v0 ) );
assertTrue( ! v0.complies( v1 ) );
assertTrue( ! v0.complies( v4 ) );
assertTrue( v1.complies( v1 ) );
assertTrue( ! v1.complies( v2 ) );
assertTrue( v2.complies( v1 ) );
assertTrue( ! v1.complies( v3 ) );
assertTrue( v3.complies( v1 ) );
assertTrue( ! v1.complies( v4 ) );
assertTrue( ! v4.complies( v1 ) );
}
public void testHashCode()
{
final Version v1 = new Version( 5, 1, 0 );
final Version v2 = new Version( 1, 0, 3 );
final Version v3 = new Version( 1, 0, 3 );
assertEquals( calculateHash(v1), v1.hashCode() );
assertEquals( calculateHash(v2), v2.hashCode() );
assertTrue( v1.hashCode() != v2.hashCode() );
assertTrue( ! v1.equals(v2) );
assertEquals( v2.hashCode(), v3.hashCode() );
assertEquals( v2, v3 );
}
public void testComparable()
{
final Version v1 = new Version( 1, 0, 0 );
final Version v2 = new Version( 2, 0, 0 );
final Version v3 = new Version( 2, 1, 0 );
final Version v4 = new Version( 2, 1, 1 );
final Version v5 = new Version( 1, 0, 0 );
assertEquals( 0, v1.compareTo(v5) );
assertEquals( 0, v5.compareTo(v1) );
assertEquals( -1, v1.compareTo(v2) );
assertEquals( 1, v2.compareTo(v1) );
assertEquals( -1, v2.compareTo(v3) );
assertEquals( 1, v3.compareTo(v2) );
assertEquals( -1, v3.compareTo(v4) );
assertEquals( 1, v4.compareTo(v3) );
}
private int calculateHash(final Version v) {
int hash = v.getMajor();
hash >>>= 17;
hash += v.getMinor();
hash >>>= 17;
hash += v.getMicro();
return hash;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]