### Question:
StateModelParser { public Method getMethodForTransitionUsingAnnotation(Class<? extends StateModel> clazz, String fromState, String toState, Class<?>[] paramTypes) { StateModelInfo stateModelInfo = clazz.getAnnotation(StateModelInfo.class); Method methodToInvoke = null; if (stateModelInfo != null) { Method[] methods = clazz.getMethods(); if (methods != null) { for (Method method : methods) { Transition annotation = method.getAnnotation(Transition.class); if (annotation != null) { boolean matchesFrom = "*".equals(annotation.from()) || annotation.from().equalsIgnoreCase(fromState); boolean matchesTo = "*".equals(annotation.to()) || annotation.to().equalsIgnoreCase(toState); boolean matchesParamTypes = Arrays.equals(paramTypes, method.getParameterTypes()); if (matchesFrom && matchesTo && matchesParamTypes) { methodToInvoke = method; break; } } } } } return methodToInvoke; }  Method getMethodForTransition(Class<? extends StateModel> clazz, String fromState,
      String toState, Class<?>[] paramTypes); Method getMethodForTransitionByConvention(Class<? extends StateModel> clazz,
      String fromState, String toState, Class<?>[] paramTypes); Method getMethodForTransitionUsingAnnotation(Class<? extends StateModel> clazz,
      String fromState, String toState, Class<?>[] paramTypes); String getInitialState(Class<? extends StateModel> clazz);  }### Answer:
@Test public void testUsingAnnotation() { StateModelParser parser = new StateModelParser(); StateModelUsingAnnotation testModel = new StateModelUsingAnnotation(); Method method = parser.getMethodForTransitionUsingAnnotation(testModel.getClass(), "offline", "slave", new Class[] { Message.class, NotificationContext.class }); Assert.assertNotNull(method); Assert.assertEquals(method.getName(), "onBecomeSlaveFromOffline"); }
@Test public void testDerivedUsingAnnotation() { StateModelParser parser = new StateModelParser(); DerivedStateModelUsingAnnotation testModel = new DerivedStateModelUsingAnnotation(); Method method = parser.getMethodForTransitionUsingAnnotation(testModel.getClass(), "offline", "slave", new Class[] { Message.class, NotificationContext.class }); Assert.assertNotNull(method); Assert.assertEquals(method.getName(), "derivedOnBecomeSlaveFromOffline"); method = parser.getMethodForTransitionUsingAnnotation(testModel.getClass(), "error", "dropped", new Class[] { Message.class, NotificationContext.class }); Assert.assertNotNull(method); Assert.assertEquals(method.getName(), "onBecomeDroppedFromError"); }