@Test
public void verifyEnrollmentIsNotSetWithProgramWithoutRegistrationAndMultipleProgramStageInstances()
        throws SQLException
{

    // crete a Program "without registration"
    Program programWithoutReg = createProgram( 'W' );
    programWithoutReg.setProgramType( ProgramType.WITHOUT_REGISTRATION );
    // add the program to the work context map
    Map<String, Program> programMap = new HashMap<>();
    programMap.put( programWithoutReg.getUid(), programWithoutReg );
    // make sure tha map is returned when invoking the mock work context
    when( workContext.getProgramsMap() ).thenReturn( programMap );
    ProgramInstance programInstance1 = new ProgramInstance();
    programInstance1.setUid( CodeGenerator.generateUid() );
    programInstance1.setId( 100L );
    ProgramInstance programInstance2 = new ProgramInstance();
    programInstance2.setUid( CodeGenerator.generateUid() );
    programInstance2.setId( 100L );
    when( workContext.getServiceDelegator().getJdbcTemplate() ).thenReturn( jdbcTemplate );
    //
    // simulate 2 records returned from query
    //
    when( mockResultSet.next() ).thenReturn( true ).thenReturn( true ).thenReturn( false );
    when( mockResultSet.getLong( "programinstanceid" ) ).thenReturn( programInstance1.getId(), programInstance2.getId() );
    when( mockResultSet.getString( "uid" ) ).thenReturn( programInstance1.getUid(), programInstance2.getUid() );
    // Mock jdbc call
    mockResultSetExtractor( mockResultSet );
    event.setProgram( programWithoutReg.getUid() );
    // method under test
    subject.process( event, workContext );
    assertThat( event.getEnrollment(), is( nullValue() ) );
    assertThat( sql.getValue(), is( "select pi.programinstanceid, pi.programid, pi.uid from programinstance pi where pi.programid = ? and pi.status = ?" ) );
}