### Question:
SshShellSecurityAuthenticationProvider implements SshShellAuthenticationProvider { @PostConstruct public void init() { Map<String, AuthenticationManager> map = context.getBeansOfType(AuthenticationManager.class); if (map.isEmpty()) { throw new BeanCreationException( "Could not find any beans of class: " + AuthenticationManager.class.getName()); } String beanName = authProviderBeanName; Set<String> available = map.keySet(); if (beanName != null && !beanName.isEmpty()) { this.authenticationManager = map.get(beanName); if (this.authenticationManager == null) { throw new BeanCreationException( "Could not find bean with name: " + beanName + " and class: " + AuthenticationManager.class .getName() + ". Available are: " + available); } } else { if (map.size() != 1) { throw new BeanCreationException( "Found too many beans of class: " + AuthenticationManager.class.getName() + ". Please specify" + " name with property '" + SSH_SHELL_PREFIX + ".authProviderBeanName'"); } Map.Entry<String, AuthenticationManager> e = map.entrySet().iterator().next(); beanName = e.getKey(); this.authenticationManager = e.getValue(); } LOGGER.info("Using authentication manager named: {} [class={}]", beanName, this.authenticationManager.getClass().getName()); } SshShellSecurityAuthenticationProvider(ApplicationContext context, String authProviderBeanName); @PostConstruct void init(); @Override boolean authenticate(String username, String pass,
                                ServerSession serverSession);  }### Answer:
@Test void init() { SshShellSecurityAuthenticationProvider provider = new SshShellSecurityAuthenticationProvider(ctx, null); BeanCreationException ex = assertThrows(BeanCreationException.class, provider::init); assertTrue(ex.getMessage().contains("find any beans of")); Map<String, Object> map = new HashMap<>(); map.put("sec1", sec); map.put("sec2", sec); Mockito.when(ctx.getBeansOfType(any())).thenReturn(map); ex = assertThrows(BeanCreationException.class, provider::init); assertTrue(ex.getMessage().contains("too many beans of")); Mockito.when(ctx.getBeansOfType(any())).thenReturn(Collections.singletonMap("sec", sec)); provider.init(); }
@Test void initWithBeanName() { ApplicationContext ctx = Mockito.mock(ApplicationContext.class); AuthenticationManager sec = Mockito.mock(AuthenticationManager.class); SshShellSecurityAuthenticationProvider provider = new SshShellSecurityAuthenticationProvider(ctx, "sec"); Map<String, Object> map = new HashMap<>(); map.put("sec1", sec); map.put("sec2", sec); Mockito.when(ctx.getBeansOfType(any())).thenReturn(map); BeanCreationException ex = assertThrows(BeanCreationException.class, provider::init); assertTrue(ex.getMessage().contains("not find bean with name")); map.put("sec", sec); Mockito.when(ctx.getBeansOfType(any())).thenReturn(Collections.singletonMap("sec", sec)); provider.init(); }