### Question:
ItemDefinitionCreateHandler { Optional<ItemDefinition> lookupAbsoluteParent(final String parentUUID) { final Optional<ItemDefinition> optionalParent = Optional.ofNullable(getIndexedItemDefinition(parentUUID)); if (optionalParent.isPresent()) { final ItemDefinition parent = optionalParent.get(); final boolean isStructure = parent.getTypeRef() == null; if (isStructure) { return Optional.of(parent); } else { return findItemDefinitionByName(parent.getTypeRef().getLocalPart()); } } return Optional.empty(); } @Inject  ItemDefinitionCreateHandler(final ItemDefinitionUtils itemDefinitionUtils,
                                       final ItemDefinitionStore itemDefinitionStore); ItemDefinition appendItemDefinition(); ItemDefinition insertNested(final DataType record,
                                       final DataType reference); ItemDefinition insertSibling(final DataType record,
                                        final DataType reference,
                                        final CreationType creationType);  }### Answer:
@Test public void testLookupAbsoluteParentWhenParentIsNotPresent() { final String referenceUUID = "referenceUUID"; when(itemDefinitionStore.get(referenceUUID)).thenReturn(null); final Optional<ItemDefinition> absoluteParent = handler.lookupAbsoluteParent(referenceUUID); assertFalse(absoluteParent.isPresent()); }
@Test public void testLookupAbsoluteParentWhenParentIsStructure() { final String referenceUUID = "referenceUUID"; final ItemDefinition parent = mock(ItemDefinition.class); when(parent.getTypeRef()).thenReturn(null); when(itemDefinitionStore.get(referenceUUID)).thenReturn(parent); final Optional<ItemDefinition> actualParent = handler.lookupAbsoluteParent(referenceUUID); final Optional<ItemDefinition> expectedParent = Optional.of(parent); assertEquals(expectedParent, actualParent); }
@Test public void testLookupAbsoluteParentWhenParentIsNotStructure() { final String type = "type"; final String referenceUUID = "referenceUUID"; final ItemDefinition parent = mock(ItemDefinition.class); final Optional<ItemDefinition> expectedParent = Optional.of(mock(ItemDefinition.class)); final QName qName = mock(QName.class); when(qName.getLocalPart()).thenReturn(type); when(parent.getTypeRef()).thenReturn(qName); when(itemDefinitionStore.get(referenceUUID)).thenReturn(parent); when(itemDefinitionUtils.findByName(type)).thenReturn(expectedParent); final Optional<ItemDefinition> actualParent = handler.lookupAbsoluteParent(referenceUUID); assertEquals(expectedParent, actualParent); }