I set up following pact contract provider test
@RunWith(SpringRestPactRunner.class)
@Provider("structures")
@PactFolder("pacts")
@VerificationReports({"console", "markdown"})
@SpringBootTest
public class ContractTest {
@MockBean
private MyServiceImpl myServiceImpl;
@Autowired
private MyController myController;
@Configuration
public static class TestConfiguration {
@Bean
public MyController myController() {
return new MyController();
}
}
@TestTarget
public final MockMvcTarget target = new MockMvcTarget();
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
target.setControllers(myController);
}
@State("My state")
public void setupDocumentWithStructures() {
Mockito.when(myService.getStructuresByDocumentId(
ArgumentMatchers.eq("1"),
ArgumentMatchers.any()
)).thenReturn(new PageImpl<>(Arrays.asList(
Structure.of("first"),
Structure.of("second")
)));
}
}
Running the test results in:
java.lang.AssertionError:
0 - Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.data.domain.Pageable
java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.data.domain.Pageable
The method getStructuresByDocumentId expects a Pageable object as its second argument. Changing the annotation @SpringBootTest to
@WebMvcTest(MyController.class)
@EnableSpringDataWebSupport
Doesn't solve the problem. Any ideas, how to solve this issue?
I was having the same problem and fixed setting a new
mockMvc
like thisI am not using
@SpringBootTest
as you are, but I think in this case it does not matter. Below is my entire (redacted) code.I hope this helps, I spend a few hours trying to solve this.
Cheers