### Question:
DataTypeConfirmation { public void ifDataTypeDoesNotHaveLostSubDataTypes(final DataType dataType, final Command onSuccess, final Command onError) { if (hasLostSubDataTypes(dataType)) { flashMessageEvent.fire(dataTypeHasFieldsWarningMessage.getFlashMessage(dataType, onSuccess, onError)); } else { onSuccess.execute(); } } @Inject  DataTypeConfirmation(final DataTypeStore dataTypeStore,
                                final ItemDefinitionStore itemDefinitionStore,
                                final Event<FlashMessage> flashMessageEvent,
                                final DataTypeHasFieldsWarningMessage dataTypeHasFieldsWarningMessage,
                                final ReferencedDataTypeWarningMessage referencedDataTypeWarningMessage,
                                final TranslationService translationService); void ifDataTypeDoesNotHaveLostSubDataTypes(final DataType dataType,
                                                      final Command onSuccess,
                                                      final Command onError); void ifIsNotReferencedDataType(final DataType dataType,
                                          final Command onSuccess);  }### Answer:
@Test public void testIfDataTypeDoesNotHaveLostSubDataTypesWhenSuccessCallbackIsExecuted() { final DataType dataType = mock(DataType.class); final ItemDefinition itemDefinition = mock(ItemDefinition.class); final Command onSuccess = mock(Command.class); final Command onError = mock(Command.class); final String uuid = "uuid"; when(dataType.getUUID()).thenReturn(uuid); when(dataType.getType()).thenReturn(STRUCTURE); when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition); confirmation.ifDataTypeDoesNotHaveLostSubDataTypes(dataType, onSuccess, onError); verify(onSuccess).execute(); }
@Test public void testIfDataTypeDoesNotHaveLostSubDataTypesWhenItemDefinitionItemComponentIsEmpty() { final DataType dataType = mock(DataType.class); final ItemDefinition itemDefinition = mock(ItemDefinition.class); final List<ItemDefinition> itemComponent = singletonList(mock(ItemDefinition.class)); final Command onSuccess = mock(Command.class); final Command onError = mock(Command.class); final String uuid = "uuid"; when(dataType.getUUID()).thenReturn(uuid); when(dataType.getType()).thenReturn(STRUCTURE); when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition); when(itemDefinition.getItemComponent()).thenReturn(itemComponent); confirmation.ifDataTypeDoesNotHaveLostSubDataTypes(dataType, onSuccess, onError); verify(onSuccess).execute(); }
@Test public void testIfDataTypeDoesNotHaveLostSubDataTypesWhenItemDefinitionItemComponentIsNotEmpty() { final DataType dataType = mock(DataType.class); final ItemDefinition itemDefinition = mock(ItemDefinition.class); final List<ItemDefinition> itemComponent = singletonList(mock(ItemDefinition.class)); final Command onSuccess = mock(Command.class); final Command onError = mock(Command.class); final FlashMessage warningMessage = mock(FlashMessage.class); final String uuid = "uuid"; when(dataType.getUUID()).thenReturn(uuid); when(dataType.getType()).thenReturn("tCity"); when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition); when(itemDefinition.getItemComponent()).thenReturn(itemComponent); when(dataTypeHasFieldsWarningMessage.getFlashMessage(dataType, onSuccess, onError)).thenReturn(warningMessage); confirmation.ifDataTypeDoesNotHaveLostSubDataTypes(dataType, onSuccess, onError); verify(onSuccess, never()).execute(); verify(flashMessageEvent).fire(warningMessage); }