Search in sources :

Example 1 with ProgramWorkflowDAO

use of org.openmrs.api.db.ProgramWorkflowDAO in project openmrs-core by openmrs.

the class ProgramWorkflowServiceUnitTest method getProgramByName_shouldReturnNullWhenThereIsNoProgramForGivenName.

@Test
public void getProgramByName_shouldReturnNullWhenThereIsNoProgramForGivenName() {
    ProgramWorkflowDAO mockDao = Mockito.mock(ProgramWorkflowDAO.class);
    List<Program> noProgramWithGivenName = new ArrayList<>();
    Mockito.stub(mockDao.getProgramsByName("A name", false)).toReturn(noProgramWithGivenName);
    Mockito.stub(mockDao.getProgramsByName("A name", true)).toReturn(noProgramWithGivenName);
    pws.setProgramWorkflowDAO(mockDao);
    Assert.assertNull(pws.getProgramByName("A name"));
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ArrayList(java.util.ArrayList) ProgramWorkflowDAO(org.openmrs.api.db.ProgramWorkflowDAO) Test(org.junit.Test)

Example 2 with ProgramWorkflowDAO

use of org.openmrs.api.db.ProgramWorkflowDAO in project openmrs-core by openmrs.

the class ProgramWorkflowServiceUnitTest method getProgramByName_shouldCallDaoGetProgramsByName.

@Test
public void getProgramByName_shouldCallDaoGetProgramsByName() {
    ProgramWorkflowDAO mockDao = Mockito.mock(ProgramWorkflowDAO.class);
    pws.setProgramWorkflowDAO(mockDao);
    pws.getProgramByName("A name");
    Mockito.verify(mockDao).getProgramsByName("A name", false);
    Mockito.verify(mockDao).getProgramsByName("A name", true);
}
Also used : ProgramWorkflowDAO(org.openmrs.api.db.ProgramWorkflowDAO) Test(org.junit.Test)

Example 3 with ProgramWorkflowDAO

use of org.openmrs.api.db.ProgramWorkflowDAO in project openmrs-core by openmrs.

the class ProgramWorkflowServiceUnitTest method getProgramByName_shouldFailWhenTwoProgramsFoundWithSameName.

@Test(expected = org.openmrs.api.ProgramNameDuplicatedException.class)
public void getProgramByName_shouldFailWhenTwoProgramsFoundWithSameName() {
    ProgramWorkflowDAO mockDao = Mockito.mock(ProgramWorkflowDAO.class);
    List<Program> programsWithGivenName = new ArrayList<>();
    Program program1 = new Program("A name");
    Program program2 = new Program("A name");
    programsWithGivenName.add(program1);
    programsWithGivenName.add(program2);
    Mockito.stub(mockDao.getProgramsByName("A name", false)).toReturn(programsWithGivenName);
    Mockito.stub(mockDao.getProgramsByName("A name", true)).toReturn(programsWithGivenName);
    pws.setProgramWorkflowDAO(mockDao);
    pws.getProgramByName("A name");
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ArrayList(java.util.ArrayList) ProgramWorkflowDAO(org.openmrs.api.db.ProgramWorkflowDAO) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ProgramWorkflowDAO (org.openmrs.api.db.ProgramWorkflowDAO)3 ArrayList (java.util.ArrayList)2 PatientProgram (org.openmrs.PatientProgram)2 Program (org.openmrs.Program)2