I set out to improve test coverage in avalon-framework. I've already found 3 bugs :D. I need some input on Enum and ValuedEnum. I've never used them (enumerations are a code smell :D), but they should be fixed nonetheless.
The Enum equals() method is marked final, which is weird to say the least. Weird, because ValuedEnum can't override it and hence what value is stored in the ValuedEnum doesn't matter for equality tests. See the testcases for more info. In particular, the following code *passes*:
// fragments
private final static class Color extends ValuedEnum
{
public static final Color RED = new Color( "Red", 0 );
public static final Color RED_NEGATIVE = new Color( "Red", -1 );/* ... */
}
private final static class OtherColor extends ValuedEnum
{
public static final OtherColor RED = new OtherColor( "Red", 0 );
public static final OtherColor RED_NEGATIVE = new OtherColor(
"Red", -1 ); /* ... */
}/* ... */
assertTrue( Color.RED.equals( Color.RED_NEGATIVE ) );
assertTrue( Color.RED_NEGATIVE.equals( Color.RED ) );
assertTrue( OtherColor.RED.equals( OtherColor.RED_NEGATIVE ) );
assertTrue( OtherColor.RED_NEGATIVE.equals( OtherColor.RED ) ); assertTrue( Color.RED.hashCode() ==
Color.RED_NEGATIVE.hashCode() );
assertTrue( Color.RED_NEGATIVE.hashCode()
== Color.RED.hashCode() );
assertTrue( OtherColor.RED.hashCode()
== OtherColor.RED_NEGATIVE.hashCode() );
assertTrue( OtherColor.RED_NEGATIVE.hashCode()
== OtherColor.RED.hashCode() );is this really desired behaviour, or should I go ahead and override equals() and hashCode() to take the value into account? Does anyone have code anywhere that depends on this behaviour?
-- cheers,
- Leo Simons
----------------------------------------------------------------------- Weblog -- http://leosimons.com/ IoC Component Glue -- http://jicarilla.org/ Articles & Opinions -- http://articles.leosimons.com/ ----------------------------------------------------------------------- "We started off trying to set up a small anarchist community, but people wouldn't obey the rules." -- Alan Bennett
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
