ReferenceSavingResolver { boolean shouldSaveReference(Object value, URI context) { return value == null || IdentifierTransformer.isValidIdentifierType(value.getClass()) || shouldSaveReferenceToItem(value, context); } ReferenceSavingResolver(ObjectOntologyMapperImpl mapper);   }
@Test void shouldSaveReferenceReturnsTrueForNullValue() { assertTrue(resolver.shouldSaveReference(null, null)); }
@Test void shouldSaveReferenceReturnsTrueForPlainIdentifierValue() { final URI value = Generators.createIndividualIdentifier(); assertTrue(resolver.shouldSaveReference(value, null)); }
@Test void shouldSaveReferenceReturnsFalseForValueWithNullIdentifier() { final OWLClassA value = new OWLClassA(); when(mapperMock.getEntityType(OWLClassA.class)).thenReturn(metamodelMocks.forOwlClassA().entityType()); assertFalse(resolver.shouldSaveReference(value, null)); }
@Test void shouldSaveReferenceReturnsTrueForValueBeingManaged() { final OWLClassA value = Generators.generateOwlClassAInstance(); when(mapperMock.isManaged(value)).thenReturn(true); assertTrue(resolver.shouldSaveReference(value, null)); verify(mapperMock).isManaged(value); }
@Test void shouldSaveReferenceReturnsTrueForValueExistingInStorage() { final OWLClassA value = Generators.generateOwlClassAInstance(); when(mapperMock.isManaged(value)).thenReturn(false); when(mapperMock.getEntityType(OWLClassA.class)).thenReturn(metamodelMocks.forOwlClassA().entityType()); when(mapperMock.containsEntity(eq(OWLClassA.class), eq(value.getUri()), any())).thenReturn(true); assertTrue(resolver.shouldSaveReference(value, null)); verify(mapperMock).containsEntity(OWLClassA.class, value.getUri(), new EntityDescriptor()); }
@Test void shouldSaveReferenceReturnsTrueForValueExistingInStorageContext() { final OWLClassA value = Generators.generateOwlClassAInstance(); final URI context = Generators.createIndividualIdentifier(); when(mapperMock.isManaged(value)).thenReturn(false); when(mapperMock.getEntityType(OWLClassA.class)).thenReturn(metamodelMocks.forOwlClassA().entityType()); when(mapperMock.containsEntity(eq(OWLClassA.class), eq(value.getUri()), any())).thenReturn(true); assertTrue(resolver.shouldSaveReference(value, context)); verify(mapperMock).containsEntity(OWLClassA.class, value.getUri(), new EntityDescriptor(context)); }