KeyAction { @RequestMapping("/fetchKey") @ResponseBody public Ki4soKey fetchKey(String appId){ return keyService.findKeyByAppId(appId); }  void setKeyService(KeyService keyService); @RequestMapping("/fetchKey") @ResponseBody Ki4soKey fetchKey(String appId);  }
@Test public void testFetchKey() throws UnsupportedEncodingException { KeyService keyService = Mockito.mock(KeyService.class); Ki4soKey ki4soKey = Mockito.mock(Ki4soKey.class); Mockito.when(keyService.findKeyByAppId(Mockito.anyString())).thenReturn(ki4soKey); keyAction.setKeyService(keyService); Ki4soKey result = keyAction.fetchKey("100"); Assert.assertTrue(ki4soKey==result); }