<commit_before>package edu.northwestern.bioinformatics.studycalendar.web.schedule;

import edu.northwestern.bioinformatics.studycalendar.dao.ArmDao;
import edu.northwestern.bioinformatics.studycalendar.dao.ScheduledCalendarDao;
import edu.northwestern.bioinformatics.studycalendar.domain.Arm;
import edu.northwestern.bioinformatics.studycalendar.domain.Fixtures;
import edu.northwestern.bioinformatics.studycalendar.domain.ScheduledCalendar;
import edu.northwestern.bioinformatics.studycalendar.web.ControllerTestCase;
import static org.easymock.classextension.EasyMock.expect;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindingResult;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;

/**
 * @author <NAME>
 */
public class ScheduleNextArmControllerTest extends ControllerTestCase {
    private ArmDao armDao;
    private ScheduledCalendarDao scheduledCalendarDao;

    private ScheduleNextArmCommand command;
    private ScheduleNextArmController controller;

    protected void setUp() throws Exception {
        super.setUp();
        armDao = registerDaoMockFor(ArmDao.class);
        scheduledCalendarDao = registerDaoMockFor(ScheduledCalendarDao.class);

        command = registerMockFor(ScheduleNextArmCommand.class, ScheduleNextArmCommand.class.getMethod("schedule"));

        controller = new ScheduleNextArmController() {
            @Override protected Object getCommand(HttpServletRequest request) throws Exception {
                return command;
            }
        };
        controller.setArmDao(armDao);
        controller.setScheduledCalendarDao(scheduledCalendarDao);
    }
    
    public void testBindArm() throws Exception {
        int id = 44;
        Arm expectedArm = Fixtures.setId(id, Fixtures.createNamedInstance("Baker", Arm.class));
        expect(armDao.getById(id)).andReturn(expectedArm);
        request.addParameter("arm", Integer.toString(id));

        executeRequest();

        assertSame(expectedArm, command.getArm());
    }

    public void testBindCalendar() throws Exception {
        int id = 17;
        ScheduledCalendar expectedCalendar = Fixtures.setId(id, new ScheduledCalendar());
        expect(scheduledCalendarDao.getById(id)).andReturn(expectedCalendar);
        request.addParameter("calendar", Integer.toString(id));

        executeRequest();

        assertSame(expectedCalendar, command.getCalendar());
    }

    public void testBindDate() throws Exception {
        request.addParameter("startDate", "08/05/2003");

        executeRequest();

        assertDayOfDate(2003, Calendar.AUGUST, 5, command.getStartDate());
    }

    private void executeRequest() throws Exception {
        command.schedule();
        replayMocks();
        ModelAndView mv = controller.handleRequest(request, response);
        verifyMocks();

        BindingResult result = (BindingResult) mv.getModel().get(BindingResult.MODEL_KEY_PREFIX + "command");
        assertEquals("There were errors in the request: " + result.getAllErrors(), 0, result.getErrorCount());
    }
}<commit_msg>Test that scheduledArm is passed into the model<commit_after>package edu.northwestern.bioinformatics.studycalendar.web.schedule;

import edu.northwestern.bioinformatics.studycalendar.dao.ArmDao;
import edu.northwestern.bioinformatics.studycalendar.dao.ScheduledCalendarDao;
import edu.northwestern.bioinformatics.studycalendar.domain.Arm;
import edu.northwestern.bioinformatics.studycalendar.domain.Fixtures;
import edu.northwestern.bioinformatics.studycalendar.domain.ScheduledCalendar;
import edu.northwestern.bioinformatics.studycalendar.domain.ScheduledArm;
import edu.northwestern.bioinformatics.studycalendar.web.ControllerTestCase;
import static org.easymock.classextension.EasyMock.expect;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindingResult;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;

/**
 * @author <NAME>
 */
public class ScheduleNextArmControllerTest extends ControllerTestCase {
    private ArmDao armDao;
    private ScheduledCalendarDao scheduledCalendarDao;

    private ScheduleNextArmCommand command;
    private ScheduleNextArmController controller;
    private static final ScheduledArm SCHEDULED_ARM = new ScheduledArm();

    protected void setUp() throws Exception {
        super.setUp();
        armDao = registerDaoMockFor(ArmDao.class);
        scheduledCalendarDao = registerDaoMockFor(ScheduledCalendarDao.class);

        command = registerMockFor(ScheduleNextArmCommand.class, ScheduleNextArmCommand.class.getMethod("schedule"));

        controller = new ScheduleNextArmController() {
            @Override protected Object getCommand(HttpServletRequest request) throws Exception {
                return command;
            }
        };
        controller.setArmDao(armDao);
        controller.setScheduledCalendarDao(scheduledCalendarDao);
    }
    
    public void testBindArm() throws Exception {
        int id = 44;
        Arm expectedArm = Fixtures.setId(id, Fixtures.createNamedInstance("Baker", Arm.class));
        expect(armDao.getById(id)).andReturn(expectedArm);
        request.addParameter("arm", Integer.toString(id));

        executeRequest();

        assertSame(expectedArm, command.getArm());
    }

    public void testBindCalendar() throws Exception {
        int id = 17;
        ScheduledCalendar expectedCalendar = Fixtures.setId(id, new ScheduledCalendar());
        expect(scheduledCalendarDao.getById(id)).andReturn(expectedCalendar);
        request.addParameter("calendar", Integer.toString(id));

        executeRequest();

        assertSame(expectedCalendar, command.getCalendar());
    }

    public void testBindDate() throws Exception {
        request.addParameter("startDate", "08/05/2003");

        executeRequest();

        assertDayOfDate(2003, Calendar.AUGUST, 5, command.getStartDate());
    }

    public void testScheduledArmInModel() throws Exception {
        ModelAndView actual = executeRequest();
        assertTrue("Missing scheduledArm", actual.getModel().containsKey("scheduledArm"));
        assertSame(SCHEDULED_ARM, actual.getModel().get("scheduledArm"));
    }

    private ModelAndView executeRequest() throws Exception {
        expect(command.schedule()).andReturn(SCHEDULED_ARM);
        replayMocks();
        ModelAndView mv = controller.handleRequest(request, response);
        verifyMocks();

        BindingResult result = (BindingResult) mv.getModel().get(BindingResult.MODEL_KEY_PREFIX + "command");
        assertEquals("There were errors in the request: " + result.getAllErrors(), 0, result.getErrorCount());
        return mv;
    }
}
{'fraction_non_alphanumeric': 0.09621380846325167, 'fraction_numerical': 0.005345211581291759, 'mean_word_length': 4.083773584905661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3639428', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1736, 'n_words': 325}