### Question:
VirtualMachineDAO extends DefaultDAOBase<Integer, VirtualMachine> { public List<VirtualMachine> findVirtualMachinesNotAllocatedCompatibleHypervisor( final Hypervisor hypervisor) { Criteria criteria = createCriteria(); criteria.createAlias(VirtualMachine.VIRTUAL_MACHINE_TEMPLATE_PROPERTY, "template"); Restrictions.and(Restrictions.eq(VirtualMachine.HYPERVISOR_PROPERTY, null), Restrictions .in("template." + VirtualMachineTemplate.DISKFORMAT_TYPE_PROPERTY, Arrays .asList(hypervisor.getType().compatibleFormats))); criteria.addOrder(Order.asc(VirtualMachine.NAME_PROPERTY)); List<VirtualMachine> result = getResultList(criteria); return result; } VirtualMachineDAO();  VirtualMachineDAO(final EntityManager entityManager); List<VirtualMachine> getNotManagedVirtualMachines(final Hypervisor hypervisor); boolean existsAnyWithName(final String name); VirtualMachine findByIdByVirtualApp(final VirtualAppliance vapp, final Integer vmId); VirtualMachine findByName(final String name); VirtualMachine findByUUID(final String uuid); List<VirtualMachine> findManagedVirtualMachines(final Hypervisor hypervisor); VirtualMachine findVirtualMachineByHypervisor(final Hypervisor hypervisor,
        final Integer virtualMachineId); List<VirtualMachine> findVirtualMachines(final Hypervisor hypervisor); List<VirtualMachine> findVirtualMachinesNotAllocatedCompatibleHypervisor(
        final Hypervisor hypervisor); List<VirtualMachine> findVirtualMachinesByDatacenter(final Integer datacenterId); List<VirtualMachine> findVirtualMachinesByEnterprise(final Enterprise enterprise); List<VirtualMachine> findVirtualMachinesByUser(final Enterprise enterprise,
        final User user); List<VirtualMachine> findVirtualMachinesByVirtualAppliance(final Integer vappId,
        Integer startwith, Integer limit, final String filter, final OrderByEnum orderby,
        final boolean asc); List<VirtualMachine> findByVirtualMachineTemplate(final Integer virtualMachineTemplateId); boolean hasVirtualMachineTemplate(final Integer virtualMachineTemplateId); void updateVirtualMachineState(final Integer vmachineId, final VirtualMachineState state); void unknownState(final Integer vmachineId); VirtualMachine findBackup(final VirtualMachine vmachine); void refreshLock(final VirtualMachine vm); void refresh(final VirtualMachine vm); void detachHypervisor(final VirtualMachine vm); void detachVirtualMachine(final VirtualMachine vm); void deleteNotManagedVirtualMachines(final Hypervisor hypervisor); static final String BY_VAPP_AND_ID; }### Answer:
@Test public void findVirtualMachinesNotAllocatedCompatibleHypervisor() { VirtualMachine vm = eg().createUniqueInstance(); Hypervisor hyp = vm.getHypervisor(); vm.setHypervisor(null); vm.setState(VirtualMachineState.NOT_ALLOCATED); List<Object> vmlist = new ArrayList<Object>(); eg().addAuxiliaryEntitiesToPersist(vm, vmlist); vmlist.add(vm); ds().persistAll(vmlist.toArray()); VirtualMachineDAO dao = createDaoForRollbackTransaction(); List<VirtualMachine> vms = dao.findVirtualMachinesNotAllocatedCompatibleHypervisor(hyp); assertEquals(vms.size(), 1); }