VmList { public static <T extends Vm> T getByIdAndUserId(List<T> vmList, int id, int userId) { for (T vm : vmList) { if (vm.getId() == id && vm.getUserId() == userId) { return vm; } } return null; }  static T getById(List<T> vmList, int id); static T getByIdAndUserId(List<T> vmList, int id, int userId);  }
@Test public void testGetVMByIdAndUserId() { assertNull(VmList.getByIdAndUserId(vmList, 0, 0)); assertNull(VmList.getByIdAndUserId(vmList, 1, 0)); assertNull(VmList.getByIdAndUserId(vmList, 0, 1)); assertNull(VmList.getByIdAndUserId(vmList, 1, 1)); Vm vm1 = new Vm(0, 0, 0, 1, 0, 0, 0, "", null); Vm vm2 = new Vm(1, 0, 0, 1, 0, 0, 0, "", null); Vm vm3 = new Vm(0, 1, 0, 2, 0, 0, 0, "", null); Vm vm4 = new Vm(1, 1, 0, 2, 0, 0, 0, "", null); vmList.add(vm1); vmList.add(vm2); vmList.add(vm3); vmList.add(vm4); assertSame(vm1, VmList.getByIdAndUserId(vmList, 0, 0)); assertSame(vm2, VmList.getByIdAndUserId(vmList, 1, 0)); assertSame(vm3, VmList.getByIdAndUserId(vmList, 0, 1)); assertSame(vm4, VmList.getByIdAndUserId(vmList, 1, 1)); }