DefaultInstanceLoader extends EntityInstanceLoader { @Override <T> T loadEntity(LoadingParameters<T> loadingParameters) { final EntityType<T> et = metamodel.entity(loadingParameters.getEntityType()); return loadInstance(loadingParameters, et); } private  DefaultInstanceLoader(DefaultInstanceLoaderBuilder builder);   }
@Test void testLoadEntity() throws Exception { final Collection<Axiom<?>> entityAAxioms = Collections.singletonList(mock(Axiom.class)); when(connectionMock.find(axiomDescriptor)).thenReturn(entityAAxioms); when(entityConstructorMock.reconstructEntity(IDENTIFIER, etAMock, descriptor, entityAAxioms)) .thenReturn(entityA); final OWLClassA res = instanceLoader.loadEntity(loadingParameters); assertNotNull(res); assertSame(entityA, res); verify(connectionMock).find(axiomDescriptor); }
@Test void testLoadEntityUnknown() throws Exception { when(connectionMock.find(axiomDescriptor)).thenReturn(Collections.emptyList()); final OWLClassA res = instanceLoader.loadEntity(loadingParameters); assertNull(res); verify(connectionMock).find(axiomDescriptor); }
@Test void testLoadEntityDriverException() throws Exception { when(connectionMock.find(any(AxiomDescriptor.class))).thenThrow(new OntoDriverException()); assertThrows(StorageAccessException.class, () -> instanceLoader.loadEntity(loadingParameters)); }
@Test void loadEntityBypassesCacheWhenConfiguredTo() throws Exception { loadingParameters.bypassCache(); final Collection<Axiom<?>> entityAAxioms = Collections.singletonList(mock(Axiom.class)); when(connectionMock.find(axiomDescriptor)).thenReturn(entityAAxioms); when(entityConstructorMock.reconstructEntity(IDENTIFIER, etAMock, descriptor, entityAAxioms)) .thenReturn(entityA); final OWLClassA res = instanceLoader.loadEntity(loadingParameters); assertNotNull(res); verify(cacheMock, never()).contains(etAMock.getJavaType(), IDENTIFIER, descriptor); }