EntityManagerImpl implements AbstractEntityManager, Wrapper { @Override public <T> T getReference(Class<T> entityClass, Object identifier) { try { Objects.requireNonNull(entityClass); Objects.requireNonNull(identifier); return getReference(entityClass, identifier, new EntityDescriptor()); } catch (RuntimeException e) { markTransactionForRollback(); throw e; } } EntityManagerImpl(EntityManagerFactoryImpl emf, Configuration configuration, ServerSession serverSession); @Override void persist(final Object entity); @Override void persist(final Object entity, final Descriptor descriptor); @Override T merge(final T entity); @Override T merge(final T entity, final Descriptor descriptor); @Override void remove(Object object); @Override T find(Class<T> cls, Object identifier); @Override T find(Class<T> cls, Object identifier, Descriptor descriptor); @Override T getReference(Class<T> entityClass, Object identifier); @Override T getReference(Class<T> entityClass, Object identifier, Descriptor descriptor); @Override void flush(); @Override void refresh(Object entity); @Override void clear(); @Override void detach(Object entity); @Override boolean contains(Object entity); @Override void close(); @Override boolean isOpen(); @Override EntityTransaction getTransaction(); @Override EntityManagerFactoryImpl getEntityManagerFactory(); @Override Metamodel getMetamodel(); @Override boolean isLoaded(final Object object, final String attributeName); @Override boolean isLoaded(Object object); @Override QueryImpl createQuery(String qlString); @Override TypedQueryImpl<T> createQuery(String query, Class<T> resultClass); @Override QueryImpl createNativeQuery(String sparqlString); @Override TypedQueryImpl<T> createNativeQuery(String sparqlString, Class<T> resultClass); @Override QueryImpl createNativeQuery(String sparqlString, String resultSetMapping); @Override QueryImpl createNamedQuery(String name); @Override TypedQueryImpl<T> createNamedQuery(String name, Class<T> resultClass); @Override boolean isConsistent(URI context); @Override List<URI> getContexts(); @Override void setUseTransactionalOntologyForQueryProcessing(); @Override boolean useTransactionalOntologyForQueryProcessing(); @Override void setUseBackupOntologyForQueryProcessing(); @Override boolean useBackupOntologyForQueryProcessing(); @Override T unwrap(Class<T> cls); @Override Object getDelegate(); @Override UnitOfWorkImpl getCurrentPersistenceContext(); @Override void removeCurrentPersistenceContext(); @Override void transactionStarted(EntityTransaction t); @Override void transactionFinished(EntityTransaction t); @Override Configuration getConfiguration();  }
@Test void getReferenceRetrievesInstanceReferenceFromUnitOfWork() { final OWLClassA instance = new OWLClassA(Generators.createIndividualIdentifier()); doReturn(instance).when(uow).getReference(eq(OWLClassA.class), eq(instance.getUri()), any()); final OWLClassA result = em.getReference(OWLClassA.class, instance.getUri()); assertSame(instance, result); verify(uow).getReference(OWLClassA.class, instance.getUri(), new EntityDescriptor()); }
@Test void getReferenceWithDescriptorRetrievesInstanceReferenceFromUnitOfWork() { final OWLClassA instance = new OWLClassA(Generators.createIndividualIdentifier()); final Descriptor descriptor = new EntityDescriptor(Generators.createIndividualIdentifier()); doReturn(instance).when(uow).getReference(OWLClassA.class, instance.getUri(), descriptor); final OWLClassA result = em.getReference(OWLClassA.class, instance.getUri(), descriptor); assertSame(instance, result); verify(uow).getReference(OWLClassA.class, instance.getUri(), descriptor); }
@Test void getReferenceThrowsIllegalArgumentExceptionWhenTargetClassIsNotEntity() { final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> em.getReference(UnknownEntity.class, Generators.createIndividualIdentifier())); assertEquals(NON_ENTITY_CLASS_EXCEPTION_MESSAGE, ex.getMessage()); verify(uow, never()).getReference(any(), any(), any()); }