@Test public void setorganstatus_valid_multiple_updates() { Client client = new Client("First", null, "Last", LocalDate.of(1970, 1, 1), 1); when(spyClientManager.getClientByID(anyInt())).thenReturn(Optional.of(client)); String[] inputs = {"-u", "1", "--liver", "--kidney"}; CommandLine.run(spySetOrganStatus, System.out, inputs); assertTrue(client.getOrganDonationStatus().get(Organ.LIVER)); assertTrue(client.getOrganDonationStatus().get(Organ.KIDNEY)); }
@Override public void run() { Optional<Client> client = manager.getClientByID(uid); if (!client.isPresent()) { outputStream.println("No client exists with that user ID"); return; } ModifyClientOrgansAction action = new ModifyClientOrgansAction(client.get(), manager); Map<Organ, Boolean> states = new EnumMap<>(Organ.class); states.put(Organ.LIVER, liver); states.put(Organ.KIDNEY, kidney); states.put(Organ.PANCREAS, pancreas); states.put(Organ.HEART, heart); states.put(Organ.LUNG, lung); states.put(Organ.INTESTINE, intestine); states.put(Organ.CORNEA, cornea); states.put(Organ.MIDDLE_EAR, middleear); states.put(Organ.SKIN, skin); states.put(Organ.BONE, bone); states.put(Organ.BONE_MARROW, bonemarrow); states.put(Organ.CONNECTIVE_TISSUE, connectivetissue); for (Map.Entry<Organ, Boolean> entry : states.entrySet()) { Organ organ = entry.getKey(); Boolean newState = entry.getValue(); Boolean currState = client.get().getOrganDonationStatus().get(organ); if (newState == null) { continue; } else if (newState && currState) { outputStream.println(organ + " is already registered for donation"); } else if (!newState && !currState) { outputStream.println(organ + " is already not registered for donation"); } else { try { action.addChange(organ, newState); } catch (OrganAlreadyRegisteredException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } } outputStream.println(invoker.execute(action)); }
SetOrganStatus implements Runnable { @Override public void run() { Optional<Client> client = manager.getClientByID(uid); if (!client.isPresent()) { outputStream.println("No client exists with that user ID"); return; } ModifyClientOrgansAction action = new ModifyClientOrgansAction(client.get(), manager); Map<Organ, Boolean> states = new EnumMap<>(Organ.class); states.put(Organ.LIVER, liver); states.put(Organ.KIDNEY, kidney); states.put(Organ.PANCREAS, pancreas); states.put(Organ.HEART, heart); states.put(Organ.LUNG, lung); states.put(Organ.INTESTINE, intestine); states.put(Organ.CORNEA, cornea); states.put(Organ.MIDDLE_EAR, middleear); states.put(Organ.SKIN, skin); states.put(Organ.BONE, bone); states.put(Organ.BONE_MARROW, bonemarrow); states.put(Organ.CONNECTIVE_TISSUE, connectivetissue); for (Map.Entry<Organ, Boolean> entry : states.entrySet()) { Organ organ = entry.getKey(); Boolean newState = entry.getValue(); Boolean currState = client.get().getOrganDonationStatus().get(organ); if (newState == null) { continue; } else if (newState && currState) { outputStream.println(organ + " is already registered for donation"); } else if (!newState && !currState) { outputStream.println(organ + " is already not registered for donation"); } else { try { action.addChange(organ, newState); } catch (OrganAlreadyRegisteredException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } } outputStream.println(invoker.execute(action)); } }
SetOrganStatus implements Runnable { @Override public void run() { Optional<Client> client = manager.getClientByID(uid); if (!client.isPresent()) { outputStream.println("No client exists with that user ID"); return; } ModifyClientOrgansAction action = new ModifyClientOrgansAction(client.get(), manager); Map<Organ, Boolean> states = new EnumMap<>(Organ.class); states.put(Organ.LIVER, liver); states.put(Organ.KIDNEY, kidney); states.put(Organ.PANCREAS, pancreas); states.put(Organ.HEART, heart); states.put(Organ.LUNG, lung); states.put(Organ.INTESTINE, intestine); states.put(Organ.CORNEA, cornea); states.put(Organ.MIDDLE_EAR, middleear); states.put(Organ.SKIN, skin); states.put(Organ.BONE, bone); states.put(Organ.BONE_MARROW, bonemarrow); states.put(Organ.CONNECTIVE_TISSUE, connectivetissue); for (Map.Entry<Organ, Boolean> entry : states.entrySet()) { Organ organ = entry.getKey(); Boolean newState = entry.getValue(); Boolean currState = client.get().getOrganDonationStatus().get(organ); if (newState == null) { continue; } else if (newState && currState) { outputStream.println(organ + " is already registered for donation"); } else if (!newState && !currState) { outputStream.println(organ + " is already not registered for donation"); } else { try { action.addChange(organ, newState); } catch (OrganAlreadyRegisteredException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } } outputStream.println(invoker.execute(action)); } SetOrganStatus(PrintStream outputStream, ActionInvoker invoker);  SetOrganStatus(ClientManager manager, ActionInvoker invoker); }
SetOrganStatus implements Runnable { @Override public void run() { Optional<Client> client = manager.getClientByID(uid); if (!client.isPresent()) { outputStream.println("No client exists with that user ID"); return; } ModifyClientOrgansAction action = new ModifyClientOrgansAction(client.get(), manager); Map<Organ, Boolean> states = new EnumMap<>(Organ.class); states.put(Organ.LIVER, liver); states.put(Organ.KIDNEY, kidney); states.put(Organ.PANCREAS, pancreas); states.put(Organ.HEART, heart); states.put(Organ.LUNG, lung); states.put(Organ.INTESTINE, intestine); states.put(Organ.CORNEA, cornea); states.put(Organ.MIDDLE_EAR, middleear); states.put(Organ.SKIN, skin); states.put(Organ.BONE, bone); states.put(Organ.BONE_MARROW, bonemarrow); states.put(Organ.CONNECTIVE_TISSUE, connectivetissue); for (Map.Entry<Organ, Boolean> entry : states.entrySet()) { Organ organ = entry.getKey(); Boolean newState = entry.getValue(); Boolean currState = client.get().getOrganDonationStatus().get(organ); if (newState == null) { continue; } else if (newState && currState) { outputStream.println(organ + " is already registered for donation"); } else if (!newState && !currState) { outputStream.println(organ + " is already not registered for donation"); } else { try { action.addChange(organ, newState); } catch (OrganAlreadyRegisteredException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } } outputStream.println(invoker.execute(action)); } SetOrganStatus(PrintStream outputStream, ActionInvoker invoker);  SetOrganStatus(ClientManager manager, ActionInvoker invoker); @Override void run(); }
SetOrganStatus implements Runnable { @Override public void run() { Optional<Client> client = manager.getClientByID(uid); if (!client.isPresent()) { outputStream.println("No client exists with that user ID"); return; } ModifyClientOrgansAction action = new ModifyClientOrgansAction(client.get(), manager); Map<Organ, Boolean> states = new EnumMap<>(Organ.class); states.put(Organ.LIVER, liver); states.put(Organ.KIDNEY, kidney); states.put(Organ.PANCREAS, pancreas); states.put(Organ.HEART, heart); states.put(Organ.LUNG, lung); states.put(Organ.INTESTINE, intestine); states.put(Organ.CORNEA, cornea); states.put(Organ.MIDDLE_EAR, middleear); states.put(Organ.SKIN, skin); states.put(Organ.BONE, bone); states.put(Organ.BONE_MARROW, bonemarrow); states.put(Organ.CONNECTIVE_TISSUE, connectivetissue); for (Map.Entry<Organ, Boolean> entry : states.entrySet()) { Organ organ = entry.getKey(); Boolean newState = entry.getValue(); Boolean currState = client.get().getOrganDonationStatus().get(organ); if (newState == null) { continue; } else if (newState && currState) { outputStream.println(organ + " is already registered for donation"); } else if (!newState && !currState) { outputStream.println(organ + " is already not registered for donation"); } else { try { action.addChange(organ, newState); } catch (OrganAlreadyRegisteredException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } } outputStream.println(invoker.execute(action)); } SetOrganStatus(PrintStream outputStream, ActionInvoker invoker);  SetOrganStatus(ClientManager manager, ActionInvoker invoker); @Override void run();  }