CommandHandlerProvider implements ApplicationContextAware { @Nonnull public NewCommandSourceHandler getHandler (@Nonnull final String entity, @Nonnull final String action) { Preconditions.checkArgument(StringUtils.isNoneEmpty(entity), "An entity must be given!"); Preconditions.checkArgument(StringUtils.isNoneEmpty(action), "An action must be given!"); final String key = entity + "|" + action; if (!this.registeredHandlers.containsKey(key)) { throw new UnsupportedCommandException(key); } return (NewCommandSourceHandler)this.applicationContext.getBean(this.registeredHandlers.get(key)); } CommandHandlerProvider(); @Nonnull NewCommandSourceHandler getHandler(@Nonnull final String entity, @Nonnull final String action); @Override void setApplicationContext(ApplicationContext applicationContext);  }
@Test public void shouldRegisterHandler() { try { final Long testCommandId = 815L; final NewCommandSourceHandler registeredHandler = this.commandHandlerProvider.getHandler("HUMAN", "UPDATE"); final CommandProcessingResult result = registeredHandler.processCommand( JsonCommand.fromExistingCommand(testCommandId, null, null, null, null, null, null, null, null)); Assert.assertEquals(testCommandId, result.commandId()); } catch (UnsupportedCommandException ucex) { Assert.fail(); } }
@Test(expected = UnsupportedCommandException.class) public void shouldThrowUnsupportedCommandException() { this.commandHandlerProvider.getHandler("WHATEVER", "DOSOMETHING"); }