Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am pretty confused about how to write the test case for this class: /** * * This class uses a singleton pattern to

Hi, I am pretty confused about how to write the test case for this class:

/** * * 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 DoctorService { private static DoctorService reference = new DoctorService(); private static List doctors; DoctorService(){ doctors = new ArrayList(); } public static DoctorService getReference(){ return reference; } public List getAllDoctors(){ return doctors; } public boolean addDoctor(String name, String id){ String tempId = new String(id); boolean createDoctor = !doctors.stream().anyMatch(doctor -> doctor.getId() == tempId); if (createDoctor) { doctors.add(new Doctor(name, id)); } return createDoctor; }

}

I want to test all the methods in a test class TestDoctorService (not altering the DoctorService class in any way) and I want to test if a doctor with the same id is entered if it will be rejected since doctors can have the same name but not the same id which is unique. Can you just help with an example of your own?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions