Question: Hi i need help implementing the proper code for a JUnit test within my code for eclipse oxygen: package medical.com.medicalApplication.model; import static org.junit.Assert.*; import java.util.ArrayList;

Hi i need help implementing the proper code for a JUnit test within my code for eclipse oxygen:

package medical.com.medicalApplication.model;

import static org.junit.Assert.*;

import java.util.ArrayList; import java.util.Collections; import java.util.List;

import org.junit.Test;

import medical.com.medicalApplication.services.MedicalRescordService;

public class TestMedicalRescordService {

public class MedicalRescordService { private static MedicalRescordService reference = new MedicalRescordService(); private List patients; private List medicalRecords;

public static MedicalRescordService getReference() { return reference; }

MedicalRescordService() { this.patients = new ArrayList(); this.medicalRecords = 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 getAllPatients() { return patients; } public List getPatientsWithAllergies(String allergyName){ for(Patient patient : getAllPatients()){ if(getMedicalRecord(patient.getId()).getHistory().getAlergies().stream().filter(allergy -> allergy.getName().equals(allergyName)).findFirst().get() != null){ return Collections.singletonList(patient); } } return Collections.emptyList(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!