### Question:
ConfigurationService { public Configuration getConfigurationByName(String name) { Optional<Configuration> configuration = configurationRepository.findByName(name); if (configuration.isPresent()) { return configuration.get(); } else { throw new EntityNotFoundException("Entity with name " + name + " could not be found"); } }  Collection<Configuration> getAllConfigurations(); Configuration getConfigurationById(Long configurationId); Configuration getConfigurationByName(String name); Configuration createConfiguration(Configuration configuration, User user); Configuration updateConfigurationById(Configuration configuration, User user); void deleteConfigurationById(Long configurationId, User user);  }### Answer:
@Test(expected = EntityNotFoundException.class) public void getConfigurationByName_expectException() { when(configurationRepository.findByName("name")).thenThrow(EntityNotFoundException.class); Configuration configuration = configurationService.getConfigurationByName("name"); }
@Test public void getConfigurationByName_expectConfiguration() { Configuration dbConfiguration = new Configuration(); dbConfiguration.setId(42L); dbConfiguration.setName("name"); dbConfiguration.setValue("3"); when(configurationRepository.findByName("name")).thenReturn(Optional.of(dbConfiguration)); Configuration configuration = configurationService.getConfigurationByName("name"); Assert.assertEquals(dbConfiguration.getId(), configuration.getId()); Assert.assertEquals(dbConfiguration.getName(), configuration.getName()); Assert.assertEquals(dbConfiguration.getValue(), configuration.getValue()); }