Mockito:キャプチャのHttpServletResponse#のsendError()
質問
私が使用することはでき Mockito のHttpServletResponse#sendError()
メソッドに渡されたものをキャプチャしますか?私はそれを行う方法を見つけ出すことはできません。
解決
これを行うには、Mockitoに検証メソッドを使用する必要があります。通常モックのHttpResponseかかわら楽しい経験ではありません。
mockResponse = mock(HttpSR→);
//…
verify(mockResponse, times(1)).sendError(..);
あなたは、あなたが必要とする引数のいずれかのチェックを行うことができますmockitoマッチャを渡すことができsendError
への引数として
他のヒント
私はポスターがメソッドに渡された引数を取得する方法を、知りたいと思ったと思います。あなたが使用することができます:
// given
HttpServletResponse response = mock(HttpServletResponse.class);
ArgumentCaptor<Integer> intArg = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<String> stringArg = ArgumentCaptor.forClass(String.class);
doNothing().when(response).sendError(intArg.capture(), stringArg.capture());
// when (do your test here)
response.sendError(404, "Not found");
// then (do your assertions here, I just print out the values)
System.out.println(intArg.getValue());
System.err.println(stringArg.getValue());
あなたは Mockitoのスパイで見たいと思うかもしれません(第13章)。あなたがモックができないオブジェクトの場合、あなたは時々彼らの内部とスタブ特定の方法この方法を調べることができます。
あなたには、いくつかのサンプルコードを投稿することができた場合は、、私はそれを見てみることができます。
所属していません StackOverflow