### Question:
VMDAOJpa implements VMDAO { @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public VM getVMWithProviderVMId(String proivderVMId, String providerId) { Query query = entityManager.createQuery("SELECT v FROM VM v " + "WHERE v.providerId = :providerId " + "AND v.providerVmId = :providerVmId "); query.setParameter("providerId", providerId); query.setParameter("providerVmId", proivderVMId); List<VM> vms = (List<VM>) query.getResultList(); if(vms == null || vms.size() < 1) return null; return vms.get(0); }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) VM getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<VM> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(VM vm); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(VM vm); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(VM vm); @Override @SuppressWarnings("unchecked") List<VM> getNotDeletedVMsWithImage(Image image); @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) VM getVMWithProviderVMId(String proivderVMId, String providerId); @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<VM> getVMsWithOVfIdForDeploymentNotDeleted(String ovfId, int deploymentId); @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<VM> getVMsWithOvfIdAndActive(int deploymentId, String ovfId);  }### Answer:
@Test public void getVMWithProviderVMIdTest() { int sizeDeployments = deploymentDAO.getAll().size(); Deployment deployment = new Deployment(); deployment.setStatus("PEPITO"); deploymentDAO.save(deployment); deployment = deploymentDAO.getAll().get(sizeDeployments); int sizeVMs = vmDAO.getAll().size(); VM vm1 = new VM(); vm1.setProviderId("1"); vm1.setProviderVmId("1212"); deployment.addVM(vm1); vm1.setDeployment(deployment); vmDAO.save(vm1); vm1 = vmDAO.getAll().get(sizeVMs); deploymentDAO.update(deployment); VM vm2 = new VM(); vm2.setProviderId("2"); vm2.setProviderVmId("11212"); deployment.addVM(vm2); vm2.setDeployment(deployment); vmDAO.save(vm2); vm2 = vmDAO.getAll().get(sizeVMs + 1); deploymentDAO.update(deployment); assertEquals(vm1, vmDAO.getVMWithProviderVMId("1212", "1")); assertEquals(vmDAO.getVMWithProviderVMId("1212", "1").getDeployment().getId(), deployment.getId()); assertEquals(vm2, vmDAO.getVMWithProviderVMId("11212", "2")); assertEquals(vmDAO.getVMWithProviderVMId("11212", "2").getDeployment().getId(), deployment.getId()); assertEquals(null, vmDAO.getVMWithProviderVMId("112212", "22")); }