RoutingKeyMethodScanner { public <T extends Annotation> Method getRoutingKeyMethod(Class<T> annotationType, Class<?> spaceObjectClass) { Method result = null; for (Method m : spaceObjectClass.getMethods()) { if (m.isAnnotationPresent(annotationType)) { if (result != null) { throw new IllegalArgumentException("Multiple methods annotated with @SpaceRouting found on class: " + spaceObjectClass.getName()); } result = m; } } return result; }  Method getRoutingKeyMethod(Class<T> annotationType, Class<?> spaceObjectClass);  }
@Test public void findsNoArgumentMethodWithAstrixRoutingAnnotation() throws Exception { class Test { @AstrixRouting public String routingMethod() { return null; } @SuppressWarnings("unused") public String anotherMethod() { return null; } } RoutingKeyMethodScanner scanner = new RoutingKeyMethodScanner(); Method routingKeyMethod = scanner.getRoutingKeyMethod(AstrixRouting.class, Test.class); assertEquals(Test.class.getMethod("routingMethod"), routingKeyMethod); }
@Test(expected = IllegalArgumentException.class) public void throwsIllegalArgumentExceptionForTypeWithMultipleAstrixRoutingAnnotations() throws Exception { class Test { @AstrixRouting public String routingMethod() { return null; } @AstrixRouting public String anotherMethod() { return null; } } RoutingKeyMethodScanner scanner = new RoutingKeyMethodScanner(); scanner.getRoutingKeyMethod(AstrixRouting.class, Test.class); }
@Test public void returnsNullIfNoMethodIsMethodHasAstrixRoutingAnnotating() throws Exception { class Test { @SuppressWarnings("unused") public String routingMethod() { return null; } @SuppressWarnings("unused") public String anotherMethod() { return null; } } RoutingKeyMethodScanner scanner = new RoutingKeyMethodScanner(); assertNull(scanner.getRoutingKeyMethod(AstrixRouting.class, Test.class)); }