ConfigurableCommandRegistry implements CommandRegistry { public void register(String name, MethodTarget target) { MethodTarget previous = commands.get(name); if (previous != null) { throw new IllegalArgumentException( String.format("Illegal registration for command '%s': Attempt to register both '%s' and '%s'", name, target, previous)); } commands.put(name, target); }  @Override Map<String, MethodTarget> listCommands(); void register(String name, MethodTarget target);  }
@Test public void testDoubleRegistration() { ConfigurableCommandRegistry registry = new ConfigurableCommandRegistry(); registry.register("foo", MethodTarget.of("toString", this, new Command.Help("some command"))); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("foo"); thrown.expectMessage("toString"); thrown.expectMessage("hashCode"); registry.register("foo", MethodTarget.of("hashCode", this, new Command.Help("some command"))); }