I've been trying to mock a static method on the producer side to generate and run the contracts against the controller but the tests are running against the actual method
Here's the controller on producer where "getId" is the static method in the class
@PostMapping(path = "/getone", consumes = "application/json", produces = "application/json")
public ResponseEntity<Response> getone(@RequestBody Test[] test) {
String appId = Utils.getId();
return new ResponseEntity<>(service.pub(test,id), HttpStatus.OK);
}
Here's the base test on the producer side which generates contracts
@ExtendWith(SpringExtension.class)
@ActiveProfiles("test")
@SpringBootTest
public class ContractTest {
@Autowired
private WebApplicationContext context;
@Mock
private Utils utils;
@BeforeEach
void setup() {
try (MockedStatic mocked = mockStatic(Utils.class)) {
mocked.when(() -> Utils.getId()).thenReturn("194");
RestAssuredMockMvc.webAppContextSetup(this.context);}
}
I've tried using the standalone setup as well but no luck
@Autowired
private ApiController controller;
@BeforeEach
void setup() {
try (MockedStatic mocked = mockStatic(Utils.class)) {
mocked.when(() -> Utils.getId()).thenReturn("194");
StandaloneMockMvcBuilder standaloneMockMvcBuilder = MockMvcBuilders.standaloneSetup(controller);
RestAssuredMockMvc.standaloneSetup(standaloneMockMvcBuilder);}
The tests are running against the actual class rather than the mocked value. Is there any way to mock the static method getId() and generate the tests ?