InteractionRunner { public void executePacts(@Observes EventContext<Test> test) { final Pacts pacts = pactsInstance.get(); if (pacts == null) { test.proceed(); return; } TestClass testClass = test.getEvent().getTestClass(); final List<Throwable> errors = new ArrayList<>(); validateState(testClass, errors); validateTargetRequestFilters(testClass, errors); validateTestTarget(testClass, errors); Field interactionField = validateAndGetResourceField(testClass, RequestResponseInteraction.class, CurrentInteraction.class, errors); Field consumerField = validateAndGetResourceField(testClass, Consumer.class, CurrentConsumer.class, errors); if (errors.size() != 0) { String errorMessage = errors.stream() .map(Throwable::getMessage) .collect(Collectors.joining(" * ")); throw new IllegalArgumentException(errorMessage); } executePacts(test, pacts, interactionField, consumerField); }  void executePacts(@Observes EventContext<Test> test);  }
@Test public void should_execute_test_for_each_interaction() { when(test.getTestClass()).thenReturn(new TestClass(PactProvider.class)); PactProvider pactDefinition = new PactProvider(); when(test.getTestInstance()).thenReturn(pactDefinition); InteractionRunner interactionRunner = new InteractionRunner(); interactionRunner.pactsInstance = pactsInstance; interactionRunner.targetInstance = () -> target; interactionRunner.executePacts(eventContext); assertThat(pactDefinition.consumer).isEqualTo(new Consumer("planets_consumer")); assertThat(pactDefinition.interaction).isNotNull(); verify(eventContext, times(2)).proceed(); }
@Test public void should_throw_exception_when_no_target() { when(test.getTestClass()).thenReturn(new TestClass(PactProviderWithNoTarget.class)); PactProviderWithNoTarget pactDefinition = new PactProviderWithNoTarget(); InteractionRunner interactionRunner = new InteractionRunner(); interactionRunner.pactsInstance = pactsInstance; interactionRunner.targetInstance = () -> target; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> interactionRunner.executePacts(eventContext)) .withMessage( "Field annotated with org.jboss.arquillian.test.api.ArquillianResource should implement org.arquillian.algeron.pact.provider.spi.Target and didn't found any"); }