I have a pretty simple method that uses Spring framework and, aside from interacting with injected services, has to new an object and then get an other object using a static method, like so:
// These two guys are injected:
UserDetailsService userDetailsService;
AuthenticationManager authManager;
UserDetails userDetails = userDetailsService.loadUserByUsername(name);
Authentication token = new UsernamePasswordAuthenticationToken(userDetails,
password, userDetails.getAuthorities());
Authentication authentication = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
How should I go about testing it (making sure the methods get called and the right arguments are passed into them)? I cannot simply mock the UsernamePasswordAuthenticationToken and SecurityContextHolder. I could create factories for both things, and that would solve the problem, but it feels like a huge overkill for something as simple as this. Plus then I'd have to test the factories. Is there an other way?