### Question:
ItemDefinitionDestroyHandler { Optional<ItemDefinition> findItemDefinitionParent(final DataType dataType) { final Optional<ItemDefinition> itemDefinitionParent = Optional.ofNullable(itemDefinitionStore.get(dataType.getParentUUID())); if (itemDefinitionParent.isPresent()) { final ItemDefinition parent = itemDefinitionParent.get(); if (parent.getTypeRef() == null) { return Optional.of(parent); } else { for (final ItemDefinition itemDefinition : itemDefinitions()) { if (Objects.equals(itemDefinition.getName().getValue(), parent.getTypeRef().getLocalPart())) { return Optional.of(itemDefinition); } } } } return Optional.empty(); } @Inject  ItemDefinitionDestroyHandler(final ItemDefinitionStore itemDefinitionStore,
                                        final DMNGraphUtils dmnGraphUtils,
                                        final PropertiesPanelNotifier panelNotifier); void destroy(final DataType dataType, final boolean notifyPropertiesPanel);  }### Answer:
@Test public void testFindItemDefinitionParentWhenParentDoesNotExist() { final DataType dataType = mock(DataType.class); final String parentUUID = "parentUUID"; when(dataType.getParentUUID()).thenReturn(parentUUID); when(itemDefinitionStore.get(parentUUID)).thenReturn(null); final Optional<ItemDefinition> expectedParent = Optional.empty(); final Optional<ItemDefinition> actualParent = handler.findItemDefinitionParent(dataType); assertEquals(expectedParent, actualParent); }
@Test public void testFindItemDefinitionParentWhenParentDoesNotHaveTypeRef() { final DataType dataType = mock(DataType.class); final ItemDefinition parent = makeItemDefinition(); final String parentUUID = "parentUUID"; when(parent.getTypeRef()).thenReturn(null); when(dataType.getParentUUID()).thenReturn(parentUUID); when(itemDefinitionStore.get(parentUUID)).thenReturn(parent); final Optional<ItemDefinition> expectedParent = Optional.of(parent); final Optional<ItemDefinition> actualParent = handler.findItemDefinitionParent(dataType); assertEquals(expectedParent, actualParent); }