LogoutAction { @RequestMapping("/getAppList") public void getAppList(HttpServletRequest request, HttpServletResponse response){ Credential credential = credentialResolver.resolveCredential(request); List<App> list = this.ki4soService.getAppList(credential); String json = JSON.toJSONString(list); StringBuffer sb = new StringBuffer(); sb.append(getCallbackName("fetchAppList", request)) .append("(") .append(json) .append(");"); try { response.setContentType("application/x-javascript"); response.setCharacterEncoding("UTF-8"); response.getWriter().println(sb.toString()); } catch (IOException e) { } }  void setKi4soService(Ki4soService ki4soService); void setCredentialResolver(CredentialResolver credentialResolver); @RequestMapping("/getAppList") void getAppList(HttpServletRequest request,
			HttpServletResponse response); @RequestMapping("/logout") void logout(HttpServletRequest request,
			HttpServletResponse response);  }
@Test public void testGetAppList() throws UnsupportedEncodingException { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); CredentialResolver credentialResolver = Mockito.mock(CredentialResolver.class); logoutAction.setCredentialResolver(credentialResolver); Ki4soService ki4soService = Mockito.mock(Ki4soService.class); logoutAction.setKi4soService(ki4soService); Credential credential = Mockito.mock(Credential.class); Mockito.when(credentialResolver.resolveCredential(request)).thenReturn(credential); List<App> list = new ArrayList<App>(); App app = new App(); app.setAppId("1000"); app.setAppName("测试应用程序1"); app.setHost("app.com"); app.setLogoutUrl("http: list.add(app); Mockito.when(ki4soService.getAppList(credential)).thenReturn(list); logoutAction.getAppList(request, response); Assert.assertEquals("application/x-javascript", response.getContentType()); Assert.assertEquals("UTF-8", response.getCharacterEncoding()); String content = response.getContentAsString(); content = content.trim(); Assert.assertTrue(content.startsWith("fetchAppList(")); Assert.assertTrue(content.endsWith(");")); String json = content.replaceFirst("fetchAppList\\(", ""); json = json.replaceFirst("\\);", ""); JSONArray data = (JSONArray)JSON.parse(json); Assert.assertEquals(1, data.size()); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>)data.get(0); Assert.assertEquals("1000", map.get("appId")); }