InstanceDescriptorFactory { public static <T> InstanceDescriptor<T> create(T instance, EntityType<T> et) { final InstanceDescriptor<T> descriptor = createNotLoaded(instance, et); et.getFieldSpecifications() .forEach(fs -> descriptor.setLoaded(fs, fs.getFetchType() == FetchType.EAGER ? LoadState.LOADED : EntityPropertiesUtils.getAttributeValue(fs, instance) != null ? LoadState.LOADED : LoadState.UNKNOWN)); return descriptor; } private  InstanceDescriptorFactory(); static InstanceDescriptor<T> createNotLoaded(T instance, EntityType<T> et); static InstanceDescriptor<T> createAllLoaded(T instance, EntityType<T> et); static InstanceDescriptor<T> create(T instance, EntityType<T> et); static InstanceDescriptor<T> createCopy(T instance, InstanceDescriptor<T> original);  }
@Test void createCreatesInstanceDescriptorWithLoadedSetForNonNullAttributes() { final OWLClassA instance = Generators.generateOwlClassAInstance(); instance.setTypes(null); final InstanceDescriptor<OWLClassA> result = InstanceDescriptorFactory .create(instance, metamodelMocks.forOwlClassA().entityType()); assertNotNull(result); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassA().identifier())); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassA().stringAttribute())); }
@Test void createCreatesInstanceDescriptorWithLoadedSetForNullEagerlyFetchedAttributes() { final OWLClassA instance = Generators.generateOwlClassAInstance(); instance.setStringAttribute(null); instance.setTypes(null); final InstanceDescriptor<OWLClassA> result = InstanceDescriptorFactory .create(instance, metamodelMocks.forOwlClassA().entityType()); assertNotNull(result); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassA().identifier())); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassA().stringAttribute())); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassA().typesSpec())); }
@Test void createCreatesInstanceDescriptorWithUnknownSetForNullLazilyFetchedAttributes() { final OWLClassC instance = new OWLClassC(Generators.createIndividualIdentifier()); final InstanceDescriptor<OWLClassC> result = InstanceDescriptorFactory .create(instance, metamodelMocks.forOwlClassC().entityType()); assertNotNull(result); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassC().identifier())); assertEquals(LoadState.LOADED, result.isLoaded(metamodelMocks.forOwlClassC().referencedListAtt())); assertEquals(LoadState.UNKNOWN, result.isLoaded(metamodelMocks.forOwlClassC().simpleListAtt())); }