Handlers { public static List<Method> handlerMethodsFrom(final Object handler) { final Class<?> handlerClass = handler.getClass(); final List<Method> handlerMethods = stream(handlerClass.getMethods()) .filter(method -> method.isAnnotationPresent(Handles.class)) .collect(Collectors.toList()); if (handlerMethods.isEmpty()) { throw new InvalidHandlerException("Class " + handlerClass + " doesn't have any method annotated with the annotation @Handles"); } return handlerMethods; } private  Handlers(); static List<Method> handlerMethodsFrom(final Object handler);  }
@Test public void shouldFindHandlerMethods() { List<Method> methods = Handlers.handlerMethodsFrom(new CommandHandler()); assertThat(methods, notNullValue()); assertThat(methods, IsCollectionWithSize.hasSize(3)); }
@Test(expected = InvalidHandlerException.class) public void shouldThrowExceptionWithInvalidHandlerMethods() { Handlers.handlerMethodsFrom(new InvalidHandler()); }