### Question:
ContextualPreferenceManager { public ContextualPreference load(final String name, final ContextualPreferenceExternalResource resource) { validateName(name); validateResource(resource); return contextualPreferenceDao.load(name, resource) .orElseThrow(() -> new IllegalArgumentException(messageHelper.getMessage( MessageConstants.ERROR_CONTEXTUAL_PREFERENCE_NOT_FOUND, name, resource))); }  List<ContextualPreference> loadAll(); ContextualPreference load(final String name, final ContextualPreferenceExternalResource resource); ContextualPreference search(final List<String> preferences,
                                       final ContextualPreferenceExternalResource resource); ContextualPreference search(final List<String> preferences); @Transactional ContextualPreference upsert(final ContextualPreferenceVO preferenceVO); @Transactional ContextualPreference delete(final String name, final ContextualPreferenceExternalResource resource);  }### Answer:
@Test public void loadShouldFailIfThereIsNoSuchPreference() { when(contextualPreferenceDao.load(eq(NAME), eq(toolResource))).thenReturn(Optional.empty()); assertThrows(() -> manager.load(NAME, toolResource)); verify(contextualPreferenceDao).load(eq(NAME), eq(toolResource)); }
@Test public void loadShouldFailIfSomeOfParametersAreEmpty() { assertThrows(IllegalArgumentException.class, () -> manager.load(null, toolResource)); assertThrows(IllegalArgumentException.class, () -> manager.load(NAME, null)); assertThrows(IllegalArgumentException.class, () -> manager.load(NAME, new ContextualPreferenceExternalResource(null, TOOL_ID))); assertThrows(IllegalArgumentException.class, () -> manager.load(NAME, new ContextualPreferenceExternalResource(LEVEL, null))); }
@Test public void loadShouldReturnPreferenceIfItExists() { final ContextualPreference preference = new ContextualPreference(NAME, VALUE, toolResource); when(contextualPreferenceDao.load(eq(NAME), eq(toolResource))).thenReturn(Optional.of(preference)); final ContextualPreference loadedPreference = manager.load(NAME, toolResource); assertThat(loadedPreference, is(preference)); verify(contextualPreferenceDao).load(eq(NAME), eq(toolResource)); }