2016-09-28 2 views
0

어떻게 Mockito를 사용하여 Jax RS Client를 모의 할 수 있습니까?Jax Rs 2.0 Rest Client Response를 조롱하는 방법?

Foo expected = new Foo(); 

    when(restClient.target(anyString()) 
      .path(anyString()) //Got NPE here 
      .request(MediaType.APPLICATION_JSON) 
      .post(Entity.entity(expected, MediaType.APPLICATION_JSON)) 
      .readEntity(Foo.class) 
    ).thenReturn(expected); 

답변

0

당신은 모든 메소드 호출을 조롱 할 것이다 :

when(restClient.target(anyString()).thenReturn(...) 
when(target.path(anyString()).thenReturn(...) 
... 

나는 수익을 위해 RESTClient 무엇인지 모르겠습니다 ... 아마 그냥 위해 RESTClient를 반환을?

+0

적절한 답변과 함께 답변을 작성하십시오. – richersoon

+0

이 작업을 수행하려면 "대상", "경로", "요청", "게시"및 "readEnity"메소드가 반환되는지 알아야합니다. –

+0

any() 할 수 있습니다. – richersoon