Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when trying to resolve Junit5 consumer test class ctor params #1666

Open
iekdosha opened this issue Feb 8, 2023 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@iekdosha
Copy link

iekdosha commented Feb 8, 2023

Scenario:

Using au.com.dius.pact.consumer:junit5 version 4.4.4

//Relevant consumer tests annotations
public class MyTestClass {

  @RegisterExtension
  static final TestDependencyResolver resolverExt = new TestDependencyResolver(/*...*/);
  
  private final TestDependency dependency;

  public MyTestClass(TestDependency dependency) {
    this.dependency = dependency;
  }

  @TestTemplate
  @ExtendWith(PactVerificationInvocationContextProvider.class)
  void test() {
    //...
  }
}

Error message:

Caused by: java.lang.NullPointerException: null cannot be cast to non-null type au.com.dius.pact.provider.junit5.PactVerificationContext
	at au.com.dius.pact.provider.junit5.PactVerificationExtension.supportsParameter(PactVerificationExtension.kt:73)
	at org.junit.jupiter.engine.execution.ParameterResolutionUtils.lambda$resolveParameter$0(ParameterResolutionUtils.java:114)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
	at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.junit.jupiter.engine.execution.ParameterResolutionUtils.resolveParameter(ParameterResolutionUtils.java:115)

The issue seems to be in the method supportsParameter when trying to get verification context from the store: store.get("interactionContext") as PactVerificationContext.
This gets called before creation of the test object so beforeEach lifecycle which inits "interactionContext" is not called yet, leading to a null value which failed to be casted into PactVerificationContext.

@iekdosha iekdosha changed the title NullPointerException when trying to resolve Junit5 consumer test class params NullPointerException when trying to resolve Junit5 consumer test class ctor params Feb 8, 2023
@rholshausen rholshausen added bug Indicates an unexpected problem or unintended behavior smartbear-supported labels Feb 24, 2023
@github-actions
Copy link

👋 Thanks, this ticket has been added to the PactFlow team's backlog as PACT-758

rholshausen added a commit that referenced this issue Feb 24, 2023
@rholshausen
Copy link
Contributor

4.4.7 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants