Switch extends Event<String> { @Override public String serialize() { return getValue(); } Switch(int sourceID, String sourceName, String switchValue, State switchState);  Switch(int sourceID, String sourceName, State switchState); State getState(); Switch clone(String eventValue, Switch.State state); @Override Switch clone(String newValue); @Override String getValue(); @Override void setValue(String value); @Override String serialize(); @Override boolean isEqual(Object o); @Override String toString();  }
@Test public void testEquals() throws Exception { Switch s1 = new Switch(1, "Source-1", Switch.State.OFF); Switch s2 = new Switch(1, "Source-1", Switch.State.OFF); Assert.assertTrue(s1.equals(s1)); Assert.assertTrue(s1.equals(s2)); Assert.assertTrue(s2.equals(s1)); Assert.assertTrue(s1.hashCode() == s2.hashCode()); Switch s3 = new Switch(2, "Source-1", Switch.State.OFF); Assert.assertFalse(s3.equals(s1)); Switch s4 = new Switch(1, "Source-2", Switch.State.OFF); Assert.assertFalse(s4.equals(s1)); Switch s5 = new Switch(1, "Source-1", Switch.State.ON); Assert.assertFalse(s5.equals(s1)); Switch s6 = new Switch(1, "Source-1", "foo", Switch.State.OFF); Switch s7 = new Switch(1, "Source-1", "foo", Switch.State.OFF); Assert.assertTrue(s6.equals(s6)); Assert.assertTrue(s6.equals(s7)); Assert.assertTrue(s7.equals(s6)); Assert.assertTrue(s6.hashCode() == s7.hashCode()); Switch s8 = new Switch(2, "Source-1", "foo", Switch.State.OFF); Assert.assertFalse(s8.equals(s6)); Switch s9 = new Switch(1, "Source-2", "foo", Switch.State.OFF); Assert.assertFalse(s9.equals(s6)); Switch s10 = new Switch(1, "Source-1", "bar", Switch.State.OFF); Assert.assertFalse(s10.equals(s6)); Switch s11 = new Switch(1, "Source-1", "foo", Switch.State.ON); Assert.assertTrue(s11.equals(s6)); Switch s12 = new Switch(444, "Source-1", Switch.State.OFF.serialize(), Switch.State.OFF); Switch s13 = new Switch(444, "Source-1", Switch.State.OFF); Switch s14 = new Switch(444, "Source-1", "foo", Switch.State.OFF); Assert.assertTrue(s12.equals(s13)); Assert.assertTrue(s12.hashCode() == s13.hashCode()); Assert.assertFalse(s12.equals(s14)); }