Jerseyを使ったRESTサービスのためにJUnitとMockitoを使ってテストケースを書いています。私は、Responseクラスの模擬オブジェクトの代わりにnullオブジェクトを取得しています。Mockitoを使った模擬型
コードテスト
Response response = builder
.put(Entity.entity(new ByteArrayInputStream(jsonObj.toString().getBytes()), MediaType.APPLICATION_JSON), Response.class);
テストケースの下で:
private Invocation.Builder builder;
private Entity<ByteArrayInputStream> inputStream;
private Response response;
@Before
public void setUp() throws Exception {
builder = mock(Invocation.Builder.class);
inputStream = (Entity<ByteArrayInputStream>)mock(Entity.class);
response = mock(Response.class);
}
@Test
public void myTest() {
when(builder.put(inputStream, Response.class)).thenReturn(response);
}
だから、このコード行は私にヌル応答を与えます。これを行う他の方法はありますか?
ありがとうございました。