### Question:
ImageDAOJpa implements ImageDAO { @Override public Image getLastImageWithOvfId(String ovfId) { Query query = entityManager.createQuery("from Image where ovfId = :ovfIdentifier order by id desc").setMaxResults(1); query.setParameter("ovfIdentifier", ovfId); Image image = (Image) query.getSingleResult(); return image; }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Image getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Image> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Image image); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Image image); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Image image); @Override Image getLastImageWithOvfId(String ovfId); @Override Image getDemoCacheImage(String ovfId, String ovfHref); @Override @SuppressWarnings("unchecked") List<Image> getCacheImagesForApplication(Application application);  }### Answer:
@Test public void getLastImageWithOvfIdTest() { int size = imageDAO.getAll().size(); Image image1 = new Image(); image1.setOvfId("ovf-id"); image1.setProviderImageId("provider-image-id"); boolean saved = imageDAO.save(image1); assertTrue(saved); Image image2 = new Image(); image2.setOvfId("ovf-id"); image2.setProviderImageId("provider-image-id"); saved = imageDAO.save(image2); assertTrue(saved); Image image3 = new Image(); image3.setOvfId("ovf-id"); image3.setProviderImageId("provider-image-id"); saved = imageDAO.save(image3); assertTrue(saved); Image image3FromDatabase = imageDAO.getAll().get(size+2); int id3 = image3FromDatabase.getId(); image3FromDatabase = imageDAO.getLastImageWithOvfId("ovf-id"); assertEquals(id3, image3FromDatabase.getId()); }