### Question:
ConfigFileValidationApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> { @Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { String configFilesString = event.getEnvironment().getProperty("spring.config.location"); ConfigFileValidator.validate(configFilesString); }  @Override void onApplicationEvent(ApplicationEnvironmentPreparedEvent event);  }### Answer:
@Test(expected = ConfigFileValidationException.class) public void configFileLocationIsNotSet() throws Exception { listener.onApplicationEvent(event); }
@Test(expected = ConfigFileValidationException.class) public void configFileLocationIsBlank() throws Exception { when(environment.getProperty(SPRING_CONFIG_LOCATION)).thenReturn(" "); listener.onApplicationEvent(event); }
@Test public void singleFileExists() throws Exception { File location = tmp.newFile(); when(environment.getProperty(SPRING_CONFIG_LOCATION)).thenReturn(location.getAbsolutePath()); listener.onApplicationEvent(event); }
@Test(expected = ConfigFileValidationException.class) public void singleFileDoesNotExist() throws Exception { File location = new File(tmp.getRoot(), "trick"); when(environment.getProperty(SPRING_CONFIG_LOCATION)).thenReturn(location.getAbsolutePath()); listener.onApplicationEvent(event); }
@Test(expected = ConfigFileValidationException.class) public void singleFileIsADirectory() throws Exception { when(environment.getProperty(SPRING_CONFIG_LOCATION)).thenReturn(tmp.getRoot().getAbsolutePath()); listener.onApplicationEvent(event); }
@Test public void multipleFilesExist() throws Exception { File location1 = tmp.newFile(); File location2 = tmp.newFile(); when(environment.getProperty(SPRING_CONFIG_LOCATION)) .thenReturn(COMMA_JOINER.join(location1.getAbsolutePath(), location2.getAbsolutePath())); listener.onApplicationEvent(event); }
@Test(expected = ConfigFileValidationException.class) public void multipleFilesAndOneDoesNotExist() throws Exception { File location1 = tmp.newFile(); File location2 = new File(tmp.getRoot(), "trick"); when(environment.getProperty(SPRING_CONFIG_LOCATION)) .thenReturn(COMMA_JOINER.join(location1.getAbsolutePath(), location2.getAbsolutePath())); listener.onApplicationEvent(event); }
@Test(expected = ConfigFileValidationException.class) public void multipleFilesAndOneIsADirectory() throws Exception { File location1 = tmp.newFile(); File location2 = tmp.getRoot(); when(environment.getProperty(SPRING_CONFIG_LOCATION)) .thenReturn(COMMA_JOINER.join(location1.getAbsolutePath(), location2.getAbsolutePath())); listener.onApplicationEvent(event); }