pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Incompatible use of Generics between Pact an RequestResponsePact #644

Closed ohubaut closed 6 years ago

ohubaut commented 6 years ago

The Pact interface has a method fun mergeInteractions(interactions: List<Interaction>) and a property val interactions: List<Interaction>. This could be all and well if the RequestResponsePact did not exposes an incompatible property List<RequestResponseInteraction> interactions.

In theory, this should be a compile error, but I guess the Groovy compiler is (once again) too permissive. The other oddity is that the same class use an unsafe cast in the void mergeInteractions(List<Interaction> interactions) method.

I see two options here: Either the class can manage to work with a list of Interaction instead of RequestResponseInteraction, either the Pact interface has to be generified so that the generic contract is satisfied.

As of now, working in Java, this code does not compile:

RequestResponsePact pactA = ...;
RequestResponsePact pactB = ...;
pactA.mergeInteractions(pactB.getInteractions());
uglyog commented 6 years ago

I've added an upper trait bound on all the uses of the Pact interface. This should resolve the signature issues.