### Question:
RackDAO extends DefaultDAOBase<Integer, Rack> { public List<Machine> getRandomMachinesToStartFromRack(final Integer rackId, final Integer howMany) { if (howMany <= 0) { return new ArrayList<Machine>(); } Query q = getSession().createQuery(HQL_EMPTY_OFF_MACHINES_IN_RACK).setInteger("rackId", rackId); List<Machine> machines = q.setMaxResults(howMany).list(); return machines; } RackDAO();  RackDAO(final EntityManager entityManager); List<Rack> findRacks(final Datacenter datacenter); List<Rack> findRacks(final Datacenter datacenter, final String filter); List<Rack> findRacksWithHAEnabled(final Datacenter datacenter); boolean existsAnyWithDatacenterAndName(final Datacenter datacenter, final String name); boolean existsAnyOtherWithDatacenterAndName(final Rack rack, final String name); List<Integer> getRackIdByMinVLANCount(final int idDatacenter); Long getNumberOfDeployedVlanNetworks(final Integer rackId); Rack findByIds(final Integer datacenterId, final Integer rackId); List<Rack> findAllNotManagedRacksByDatacenter(final Integer datacenterId); List<Rack> findAllNotManagedRacksByDatacenter(final Integer datacenterId,
        final String filter); @SuppressWarnings("unchecked") List<Integer> findUsedVrdpPorts(final Rack rack); Integer getEmptyOffMachines(final Integer rackId); Integer getEmptyOnMachines(final Integer rackId); List<Machine> getRandomMachinesToStartFromRack(final Integer rackId,
        final Integer howMany); List<Machine> getRandomMachinesToShutDownFromRack(final Integer rackId,
        final Integer howMany); List<Machine> getAllMachinesToShutDownFromRack(final Integer rackId);  }### Answer:
@Test public void getRandomMachinesToPoweOnFromRack() { DatacenterGenerator generator = new DatacenterGenerator(getSeed()); UcsRackGenerator ucsRackGenerator = new UcsRackGenerator(getSeed()); MachineGenerator machineGenerator = new MachineGenerator(getSeed()); HypervisorGenerator hypervisorGenerator = new HypervisorGenerator(getSeed()); Datacenter datacenter = generator.createUniqueInstance(); UcsRack ucsRack = ucsRackGenerator.createInstance(datacenter); ds().persistAll(datacenter, ucsRack); for (int i = 0; i < 7; i++) { Machine machine = machineGenerator.createUniqueInstance(); machine.setState(MachineState.HALTED_FOR_SAVE); machine.setRack(ucsRack); machine.setBelongsToManagedRack(Boolean.TRUE); machine.setDatacenter(datacenter); Hypervisor visor = hypervisorGenerator.createUniqueInstance(); visor.setMachine(machine); ds().persistAll(machine, visor); } Machine machine = machineGenerator.createUniqueInstance(); machine.setState(MachineState.MANAGED); machine.setRack(ucsRack); machine.setBelongsToManagedRack(Boolean.TRUE); machine.setDatacenter(datacenter); Hypervisor visor = hypervisorGenerator.createUniqueInstance(); visor.setMachine(machine); ds().persistAll(machine, visor); List<Machine> machines = createDaoForRollbackTransaction().getRandomMachinesToStartFromRack(ucsRack.getId(), 4); Assert.assertEquals(machines.size(), 4); }