PersistableRegistry { public void register(String key, Class<? extends Persistable> clazz) { if (map.containsKey(key)) { throw new UnsupportedOperationException(String.format(ALREADY_REGISTERED_MESSAGE, clazz.getName(), key)); } map.put(key, clazz); }  void register(String key, Class<? extends Persistable> clazz); Class<? extends Persistable> get(String key);  }
@Test(expected = UnsupportedOperationException.class) public void registerTwice() { registry.register(TestUser.KEY, TestUser.class); registry.register(TestUser.KEY, TestUser.class); }
@Test(expected = UnsupportedOperationException.class) public void registerTwiceDifferentTypes() { registry.register(TestUser.KEY, TestUser.class); registry.register(TestUser.KEY, Persistable.class); }
@Test public void register() { String key = TestUser.KEY; Class<TestUser> clazz = TestUser.class; registry.register(key, clazz); Class<? extends Persistable> getType = registry.get(key); assertEquals(clazz, getType); }