Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

java - Mockito test case for webclient post method

I am pretty new to Mockito and trying to write test case for below post method

  public Mono(Resonse) getReceivers(Request request)
  return webClient.post().uri.url("/receivers").body(Mono.just(request),Request.class)
      .retrieve().bodyToMono(response.clss)

Actually my response class is a wrapper class which return list of List which has Id,name etc.

My request class is simple class has 2 field key and method.

I am trying like this but its giving me error:

    Request request = new Request();
    request.setKey(1111L);
    request.setMethod("ONLINE");

    when(webClientMock.post()).thenReturn(requestBodyUriSpecMock);
    when(requestBodyUriSpecMock.uri(anyString())).thenReturn(requestBodySpecMock);
    when(requestBodySpecMock.header(any(), any())).thenReturn(requestBodySpecMock);
    when(requestBodySpecMock.body(any())).thenReturn(requestHeadersSpecMock);
    when(requestHeadersSpecMock.retrieve()).thenReturn(responseSpecMock);
    when(responseSpecMock.bodyToMono(
        ArgumentMatchers.<Class<Post>>notNull())).thenReturn(Mono.just(request));

     Mono<Response> response = proxy.getRecievers(request);
     Assertions.assertEquals("ONLINE",response.block().getRecievers().getMethod());

Does my test make any sense? Please help

question from:https://stackoverflow.com/questions/65920105/mockito-test-case-for-webclient-post-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...