1
Spring Web Model-View-Controller(MVC)フレームワークアプリケーションでMockito(MITライセンスで公開されたJavaのオープンソーステストフレームワーク)を使用してこのjunitテストを実施しました 私はこれを持っていますコントローラのメソッド:Mockito:check responseヘッダーとステータス
@RequestMapping(value = { "/devices" } , method = { RequestMethod.GET, RequestMethod.POST})
public void initGetForm(@ModelAttribute("searchForm") final SearchForm searchForm,
HttpServletRequest request,
HttpServletResponse response,
Locale locale) throws Exception {
String newUrl = request.getContextPath() + "/devices/" + locale;
if (locale !=null && isValid(locale)) {
newUrl = request.getContextPath() + "/devices/" + DEFAULT_LOCALE;
}
redirectPermanently (response, newUrl);
}
protected void redirectPermanently (HttpServletResponse response, String to) {
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", to);
response.setHeader("Connection", "close");
}
と、これは私のテストクラスです:
@Test
public void testInitGetForm() throws Exception {
controller.initGetForm(emptySearchForm(), request, response, null);
}
@Before
public void setUpTest() {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
}
はレスポンスのヘッダーとステータスを確認することが可能です?????
このテストではMockitoを使用していません。 –