@Test(expected = NullPointerException.class) public void testDetermineCollectionSizeThrowsExceptionWithoutEntityManager() { QueryOptimizer optimizer = new QueryOptimizer(); optimizer.determineCollectionSize(new ArrayList<String>()); }
public long determineCollectionSize(final Collection<?> collection) { if (entityManager == null) { throw new NullPointerException("EntityManager is null - needs to be injected."); } Session session = (Session) entityManager.getDelegate(); return ((Long) session.createFilter(collection, "select count(*)").list().get(0)).longValue(); }
QueryOptimizer { public long determineCollectionSize(final Collection<?> collection) { if (entityManager == null) { throw new NullPointerException("EntityManager is null - needs to be injected."); } Session session = (Session) entityManager.getDelegate(); return ((Long) session.createFilter(collection, "select count(*)").list().get(0)).longValue(); } }
QueryOptimizer { public long determineCollectionSize(final Collection<?> collection) { if (entityManager == null) { throw new NullPointerException("EntityManager is null - needs to be injected."); } Session session = (Session) entityManager.getDelegate(); return ((Long) session.createFilter(collection, "select count(*)").list().get(0)).longValue(); }  }
QueryOptimizer { public long determineCollectionSize(final Collection<?> collection) { if (entityManager == null) { throw new NullPointerException("EntityManager is null - needs to be injected."); } Session session = (Session) entityManager.getDelegate(); return ((Long) session.createFilter(collection, "select count(*)").list().get(0)).longValue(); }  @PersistenceContext void setEntityManager(final EntityManager newEntityManager); long determineCollectionSize(final Collection<?> collection); }
QueryOptimizer { public long determineCollectionSize(final Collection<?> collection) { if (entityManager == null) { throw new NullPointerException("EntityManager is null - needs to be injected."); } Session session = (Session) entityManager.getDelegate(); return ((Long) session.createFilter(collection, "select count(*)").list().get(0)).longValue(); }  @PersistenceContext void setEntityManager(final EntityManager newEntityManager); long determineCollectionSize(final Collection<?> collection);  }