### Question:
LoggerBeanNamesResolver { public Set<String> resolve(GenericApplicationContext applicationContext, String beanName) { String[] beanNamesForType = applicationContext.getBeanNamesForType(EclairLogger.class); if (!asList(beanNamesForType).contains(beanName)) { throw new IllegalArgumentException(format("EclairLogger '%s' not found", beanName)); } Set<String> result = new HashSet<>(asList(applicationContext.getAliases(beanName))); result.add(beanName); if (beanNamesForType.length == 1 || applicationContext.getBeanDefinition(beanName).isPrimary()) { result.add(""); } return result; } private  LoggerBeanNamesResolver(); static LoggerBeanNamesResolver getInstance(); Set<String> resolve(GenericApplicationContext applicationContext, String beanName);  }### Answer:
@Test public void resolve() { String beanName = "simpleLogger"; String emptyLoggerName = ""; String alias = "logger"; GenericApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerBeanDefinition(beanName, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName, alias); Set<String> namesByBeanName = loggerBeanNamesResolver.resolve(applicationContext, beanName); assertThat(namesByBeanName, hasSize(3)); assertThat(namesByBeanName, containsInAnyOrder(beanName, emptyLoggerName, alias)); }
@Test(expected = IllegalArgumentException.class) public void resolveByAlias() { String beanName = "simpleLogger"; String alias = "logger"; GenericApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerBeanDefinition(beanName, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName, alias); loggerBeanNamesResolver.resolve(applicationContext, alias); }
@Test(expected = IllegalArgumentException.class) public void resolveByUnknownBeanName() { String beanName = "simpleLogger"; String alias = "logger"; GenericApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerBeanDefinition(beanName, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName, alias); loggerBeanNamesResolver.resolve(applicationContext, "unknown"); }
@Test(expected = IllegalArgumentException.class) public void resolveByWrongBeanTypeName() { String beanName = "simpleLogger"; String alias = "logger"; String wrongBeanTypeName = "string"; GenericApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerBeanDefinition(beanName, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName, alias); applicationContext.registerBeanDefinition(wrongBeanTypeName, givenStringBeanDefinition()); loggerBeanNamesResolver.resolve(applicationContext, wrongBeanTypeName); }
@Test public void resolveManyLoggers() { String beanName = "simpleLogger"; String alias = "logger"; String beanName2 = "simpleLogger2"; String alias2 = "logger2"; GenericApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerBeanDefinition(beanName, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName, alias); applicationContext.registerBeanDefinition(beanName2, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName2, alias2); Set<String> namesByBeanName = loggerBeanNamesResolver.resolve(applicationContext, beanName); assertThat(namesByBeanName, hasSize(2)); assertThat(namesByBeanName, containsInAnyOrder(beanName, alias)); }
@Test public void resolveManyLoggersWithPrimary() { String beanName = "simpleLogger"; String emptyLoggerName = ""; String alias = "logger"; String beanName2 = "simpleLogger2"; String alias2 = "logger2"; AbstractBeanDefinition primaryDefinition = givenLoggerBeanDefinition(); primaryDefinition.setPrimary(true); GenericApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerBeanDefinition(beanName, primaryDefinition); applicationContext.getBeanFactory().registerAlias(beanName, alias); applicationContext.registerBeanDefinition(beanName2, givenLoggerBeanDefinition()); applicationContext.getBeanFactory().registerAlias(beanName2, alias2); Set<String> namesByBeanName = loggerBeanNamesResolver.resolve(applicationContext, beanName); assertThat(namesByBeanName, hasSize(3)); assertThat(namesByBeanName, containsInAnyOrder(beanName, emptyLoggerName, alias)); }