@Test public void testSiblingsWhenDataTypeHasParent() { final DataType dataType = mock(DataType.class); final DataType parent = mock(DataType.class); final String parentUUID = "parentUUID"; final List<DataType> expectedSiblings = Collections.singletonList(mock(DataType.class)); when(dataType.getParentUUID()).thenReturn(parentUUID); when(parent.getSubDataTypes()).thenReturn(expectedSiblings); when(dataTypeStore.get(parentUUID)).thenReturn(parent); final List<DataType> actualSiblings = validator.siblings(dataType); assertEquals(expectedSiblings, actualSiblings); }
public List<DataType> siblings(final DataType dataType) { final Optional<DataType> parent = Optional.ofNullable(dataTypeStore.get(dataType.getParentUUID())); if (parent.isPresent()) { return parent.get().getSubDataTypes(); } else { return dataTypeStore.getTopLevelDataTypes(); } }
DataTypeNameValidator { public List<DataType> siblings(final DataType dataType) { final Optional<DataType> parent = Optional.ofNullable(dataTypeStore.get(dataType.getParentUUID())); if (parent.isPresent()) { return parent.get().getSubDataTypes(); } else { return dataTypeStore.getTopLevelDataTypes(); } } }
DataTypeNameValidator { public List<DataType> siblings(final DataType dataType) { final Optional<DataType> parent = Optional.ofNullable(dataTypeStore.get(dataType.getParentUUID())); if (parent.isPresent()) { return parent.get().getSubDataTypes(); } else { return dataTypeStore.getTopLevelDataTypes(); } } @Inject  DataTypeNameValidator(final Event<FlashMessage> flashMessageEvent,
                                 final DataTypeNameIsBlankErrorMessage blankErrorMessage,
                                 final DataTypeNameIsNotUniqueErrorMessage notUniqueErrorMessage,
                                 final DataTypeNameIsDefaultTypeMessage nameIsDefaultTypeMessage,
                                 final DataTypeStore dataTypeStore); }
DataTypeNameValidator { public List<DataType> siblings(final DataType dataType) { final Optional<DataType> parent = Optional.ofNullable(dataTypeStore.get(dataType.getParentUUID())); if (parent.isPresent()) { return parent.get().getSubDataTypes(); } else { return dataTypeStore.getTopLevelDataTypes(); } } @Inject  DataTypeNameValidator(final Event<FlashMessage> flashMessageEvent,
                                 final DataTypeNameIsBlankErrorMessage blankErrorMessage,
                                 final DataTypeNameIsNotUniqueErrorMessage notUniqueErrorMessage,
                                 final DataTypeNameIsDefaultTypeMessage nameIsDefaultTypeMessage,
                                 final DataTypeStore dataTypeStore); boolean isValid(final DataType dataType); boolean isNotUnique(final DataType dataType); List<DataType> siblings(final DataType dataType); }
DataTypeNameValidator { public List<DataType> siblings(final DataType dataType) { final Optional<DataType> parent = Optional.ofNullable(dataTypeStore.get(dataType.getParentUUID())); if (parent.isPresent()) { return parent.get().getSubDataTypes(); } else { return dataTypeStore.getTopLevelDataTypes(); } } @Inject  DataTypeNameValidator(final Event<FlashMessage> flashMessageEvent,
                                 final DataTypeNameIsBlankErrorMessage blankErrorMessage,
                                 final DataTypeNameIsNotUniqueErrorMessage notUniqueErrorMessage,
                                 final DataTypeNameIsDefaultTypeMessage nameIsDefaultTypeMessage,
                                 final DataTypeStore dataTypeStore); boolean isValid(final DataType dataType); boolean isNotUnique(final DataType dataType); List<DataType> siblings(final DataType dataType);  }