SecurityContextUtil implements UserUtil { public Credential getCurrentUser() throws NoUserLoggedInException { DuracloudUserDetails userDetails = getCurrentUserDetails(); Credential credential = new Credential(userDetails.getUsername(), userDetails.getPassword()); log.debug("user in context: " + credential.toString()); return credential; }  @Override String getCurrentUsername(); Credential getCurrentUser(); DuracloudUserDetails getCurrentUserDetails();  }
@Test public void testGetCurrentUser() throws Exception { createCurrentUserMock(); Credential user = util.getCurrentUser(); Assert.assertNotNull(user); Assert.assertEquals(username, user.getUsername()); }
@Test public void testGetCurrentUserError() throws Exception { replayMocks(); SecurityContextHolder.clearContext(); try { util.getCurrentUser(); Assert.fail("exception expected."); } catch (NoUserLoggedInException e) { Assert.assertNotNull(e); } }