bloritsch 2003/07/11 08:50:04
Modified: meta/api/src/java/org/apache/avalon/meta/info
InfoDescriptor.java
meta/api/src/test/org/apache/avalon/meta/info/test
InfoDescriptorTestCase.java
Log:
Add some additional testing and make the equals/hashcode more specific
Revision Changes Path
1.4 +46 -1
avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/InfoDescriptor.java
Index: InfoDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/java/org/apache/avalon/meta/info/InfoDescriptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InfoDescriptor.java 10 Jul 2003 21:06:04 -0000 1.3
+++ InfoDescriptor.java 11 Jul 2003 15:50:01 -0000 1.4
@@ -139,6 +139,8 @@
{
super( attributes );
+ if ( null == classname ) throw new NullPointerException( "classname" );
+
if ( classname.indexOf( "/" ) > -1 )
{
throw new IllegalArgumentException( "classname: " + classname );
@@ -242,4 +244,47 @@
return "[" + getName() + "] " + getClassname() + ":" + getVersion();
}
+ public boolean equals(Object other)
+ {
+ boolean isEqual = super.equals(other) && other instanceof InfoDescriptor;
+
+ if (isEqual)
+ {
+ InfoDescriptor info = (InfoDescriptor)other;
+ isEqual = isEqual && m_classname.equals( info.m_classname );
+ isEqual = isEqual && m_name.equals( info.m_name );
+ isEqual = isEqual && m_lifestyle.equals( info.m_lifestyle );
+
+ if ( null == m_version )
+ {
+ isEqual = isEqual && null == info.m_version;
+ }
+ else
+ {
+ isEqual = isEqual && m_version.equals(info.m_version);
+ }
+ }
+
+ return isEqual;
+ }
+
+ public int hashCode()
+ {
+ int hash = super.hashCode();
+
+ hash >>>= 7;
+ hash ^= m_classname.hashCode();
+ hash >>>= 7;
+ hash ^= m_name.hashCode();
+ hash >>>= 7;
+ hash ^= m_lifestyle.hashCode();
+
+ if ( null != m_version )
+ {
+ hash >>>= 7;
+ hash ^= m_version.hashCode();
+ }
+
+ return hash;
+ }
}
1.3 +40 -0
avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/InfoDescriptorTestCase.java
Index: InfoDescriptorTestCase.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/api/src/test/org/apache/avalon/meta/info/test/InfoDescriptorTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InfoDescriptorTestCase.java 11 Jul 2003 15:33:44 -0000 1.2
+++ InfoDescriptorTestCase.java 11 Jul 2003 15:50:04 -0000 1.3
@@ -90,4 +90,44 @@
assertEquals( m_version, info.getVersion() );
assertEquals( m_lifestyle, info.getLifestyle() );
}
+
+ public void testConstructor()
+ {
+ try
+ {
+ new InfoDescriptor( m_name, null, m_version, m_lifestyle,
getProperties() );
+ fail("Did not throw the proper NullPointerException");
+ }
+ catch (NullPointerException npe)
+ {
+ // Success!
+ }
+
+ try
+ {
+ new InfoDescriptor( m_name, "foo/fake/ClassName", m_version,
m_lifestyle, getProperties());
+ fail("Did not throw the proper IllegalArgumentException");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // Success!
+ }
+
+ try
+ {
+ new InfoDescriptor( m_name, m_classname, m_version,
InfoDescriptor.POOLED, getProperties() );
+ new InfoDescriptor( m_name, m_classname, m_version,
InfoDescriptor.SINGLETON, getProperties() );
+ new InfoDescriptor( m_name, m_classname, m_version,
InfoDescriptor.THREAD, getProperties() );
+ new InfoDescriptor( m_name, m_classname, m_version,
InfoDescriptor.TRANSIENT, getProperties() );
+
+ // All these should pass.
+
+ new InfoDescriptor( m_name, m_classname, m_version, "Fake Lifestyle",
getProperties() );
+ fail( "Did not throw the proper IllegalArgumentException" );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ // Success!
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]