final User authUser = new UserImpl(USER_ID);
AbstractAuthenticationToken auth = createNiceMock(AbstractAuthenticationToken.class);
expect(auth.getPrincipal()).andReturn(authUser).anyTimes();
replay(auth);
SecurityContext context = new SecurityContextImpl();
context.setAuthentication(auth);
SecurityContextHolder.setContext(context);
User result = service.getAuthenticatedUser();
assertThat(result, is(sameInstance(authUser)));