+
+ @Test
+ public void testEquals() {
+
+ Config<MyType> config1 = new ConfigImpl<MyType>(new Id<Config>(
+ CONFIG_TYPE)) {
+ @Override
+ public MyType wrap(String aPrefix, MyType aT) {
+ return new MyTypeWrapper(aPrefix, aT);
+ }
+ };
+ assertFalse(config1.equals(null));
+ assertFalse(config1.equals("hello"));
+ Config<MyType> config2 = new ConfigImpl<MyType>(new Id<Config>(
+ CONFIG_TYPE)) {
+ @Override
+ public MyType wrap(String aPrefix, MyType aT) {
+ return new MyTypeWrapper(aPrefix, aT);
+ }
+ };
+ assertEquals(config1, config2);
+ assertEquals(config1.hashCode(), config2.hashCode());
+
+ MyType type1 = mock(MyType.class);
+ when(type1.getId()).thenReturn(new Id("type1"));
+
+ config1.add(type1);
+ assertFalse(config1.equals(config2));
+
+ MyType type2 = mock(MyType.class);
+ when(type2.getId()).thenReturn(new Id("type1"));
+
+ config2.add(type2);
+ assertEquals(config1, config2);
+ assertEquals(config1.hashCode(), config2.hashCode());
+
+ assertTrue(config2.remove(type2.getId()));
+ assertFalse(config1.equals(config2));
+ }