### Question:
UserSettingsService { public UserSettings updateUserSettings(UserSettings userSettings, User user) { UserSettings dbUserSettings = userSettingsRepository.findByIdOrThrow(userSettings.getId()); dbUserSettings.setDefaultOkrCompany(userSettings.getDefaultOkrCompany()); dbUserSettings.setDefaultTeam(userSettings.getDefaultTeam()); userSettingsRepository.save(dbUserSettings); return dbUserSettings; } @Autowired  UserSettingsService(
      UserSettingsRepository userSettingsRepository,
      ActivityService activityService,
      CompanyService companyService); UserSettings getUserSettingsByUser(User user); UserSettings updateUserSettings(UserSettings userSettings, User user);  }### Answer:
@Test public void updateUserSettings_expectEntityNotFoundExceptionIfThereIsNoSuchUserSettings() { Long id = 400L; when(userSettingsRepository.findByIdOrThrow(id)).thenThrow(EntityNotFoundException.class); UserSettings userSettings = new UserSettings(); userSettings.setId(id); try { this.userSettingsService.updateUserSettings(userSettings, user); Assert.fail(); } catch (Exception ex) { assertThat( "Should only throw EntityNotFoundException.", ex, instanceOf(EntityNotFoundException.class)); } }
@Test public void updateUserSetting_expectEntitysDefaultCompanyShouldBeUpdated() { Long id = 400L; UserSettings dbUserSettings = new UserSettings(); dbUserSettings.setId(400L); dbUserSettings.setUserId(userId); when(userSettingsRepository.findByIdOrThrow(id)).thenReturn(dbUserSettings); UserSettings userSettingsParam = new UserSettings(); userSettingsParam.setId(id); userSettingsParam.setUserId(userId); Long defaultCompanyId = 550L; OkrCompany defaultOkrCompany = new OkrCompany(); defaultOkrCompany.setId(defaultCompanyId); userSettingsParam.setDefaultOkrCompany(defaultOkrCompany); UserSettings userSettingsResult = this.userSettingsService.updateUserSettings(userSettingsParam, user); Assert.assertEquals(userSettingsParam.getId(), userSettingsResult.getId()); Assert.assertEquals(userSettingsParam.getUserId(), userSettingsResult.getUserId()); Assert.assertEquals( userSettingsParam.getDefaultOkrCompany().getId(), userSettingsParam.getDefaultOkrCompany().getId()); verify(userSettingsRepository, times(1)).save(any()); verify(userSettingsRepository, times(1)).findByIdOrThrow(id); }