Question
I need help creating a Junit test for the New patient portion. I need to test if duplicate patients are allowed or if it throws
I need help creating a Junit test for the New patient portion. I need to test if duplicate patients are allowed or if it throws an error like it should (i know as of right now it will allow duplicates but i am not sure how to test this wtihin Junit) package medical.com.medicalApplication.services;
import java.util.ArrayList; import java.util.Collections; import java.util.List;
import medical.com.medicalApplication.model.MedicalRecord; import medical.com.medicalApplication.model.Patient; /** * * This class uses a singleton pattern to mock a service instead of using dependency injection * * In addition, it stores data in memory only using Lists * */ public class MedicalRescordService { private static MedicalRescordService reference = new MedicalRescordService(); private List
public static MedicalRescordService getReference() { return reference; }
MedicalRescordService() { this.patients = new ArrayList
public boolean addPatient(String name, String id) { boolean patientAdded = !patients.stream() .anyMatch(patient -> patient.getId().equals(id)); if (patientAdded) { Patient newPatient = new Patient(name, id); patients.add(newPatient); medicalRecords.add(new MedicalRecord(newPatient)); } return patientAdded; } public MedicalRecord getMedicalRecord(String patientId) { return medicalRecords.stream() .filter(medicalRecord -> medicalRecord.getPatient().getId().equals(patientId)).findFirst().get(); }
public Patient getPatient(String patientId) { return patients.stream().filter(person -> person.getId().equals(patientId)) .findFirst().get(); }
public List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started