### Question:
RosterDAO extends AbstractDAO<RosterEntity> { public Optional<String> retrieveProviderNPIFromRoster(UUID organizationID, UUID providerOrRosterID, String patientMBI) { final CriteriaBuilder builder = currentSession().getCriteriaBuilder(); final CriteriaQuery<String> query = builder.createQuery(String.class); final Root<RosterEntity> root = query.from(RosterEntity.class); query.select(root.get(RosterEntity_.ATTRIBUTED_PROVIDER).get(ProviderEntity_.PROVIDER_NP_I)); List<Predicate> predicates = new ArrayList<>(); predicates.add(organizationPredicate(builder, root, organizationID)); predicates.add(providerOrRosterIDPredicate(builder, root, providerOrRosterID)); predicates.add(mbiPredicate(builder, root, patientMBI)); query.where(predicates.toArray(new Predicate[0])); Query<String> q = currentSession().createQuery(query); try { return Optional.ofNullable(q.getSingleResult()); } catch(NoResultException e) { return Optional.empty(); } } @Inject  RosterDAO(DPCManagedSessionFactory factory); Optional<String> retrieveProviderNPIFromRoster(UUID organizationID, UUID providerOrRosterID, String patientMBI);  }### Answer:
@Test public void testGettingProviderNPI() { Optional<String> npi = rosterDAO.retrieveProviderNPIFromRoster(organizationEntity.getId(), providerEntity.getID(), patientEntity.getBeneficiaryID()); Assertions.assertTrue(npi.isPresent()); Assertions.assertEquals(providerEntity.getProviderNPI(), npi.get()); npi = rosterDAO.retrieveProviderNPIFromRoster(organizationEntity.getId(), rosterEntity.getId(), patientEntity.getBeneficiaryID()); Assertions.assertTrue(npi.isPresent()); Assertions.assertEquals(providerEntity.getProviderNPI(), npi.get()); npi = rosterDAO.retrieveProviderNPIFromRoster(organizationEntity.getId(), UUID.randomUUID(), patientEntity.getBeneficiaryID()); Assertions.assertTrue(npi.isEmpty()); }