### Question:
MachineDAO extends DefaultDAOBase<Integer, Machine> { public Machine findByIp(final Datacenter datacenter, final String ip) { Criteria crit = createCriteria(); crit.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor"); crit.add(sameDatacenter(datacenter)); crit.add(Restrictions.eq("hypervisor.ip", ip)); return (Machine) crit.uniqueResult(); } MachineDAO();  MachineDAO(final EntityManager entityManager); List<Machine> findMachines(final Datacenter datacenter); List<Machine> findRackMachines(final Rack rack); List<Machine> findRackMachines(final Rack rack, final String filter); List<Machine> findMachinesWithHAInProgress(); List<Machine> findRackEnabledForHAMachines(final Rack rack); List<Machine> findRackEnabledForHAMachinesInUcs(final UcsRack rack); boolean existsAnyWithDatacenterAndName(final Datacenter datacenter, final String name); boolean existsAnyOtherWithDatacenterAndName(final Machine machine, final String name); int deleteRackMachines(final Rack rack); List<Machine> findCandidateMachines(final Integer idRack,
        final Integer idVirtualDatacenter, final Long hdRequiredOnDatastore,
        final Enterprise enterprise); List<Machine> findCandidateMachines(final Integer idRack,
        final Integer idVirtualDatacenter, final Enterprise enterprise, final String datastoreUuid,
        final Integer originalHypervisorId); List<Machine> findReservedMachines(final Enterprise enterprise); Machine findReservedMachine(final Enterprise enterprise, final Integer machineId); void reserveMachine(final Machine machine, final Enterprise enterprise); void releaseMachine(final Machine machine); Machine findByIds(final Integer datacenterId, final Integer rackId,
        final Integer machineId); Machine findByIp(final Datacenter datacenter, final String ip); Set<Integer> findAllIds(); List<Integer> findAllIdsInDatacenters(final Datacenter... datacenters); Long getTotalUsedCores(); Long getTotalUsedCoresExceptMachine(final Machine machine);  }### Answer:
@Test public void test_findbyIP() { Hypervisor hypervisor = hypervisorGenerator.createUniqueInstance(); List<Object> entitiesToPersist = new ArrayList<Object>(); hypervisorGenerator.addAuxiliaryEntitiesToPersist(hypervisor, entitiesToPersist); persistAll(ds(), entitiesToPersist, hypervisor); Datacenter datacenter = hypervisor.getMachine().getDatacenter(); MachineDAO dao = createDaoForRollbackTransaction(); Machine result = dao.findByIp(datacenter, hypervisor.getIp()); assertNotNull(result); }
@Test public void test_findbyIP_notFound() { Hypervisor hypervisor = hypervisorGenerator.createUniqueInstance(); List<Object> entitiesToPersist = new ArrayList<Object>(); hypervisorGenerator.addAuxiliaryEntitiesToPersist(hypervisor, entitiesToPersist); persistAll(ds(), entitiesToPersist, hypervisor); Datacenter datacenter = hypervisor.getMachine().getDatacenter(); MachineDAO dao = createDaoForRollbackTransaction(); Machine result = dao.findByIp(datacenter, "NOT_EXISTING_IP"); assertNull(result); }