From 920ac251ddb2be09420d171242443b13622bc28f Mon Sep 17 00:00:00 2001
From: Matthew Williams <mattwilliams1515@gmail.com>
Date: Thu, 19 Nov 2020 07:29:58 -0600
Subject: [PATCH] Fix tests and simplify actions

---
 .../ViewPreRegisteredPatientListAction.java   | 43 +++++--------------
 ...iewPreRegisteredPatientListActionTest.java |  8 ++--
 .../unit/dao/patient/ActivatePatientTest.java |  2 +-
 3 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/ViewPreRegisteredPatientListAction.java b/iTrust/src/edu/ncsu/csc/itrust/action/ViewPreRegisteredPatientListAction.java
index 13bdd58..135469b 100644
--- a/iTrust/src/edu/ncsu/csc/itrust/action/ViewPreRegisteredPatientListAction.java
+++ b/iTrust/src/edu/ncsu/csc/itrust/action/ViewPreRegisteredPatientListAction.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Scanner;
 
+import edu.ncsu.csc.itrust.Messages;
 import edu.ncsu.csc.itrust.beans.OfficeVisitBean;
 import edu.ncsu.csc.itrust.beans.PatientBean;
 import edu.ncsu.csc.itrust.beans.PatientVisitBean;
@@ -23,18 +24,16 @@ import edu.ncsu.csc.itrust.exception.ITrustException;
 public class ViewPreRegisteredPatientListAction {
 	private long loggedInMID;
 	private PatientDAO patientDAO;
-	private ArrayList<PatientBean> PreRegisteredPatients;
+	private List<PatientBean> PreRegisteredPatients;
 
 	/**
 	 * Set up defaults
 	 * @param factory The DAOFactory used to create the DAOs used in this action.
 	 * @param loggedInMID The MID of the person viewing the office visits.
 	 */
-	public ViewPreRegisteredPatientListAction(DAOFactory factory, long loggedInMID) {
+	public ViewPreRegisteredPatientListAction(DAOFactory factory) {
 	
 		this.patientDAO = factory.getPatientDAO();
-	
-		PreRegisteredPatients = new ArrayList<PatientBean>();
 		
 	}
 	
@@ -43,38 +42,18 @@ public class ViewPreRegisteredPatientListAction {
 	 * 
 	 * @throws ITrustException
 	 */
-	private void getPreRegisteredFromPatientsTable() throws ITrustException {
+	public List<PatientBean> getPreRegisteredPatients() throws ITrustException {
 		try {
-		
-			List<PatientBean> plist = patientDAO.getAllPreRegisteredPatients();
 
-			
-			for(PatientBean pb : plist) {
-                
-				PreRegisteredPatients.add(pb);
+			PreRegisteredPatients = patientDAO.getAllPreRegisteredPatients();
+			if (PreRegisteredPatients != null) {
+				return PreRegisteredPatients;
+			} else {
+				throw new ITrustException("getAllPreRegisteredPatients() has returned null");
 			}
-		}
-		catch (DBException dbe) {
+
+		} catch (DBException dbe) {
 			throw new ITrustException(dbe.getMessage());
 		}
 	}
-	
-/**
- * Get the list of patients an HCP has had office visits with
- * 
- * @return the list of patients an HCP has had office visits with
- * @throws DBException
- */
-	public List<PatientBean> getPreRegisteredPatients() throws DBException {
-		
-		try {
-			getPreRegisteredFromPatientsTable();
-			
-		}
-		catch (ITrustException ie) {
-			//TODO
-		}
-
-		return PreRegisteredPatients;
-	}
 }
diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewPreRegisteredPatientListActionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewPreRegisteredPatientListActionTest.java
index 3c12d87..839bff1 100644
--- a/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewPreRegisteredPatientListActionTest.java
+++ b/iTrust/test/edu/ncsu/csc/itrust/unit/action/ViewPreRegisteredPatientListActionTest.java
@@ -1,13 +1,15 @@
 package edu.ncsu.csc.itrust.unit.action;
 
 import junit.framework.TestCase;
-import edu.ncsu.csc.itrust.action.ViewPersonnelAction;
+import edu.ncsu.csc.itrust.action.ViewPreRegisteredPatientListAction;
 import edu.ncsu.csc.itrust.beans.PatientBean;
 import edu.ncsu.csc.itrust.dao.DAOFactory;
 import edu.ncsu.csc.itrust.exception.ITrustException;
 import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator;
 import edu.ncsu.csc.itrust.unit.testutils.TestDAOFactory;
 
+import java.util.List;
+
 public class ViewPreRegisteredPatientListActionTest extends TestCase {
 
 	private DAOFactory factory = TestDAOFactory.getTestInstance();
@@ -25,14 +27,14 @@ public class ViewPreRegisteredPatientListActionTest extends TestCase {
     public void testViewPatients() throws Exception {
         action = new ViewPreRegisteredPatientListAction(factory);
         List<PatientBean> pb = action.getPreRegisteredPatients();
-        assertEquals(pb.get(0) == 4);
+        assertEquals(pb.get(0).getMID(), 4);
     }
 
 	public void testNoPersonnel() throws Exception {
 		action = new ViewPreRegisteredPatientListAction(factory);
         List<PatientBean> pb = action.getPreRegisteredPatients();
         for (PatientBean p : pb) {
-            if (p.id() == "90000000") {
+            if (p.getMID() == 90000000) {
                 fail("This id should not exist in the list");
             }
         }
diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/dao/patient/ActivatePatientTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/dao/patient/ActivatePatientTest.java
index ecb61d5..645511d 100644
--- a/iTrust/test/edu/ncsu/csc/itrust/unit/dao/patient/ActivatePatientTest.java
+++ b/iTrust/test/edu/ncsu/csc/itrust/unit/dao/patient/ActivatePatientTest.java
@@ -24,7 +24,7 @@ public class ActivatePatientTest extends TestCase {
 	public void testActivateNewPatient() throws Exception {
 		long pid = patientDAO.addEmptyPatient();
 		assertEquals("PreRegisteredPatient", patientDAO.getRole(pid));
-		activatePatient(pid);
+		patientDAO.activatePatient(pid);
 		assertEquals("patient", patientDAO.getRole(pid));
 	}
 }
-- 
GitLab