### Question:
VMDAOJpa implements VMDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public boolean delete(VM vm) { try { vm = entityManager.getReference(VM.class, vm.getId()); entityManager.remove(vm); entityManager.flush(); return true; } catch(EntityNotFoundException e) { logger.debug(e); return false; } }  @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 delete() { int size = vmDAO.getAll().size(); VM vm = new VM(); vm.setIp("127.0.0.1"); vm.setOvfId("ovf-id"); vm.setProviderId("provider-id"); vm.setProviderVmId("provider-vm-id"); vm.setSlaAgreement("sla-agreement"); vm.setStatus("RUNNING"); boolean saved = vmDAO.save(vm); assertTrue(saved); VM vmFromDatabase = vmDAO.getAll().get(size); int id = vmFromDatabase.getId(); boolean deleted = vmDAO.delete(vmFromDatabase); assertTrue(deleted); deleted = vmDAO.delete(vmFromDatabase); assertTrue(!deleted); vmFromDatabase = vmDAO.getById(id); assertEquals(null, vmFromDatabase); }