### Question:
HasItemsAvailableValuesAspectDefinition extends AvailableValuesAspectDefinition<HasItems<?>> { @SuppressWarnings("unchecked") @Override protected void handleNullItems(ComponentWrapper componentWrapper, List<?> items) { Object component = componentWrapper.getComponent(); if (component instanceof ComboBox<?>) { boolean hasNullItem = items.removeIf(i -> i == null); ((ComboBox<Object>)component).setEmptySelectionAllowed(hasNullItem); } else if (component instanceof NativeSelect<?>) { boolean hasNullItem = items.removeIf(i -> i == null); ((NativeSelect<Object>)component).setEmptySelectionAllowed(hasNullItem); } } HasItemsAvailableValuesAspectDefinition(AvailableValuesType availableValuesType);   }### Answer:
@Test public void testHandleNullItems_ComboBox() { HasItemsAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new HasItemsAvailableValuesAspectDefinition( AvailableValuesType.DYNAMIC); ComboBox<TestEnum> comboBox = new ComboBox<>(); hasItemsAvailableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(comboBox), new LinkedList<>(Arrays.asList(TestEnum.ONE, null))); assertThat(comboBox.isEmptySelectionAllowed()); hasItemsAvailableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(comboBox), new LinkedList<>(Arrays.asList(TestEnum.TWO))); assertThat(comboBox.isEmptySelectionAllowed(), is(false)); }
@Test public void testHandleNullItems_NativeSelect() { HasItemsAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new HasItemsAvailableValuesAspectDefinition( AvailableValuesType.DYNAMIC); NativeSelect<TestEnum> nativeSelect = new NativeSelect<>(); hasItemsAvailableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(nativeSelect), new LinkedList<>(Arrays.asList(TestEnum.ONE, null))); assertThat(nativeSelect.isEmptySelectionAllowed()); hasItemsAvailableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(nativeSelect), new LinkedList<>(Arrays.asList(TestEnum.TWO))); assertThat(nativeSelect.isEmptySelectionAllowed(), is(false)); }
@Test public void testHandleNullItems_Other() { HasItemsAvailableValuesAspectDefinition hasItemsAvailableValuesAspectDefinition = new HasItemsAvailableValuesAspectDefinition( AvailableValuesType.DYNAMIC); Component component = mock(HasItems.class, withSettings().extraInterfaces(Component.class)); hasItemsAvailableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(component), new LinkedList<>(Arrays.asList(TestEnum.ONE, null))); verifyNoMoreInteractions(component); hasItemsAvailableValuesAspectDefinition.handleNullItems(new LabelComponentWrapper(component), new LinkedList<>(Arrays.asList(TestEnum.TWO))); verifyNoMoreInteractions(component); }