### Question:
DataTypeCreateHandler extends DataTypeHandler { Optional<DataType> lookupAbsoluteParent(final DataType reference) { final Optional<DataType> optionalParent = Optional.ofNullable(parent(reference)); if (optionalParent.isPresent()) { return fetchTopLevelDataType(optionalParent.get()); } return Optional.empty(); } @Inject  DataTypeCreateHandler(final DataTypeStore dataTypeStore,
                                 final DataTypeManager dataTypeManager); List<DataType> append(final DataType dataType,
                                 final ItemDefinition itemDefinition); List<DataType> insertSibling(final DataType dataType,
                                        final DataType reference,
                                        final CreationType creationType,
                                        final ItemDefinition itemDefinition); List<DataType> insertNested(final DataType dataType,
                                       final DataType reference,
                                       final ItemDefinition itemDefinition);  }### Answer:
@Test public void testLookupAbsoluteParentWhenReferenceDoesNotHaveParent() { final DataType reference = mock(DataType.class); final String parentUUID = "parentUUID"; when(reference.getParentUUID()).thenReturn(parentUUID); when(dataTypeStore.get(parentUUID)).thenReturn(null); final Optional<DataType> absoluteParent = handler.lookupAbsoluteParent(reference); assertFalse(absoluteParent.isPresent()); }
@Test public void testLookupAbsoluteParentWhenReferenceTypeIsStructure() { final DataType reference = mock(DataType.class); final DataType expectedParent = mock(DataType.class); final String parentUUID = "parentUUID"; final String structure = "Structure"; when(reference.getParentUUID()).thenReturn(parentUUID); when(expectedParent.getType()).thenReturn(structure); when(dataTypeStore.get(parentUUID)).thenReturn(expectedParent); when(dataTypeManager.structure()).thenReturn(structure); final Optional<DataType> actualParent = handler.lookupAbsoluteParent(reference); assertEquals(Optional.of(expectedParent), actualParent); }
@Test public void testLookupAbsoluteParentWhenReferenceTypeIsNotStructure() { final DataType reference = mock(DataType.class); final DataType expectedParent = mock(DataType.class); final DataType tCityTopLevel = mock(DataType.class); final String parentUUID = "parentUUID"; final String structure = "Structure"; final String type = "tCity"; when(reference.getParentUUID()).thenReturn(parentUUID); when(expectedParent.getType()).thenReturn(type); when(tCityTopLevel.getName()).thenReturn(type); when(dataTypeStore.get(parentUUID)).thenReturn(expectedParent); when(dataTypeManager.structure()).thenReturn(structure); when(dataTypeStore.getTopLevelDataTypes()).thenReturn(singletonList(tCityTopLevel)); final Optional<DataType> actualParent = handler.lookupAbsoluteParent(reference); assertEquals(Optional.of(tCityTopLevel), actualParent); }