This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
72 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
core/src/main/java/uk/gov/justice/services/core/handler/HandlerUtil.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
core/src/main/java/uk/gov/justice/services/core/handler/Handlers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.justice.services.core.handler; | ||
|
||
|
||
import uk.gov.justice.services.core.annotation.Handles; | ||
import uk.gov.justice.services.core.handler.registry.exception.InvalidHandlerException; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Arrays.stream; | ||
|
||
public final class Handlers { | ||
|
||
private Handlers() { | ||
} | ||
|
||
/** | ||
* Finds all the handler methods from handler object annotated by {@link Handles} | ||
* | ||
* @param handler Handler object to be examined. | ||
* @return List of methods annotated with <code>Handles.class</code>. | ||
*/ | ||
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 11 additions & 13 deletions
24
core/src/test/java/uk/gov/justice/services/core/handler/registry/HandlerRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters