### Question:
LdapAuthenticateManager { public Boolean authenticate(String userName, String password) { Map<String, LdapAuthenticateService> ldapAuthServiceMap = getSpringContextHolder().getAllBeansOfType(LdapAuthenticateService.class); Boolean authenticated = Boolean.FALSE; for (Map.Entry<String, LdapAuthenticateService> ldapAuthService : ldapAuthServiceMap.entrySet()) { authenticated = ldapAuthService.getValue().authenticate(userName, password); if (authenticated) { break; } } return authenticated; }  Boolean authenticate(String userName, String password); SpringContextHolder getSpringContextHolder(); void setSpringContextHolder(SpringContextHolder springContextHolder);  }### Answer:
@Test public void authenticate_firstOneWorks() { String userName = "userName"; String password = "password"; Map<String, LdapAuthenticateService> ldapAuthServiceMap = getLdapAuthServiceMap(); expect(mockContextHolder.getAllBeansOfType(LdapAuthenticateService.class)).andReturn(ldapAuthServiceMap); expect(mockFirstService.authenticate(userName, password)).andReturn(Boolean.TRUE); replayAll(); Boolean authenticated = unit.authenticate(userName, password); verifyAll(); assertTrue(authenticated); }
@Test public void authenticate_secondWorks() { String userName = "userName"; String password = "password"; Map<String, LdapAuthenticateService> ldapAuthServiceMap = getLdapAuthServiceMap(); expect(mockContextHolder.getAllBeansOfType(LdapAuthenticateService.class)).andReturn(ldapAuthServiceMap); expect(mockFirstService.authenticate(userName, password)).andReturn(Boolean.FALSE); expect(mockSecondService.authenticate(userName, password)).andReturn(Boolean.TRUE); replayAll(); Boolean authenticated = unit.authenticate(userName, password); verifyAll(); assertTrue(authenticated); }
@Test public void authenticate_noneWorks() { String userName = "userName"; String password = "password"; Map<String, LdapAuthenticateService> ldapAuthServiceMap = getLdapAuthServiceMap(); expect(mockContextHolder.getAllBeansOfType(LdapAuthenticateService.class)).andReturn(ldapAuthServiceMap); expect(mockFirstService.authenticate(userName, password)).andReturn(Boolean.FALSE); expect(mockSecondService.authenticate(userName, password)).andReturn(Boolean.FALSE); replayAll(); Boolean authenticated = unit.authenticate(userName, password); verifyAll(); assertFalse(authenticated); }