Mockito stubbing exception

85 Views Asked by At

I understand that the below error tells either I have to use all mocks or all original values.

Invalid use of argument matchers!
0 matchers expected, 4 recorded:

but for my code, I am using all mocks but still getting this error. below is my test code.

@ExtendWith(MockitoExtension.class)
public class GroupServiceImplTest extends TraceUtilsTest {

    @InjectMocks
    private GroupServiceImpl groupService;

    @InjectMocks
    private ClientRequest clientRequest;

    @Test
    public void shouldThrowHttpExceptionIfDeletionails(){
        Mockito.when(clientRequest.getAPIResponseUsingDeleteMethod(anyString(),
            Mockito.any(Mono.class), Mockito.eq(Request.class),
            Mockito.eq(Response.class))).thenReturn(Mono.error(new HttpServerErrorException(HttpStatus.BAD_REQUEST,
            "Abandoning r")));
        StepVerifier.create(groupService.deleteDataFromUpStream("123",List.of("123")))
            .expectErrorMatches(exception -> exception instanceof HttpClientErrorException && exception.getMessage().contains("Abandoning retrying as Error code is 4xx:"))
            .verify();
    }
}

below is my original code to test

public Mono<GroupDetailsResponse> deleteDataFromUpStream(final String groupName, final List<String> groupData) {

    return deleteGroup(groupId, groupData);
}

private Mono<GroupDetailsResponse> deleteGroup(String groupName, List<String> groupData) {
    return  clientRequest.getAPIResponseUsingDeleteMethod(new StringBuilder("baseurl")
                                                                    .append("prodgroupPath")
                                                                    .append("/")
                                                                    .append(groupName)
                                                                    
                                                                    .toString(),
                                                                    GroupRequest.groupData(groupData).build(),
                                                                    GroupRequest.class,
                                                                    GroupDetailsResponse.class
                                                );
}
0

There are 0 best solutions below