@Override protected Object runReflectiveCall() throws Throwable { return createTest(); } }.run();
private static List<FrameworkMethod> getAnnotatedMethods(TestClass testClass, Class<? extends Annotation> annotation){ List<FrameworkMethod> methodsFromTestClass = testClass.getAnnotatedMethods(annotation); List<FrameworkMethod> allMethods = new ArrayList<>(); allMethods.addAll(methodsFromTestClass); allMethods.addAll(getAnnotatedMethodsFromInterfaces(testClass, annotation)); return allMethods; }
protected void validateConstructor(final List<Throwable> errors) { if (!hasOneConstructor()) { errors.add(new Exception("Test class should have exactly one public constructor")); } if (!testClass.isANonStaticInnerClass() && hasOneConstructor() && (testClass.getOnlyConstructor().getParameterTypes().length != 0)) { errors.add(new Exception("Test class should have exactly one public zero-argument constructor")); } }
return new Fail(e); final Target target = lookupTarget(testInstance); statement = withStateChanges(interaction, testInstance, statement); statement = withBefores(interaction, testInstance, statement); statement = withRules(interaction, testInstance, statement); statement = withAfters(interaction, testInstance, statement); return statement;
public void run(final RunNotifier notifier) { boolean allPassed = true; for (final Interaction interaction : pact.getInteractions()) { final Description description = describeChild(interaction); notifier.fireTestStarted(description); try { interactionBlock(interaction, pactSource).evaluate(); } catch (final Throwable e) { notifier.fireTestFailure(new Failure(description, e)); allPassed = false; } finally { notifier.fireTestFinished(description); } } boolean publishingDisabled = results.values() .stream().anyMatch(pair -> pair.getSecond().publishingResultsDisabled()); if (!publishingDisabled && (!(pact instanceof FilteredPact) || ((FilteredPact) pact).isNotFiltered())) { reportVerificationResults(allPassed); } else { if (publishingDisabled) { LOGGER.warn("Skipping publishing of verification results (" + PACT_VERIFIER_PUBLISHRESULTS + " is not set to 'true')"); } else { LOGGER.warn("Skipping publishing of verification results as the interactions have been filtered"); } } }
@Override public void evaluate() throws Throwable { setupTargetForInteraction(target); target.addResultCallback((result, verifier) -> results.put(interaction, new Pair<>(result, verifier))); surrogateTestMethod(); target.testInteraction(pact.getConsumer().getName(), interaction, source); } };
protected Statement withRules(final Interaction interaction, final Object target, final Statement statement) { final List<TestRule> testRules = testClass.getAnnotatedMethodValues(target, Rule.class, TestRule.class); testRules.addAll(testClass.getAnnotatedFieldValues(target, Rule.class, TestRule.class)); return testRules.isEmpty() ? statement : new RunRules(statement, testRules, describeChild(interaction)); } }
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")); } }); }
public void reportVerificationResults(Boolean allPassed) { ProviderVerifierKt.reportVerificationResults(pact, allPassed, providerVersion()); }
@Override public Description getDescription() { final Description description = Description.createSuiteDescription(testClass.getJavaClass()); for (Interaction i: pact.getInteractions()) { description.addChild(describeChild(i)); } return description; }
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; } }