### Question:
ContextualPreferenceDao extends NamedParameterJdbcDaoSupport { public ContextualPreference upsert(final ContextualPreference preference) { final ContextualPreference upsertingPreference = preference.withCreatedDate(DateUtils.now()); getNamedParameterJdbcTemplate().update( insertContextualPreferenceQuery, Parameters.getParameters(upsertingPreference) ); return upsertingPreference; }  ContextualPreference upsert(final ContextualPreference preference); Optional<ContextualPreference> load(final String name,
                                               final ContextualPreferenceExternalResource externalResource); List<ContextualPreference> load(final String name); void delete(final String name, final ContextualPreferenceExternalResource externalResource); List<ContextualPreference> loadAll();  }### Answer:
@Test public void upsertShouldFailIfPreferenceHasEmptyFields() { assertThrows(() -> { final ContextualPreference preferenceWithoutName = new ContextualPreference(null, VALUE, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID)); contextualPreferenceDao.upsert(preferenceWithoutName); }); assertThrows(() -> { final ContextualPreference preferenceWithoutValue = new ContextualPreference(NAME, null, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID)); contextualPreferenceDao.upsert(preferenceWithoutValue); }); assertThrows(() -> { final ContextualPreference preferenceWithoutType = new ContextualPreference(NAME, VALUE, null, new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID)); contextualPreferenceDao.upsert(preferenceWithoutType); }); assertThrows(() -> { final ContextualPreference preferenceWithoutType = new ContextualPreference(NAME, VALUE, PreferenceType.STRING, null); contextualPreferenceDao.upsert(preferenceWithoutType); }); assertThrows(() -> { final ContextualPreference preferenceWithoutResourceLevel = new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(null, RESOURCE_ID)); contextualPreferenceDao.upsert(preferenceWithoutResourceLevel); }); assertThrows(() -> { final ContextualPreference preferenceWithoutResourceId = new ContextualPreference(NAME, VALUE, new ContextualPreferenceExternalResource(LEVEL, null)); contextualPreferenceDao.upsert(preferenceWithoutResourceId); }); }