### Question:
ConfigurationService { public Configuration updateConfigurationById(Configuration configuration, User user) { Configuration dbConfiguration = configurationRepository.findByIdOrThrow(configuration.getId()); dbConfiguration.setValue(configuration.getValue()); dbConfiguration.setName(configuration.getName()); logger.info( "Updated configuration " + dbConfiguration.getName() + " (id: " + dbConfiguration.getId() + ")"); activityService.createActivity(user, dbConfiguration, Action.EDITED); publishConfigurationChangedEvent(dbConfiguration); return configurationRepository.save(dbConfiguration); }  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 updateConfigurationById_expectEntityNotFoundException() { when(configurationRepository.findByIdOrThrow(42L)).thenThrow(EntityNotFoundException.class); Configuration configuration = new Configuration(); configuration.setId(42L); configurationService.updateConfigurationById(configuration, mockedUser); }
@Test public void updateConfigurationById_expectConfigurationToBeSaved() { Configuration dbConfiguration = new Configuration(); dbConfiguration.setId(42L); dbConfiguration.setName("name"); dbConfiguration.setValue("3"); when(configurationRepository.findByIdOrThrow(42L)).thenReturn(dbConfiguration); when(configurationRepository.save(dbConfiguration)).thenReturn(dbConfiguration); Configuration configuration = new Configuration(); configuration.setId(42L); configuration.setName("name2"); configuration.setValue("4"); Configuration actual = configurationService.updateConfigurationById(configuration, mockedUser); assertConfigurations(configuration, actual); }