volunteer.setIdContact(TEST_ID);
volunteer.setFirstName(getName());
volunteer.setLastName(getName());
volunteer.setTypeVolunteer("Potential");
VolunteerApplication application = new VolunteerApplication();
application.setIdApplication(TEST_ID);
//obtain a program
ProgramController pc = new ProgramController();
Program aProgram = pc.getPrograms().get(0);
application.setProgram(aProgram);
VolunteerController instance = new VolunteerController();
Volunteer result = instance.addApplication(volunteer, application, null);
assertNotNull(result);
assertEquals(volunteer, result);
assertEquals(application, result.getApplication());
assertEquals(aProgram, result.getApplication().getProgram());
aProgram = pc.read(aProgram.getIdProgram());
List<VolunteerApplication> theApplications =
new ArrayList<VolunteerApplication> (aProgram.getApplications());
assertTrue("Cannot find the inserted application in the program", theApplications.contains(application));
//Check the application
VolunteerApplicationController vac = new VolunteerApplicationController ();
application = vac.read(application.getIdApplication());
assertEquals(volunteer, application.getVolunteer());
// Change the program
Program anotherProgram = pc.getPrograms().get(1);
application.setProgram(anotherProgram);
volunteer = instance.addApplication(volunteer, application, aProgram);
aProgram = pc.read(aProgram.getIdProgram());
theApplications =
new ArrayList<VolunteerApplication> (aProgram.getApplications());
assertFalse("Find the stale application in the previous program", theApplications.contains(application));