1 16 package org.apache.commons.lang.enums; 17 18 import junit.framework.Test; 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 22 29 public final class EnumEqualsTest extends TestCase { 30 31 public EnumEqualsTest(String name) { 32 super(name); 33 } 34 35 public void setUp() { 36 } 37 38 public static Test suite() { 39 TestSuite suite = new TestSuite(EnumEqualsTest.class); 40 suite.setName("Enum equals Tests"); 41 return suite; 42 } 43 44 static final class CarColorEnum extends Enum { 46 public static final CarColorEnum BLACK = new CarColorEnum("black"); 47 public static final CarColorEnum BROWN = new CarColorEnum("brown"); 48 public static final CarColorEnum YELLOW = new CarColorEnum("yellow"); 49 public static final CarColorEnum BLUE = new CarColorEnum("blue"); 50 public static final CarColorEnum RED = new CarColorEnum("red"); 51 52 private CarColorEnum(String enumAsString) { 53 super(enumAsString); 54 } 55 } 56 57 static final class TrafficlightColorEnum extends Enum { 58 public static final TrafficlightColorEnum RED = new TrafficlightColorEnum("red"); 59 public static final TrafficlightColorEnum YELLOW = new TrafficlightColorEnum("yellow"); 60 public static final TrafficlightColorEnum GREEN = new TrafficlightColorEnum("green"); 61 62 private TrafficlightColorEnum(String enumAsString) { 63 super(enumAsString); 64 } 65 } 66 67 static class TotallyUnrelatedClass { 68 private final String name; 69 70 public TotallyUnrelatedClass(final String name) { 71 this.name = name; 72 } 73 74 public String getName() { 75 return name; 76 } 77 } 78 79 public void testEquals() { 81 assertEquals(false, CarColorEnum.RED.equals(TrafficlightColorEnum.RED)); 82 assertEquals(false, CarColorEnum.YELLOW.equals(TrafficlightColorEnum.YELLOW)); 83 84 assertEquals(false, TrafficlightColorEnum.RED.equals(new TotallyUnrelatedClass("red"))); 85 assertEquals(false, CarColorEnum.RED.equals(new TotallyUnrelatedClass("red"))); 86 87 assertEquals(false, TrafficlightColorEnum.RED.equals(new TotallyUnrelatedClass("some"))); 88 assertEquals(false, CarColorEnum.RED.equals(new TotallyUnrelatedClass("some"))); 89 } 90 } 91 | Popular Tags |