### Question:
AbstractContextualPreferenceHandler implements ContextualPreferenceHandler { @Override public boolean isValid(final ContextualPreference preference) { return preference.getResource().getLevel() == level ? externalEntityExists(preference) : validateUsingNextHandler(preference).orElse(false); } AbstractContextualPreferenceHandler(final ContextualPreferenceLevel level,
                                        final ContextualPreferenceHandler nextHandler); @Override boolean isValid(final ContextualPreference preference);  }### Answer:
@Test public void isValidShouldDelegateExecutionToTheNextHandlerIfPreferenceLevelDoesNotSuitCurrentHandler() { final ContextualPreference preference = new ContextualPreference(NAME, VALUE, notSuitableResource); when(nextHandler.isValid(eq(preference))).thenReturn(true); assertTrue(handler().isValid(preference)); verify(nextHandler).isValid(eq(preference)); }
@Test public void isValidShouldReturnFalseIfPreferenceLevelDoesNotSuitCurrentHandlerAndThereIsNoNextHandler() { final ContextualPreference preference = new ContextualPreference(NAME, VALUE, notSuitableResource); assertFalse(lastHandler().isValid(preference)); }