### Question:
MachineDAO extends DefaultDAOBase<Integer, Machine> { public Long getTotalUsedCoresExceptMachine(final Machine machine) { Query query = getSession().createQuery(QUERY_USED_CORES_EXCEPT_MACHINE); query.setInteger("id", machine.getId()); Long result = (Long) query.uniqueResult(); return result == null ? 0L : result; } 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 testGetTotalUsedCoresExceptMachine() { DatacenterGenerator datacenterGenerator = new DatacenterGenerator(getSeed()); RackGenerator rackGenerator = new RackGenerator(getSeed()); MachineGenerator machineGenerator = new MachineGenerator(getSeed()); Datacenter datacenter = datacenterGenerator.createUniqueInstance(); Rack rack = rackGenerator.createInstance(datacenter); Machine machine1 = machineGenerator.createMachine(datacenter, rack); Machine machine2 = machineGenerator.createMachine(datacenter, rack); machine1.setVirtualCpuCores(5); machine2.setVirtualCpuCores(7); ds().persistAll(datacenter, rack, machine1, machine2); MachineDAO dao = createDaoForRollbackTransaction(); Long totalCores = dao.getTotalUsedCoresExceptMachine(machine2); assertEquals(totalCores.longValue(), machine1.getVirtualCpuCores().longValue()); }
@Test public void testGetTotalUsedCoresExceptMachineWithoutOthers() { DatacenterGenerator datacenterGenerator = new DatacenterGenerator(getSeed()); RackGenerator rackGenerator = new RackGenerator(getSeed()); MachineGenerator machineGenerator = new MachineGenerator(getSeed()); Datacenter datacenter = datacenterGenerator.createUniqueInstance(); Rack rack = rackGenerator.createInstance(datacenter); Machine machine1 = machineGenerator.createMachine(datacenter, rack); machine1.setVirtualCpuCores(5); ds().persistAll(datacenter, rack, machine1); MachineDAO dao = createDaoForRollbackTransaction(); Long totalCores = dao.getTotalUsedCoresExceptMachine(machine1); assertEquals(totalCores.longValue(), 0L); }