private static void validateStateChangeMethods(TestClass testClass, final List<Throwable> errors) { getAnnotatedMethods(testClass, State.class).forEach(method -> { method.validatePublicVoid(false, errors); if (method.getMethod().getParameterCount() == 1 && !Map.class.isAssignableFrom(method.getMethod().getParameterTypes()[0])) { errors.add(new Exception("Method " + method.getName() + " should take only a single Map parameter")); } else if (method.getMethod().getParameterCount() > 1) { errors.add(new Exception("Method " + method.getName() + " should either take no parameters or a single Map parameter")); } }); }
protected Statement withStateChanges(final Interaction interaction, final Object target, final Statement prevStatement) { if (!interaction.getProviderStates().isEmpty()) { Statement stateChange = prevStatement; for (ProviderState state: interaction.getProviderStates()) { List<Pair<FrameworkMethod, State>> methods = getAnnotatedMethods(testClass, State.class) .stream() .map(method -> { final State annotation = method.getAnnotation(State.class); return new Pair<>(method, annotation); }) .filter(method -> ArrayUtils.contains(method.getSecond().value(), state.getName())) .collect(Collectors.toList()); if (methods.isEmpty()) { return new Fail(new MissingStateChangeMethod("MissingStateChangeMethod: Did not find a test class method annotated with @State(\"" + state.getName() + "\")")); } else { stateChange = new RunStateChanges(stateChange, methods, target, state); } } return stateChange; } else { return prevStatement; } }