### Question:
VirtualImageConversionDAO extends DefaultDAOBase<Integer, VirtualImageConversion> { public boolean existDuplicatedConversion(final VirtualImageConversion conversion) { Criterion cri = Restrictions.and(sameImage(conversion), sameSourceFormat(conversion)); cri = Restrictions.and(cri, sameTargetFormat(conversion)); return existsAnyByCriterions(cri); } VirtualImageConversionDAO();  VirtualImageConversionDAO(final EntityManager entityManager); @SuppressWarnings("unchecked") List<VirtualImageConversion> compatilbeConversions(
        final VirtualMachineTemplate virtualImage, final HypervisorType hypervisorType); boolean isVirtualImageConverted(final Integer vImageId, final DiskFormatType format); @Deprecated // use selectConversion TODO delthis @SuppressWarnings("unchecked") VirtualImageConversion getUnbundledConversion(final VirtualMachineTemplate image,
        final DiskFormatType format); boolean isConverted(final VirtualMachineTemplate image, final DiskFormatType targetType); Collection<VirtualImageConversion> findByVirtualImage(
        final VirtualMachineTemplate virtualImage); Collection<VirtualImageConversion> findByVirtualImageConversionByNodeVirtualImage(
        final NodeVirtualImage nodeVirtualImage); String getDatacenterUUIDByVirtualImageConversionID(final Integer idVirtualImageConversion); boolean existDuplicatedConversion(final VirtualImageConversion conversion);  }### Answer:
@Test public void testExistsDuplicatedConversions() { VirtualMachineTemplate template = virtualImageGenerator.createUniqueInstance(); VirtualImageConversion imageConversion = eg().createInstance(template, DiskFormatType.VHD_FLAT, DiskFormatType.VMDK_FLAT); List<Object> entitiesToPersist = new ArrayList<Object>(); eg().addAuxiliaryEntitiesToPersist(imageConversion, entitiesToPersist); entitiesToPersist.add(imageConversion); ds().persistAll(entitiesToPersist.toArray()); VirtualImageConversionDAO dao = createDaoForRollbackTransaction(); assertTrue(dao.existDuplicatedConversion(imageConversion)); }
@Test public void testNotExistsDuplicatedConversionsDiferentTemplate() { VirtualMachineTemplate template = virtualImageGenerator.createUniqueInstance(); VirtualMachineTemplate template2 = virtualImageGenerator.createUniqueInstance(); VirtualImageConversion imageConversion = eg().createInstance(template, DiskFormatType.VHD_FLAT, DiskFormatType.VMDK_FLAT); VirtualImageConversion imageConversionNotDuplicated = eg().createInstance(template2, DiskFormatType.VHD_FLAT, DiskFormatType.VMDK_FLAT); List<Object> entitiesToPersist = new ArrayList<Object>(); eg().addAuxiliaryEntitiesToPersist(imageConversion, entitiesToPersist); eg().addAuxiliaryEntitiesToPersist(imageConversionNotDuplicated, entitiesToPersist); entitiesToPersist.add(imageConversion); ds().persistAll(entitiesToPersist.toArray()); VirtualImageConversionDAO dao = createDaoForRollbackTransaction(); assertFalse(dao.existDuplicatedConversion(imageConversionNotDuplicated)); }
@Test public void testNotExistsDuplicatedConversionsDiferentFormat() { VirtualMachineTemplate template = virtualImageGenerator.createUniqueInstance(); VirtualImageConversion imageConversion = eg().createInstance(template, DiskFormatType.VHD_FLAT, DiskFormatType.VMDK_FLAT); VirtualImageConversion imageConversionNotDuplicated = eg().createInstance(template, DiskFormatType.VDI_FLAT, DiskFormatType.VMDK_FLAT); List<Object> entitiesToPersist = new ArrayList<Object>(); eg().addAuxiliaryEntitiesToPersist(imageConversion, entitiesToPersist); entitiesToPersist.add(imageConversion); ds().persistAll(entitiesToPersist.toArray()); VirtualImageConversionDAO dao = createDaoForRollbackTransaction(); assertFalse(dao.existDuplicatedConversion(imageConversionNotDuplicated)); }