Source:
public void testExecute_withNumberOfStudentsMoreThanSectionLimit_shouldThrowInvalidHttpRequestBodyException() { String courseId = typicalBundle.students.get("student1InCourse1").getCourse(); String randomSectionName = "randomSectionName"; List<StudentAttributes> studentList = new ArrayList<>(); for (int i = 0; i < Const.StudentsLogicConst.SECTION_SIZE_LIMIT; i++) { StudentAttributes addedStudent = StudentAttributes .builder(courseId, i + "email@test.com") .withName("Name " + i) .withSectionName(randomSectionName) .withTeamName("Team " + i) .withComment("cmt" + i) .build(); studentList.add(addedStudent); } String[] params = new String[] { Const.ParamsNames.COURSE_ID, courseId, }; StudentsEnrollRequest req = prepareRequest(studentList); getAction(req, params).execute(); StudentAttributes oneMoreStudentToGoBeyondLimit = StudentAttributes .builder(courseId, "email@test.com") .withName("Name") .withSectionName(randomSectionName) .withTeamName("Team") .withComment("cmt") .build(); req = prepareRequest(Collections.singletonList(oneMoreStudentToGoBeyondLimit)); EnrollStudentsAction action = getAction(req, params); InvalidHttpRequestBodyException ee = assertThrows(InvalidHttpRequestBodyException.class, action::execute); String expectedErrorMessage = String.format( Const.StudentsLogicConst.ERROR_ENROLL_EXCEED_SECTION_LIMIT, Const.StudentsLogicConst.SECTION_SIZE_LIMIT, randomSectionName) + " " + String.format(Const.StudentsLogicConst.ERROR_ENROLL_EXCEED_SECTION_LIMIT_INSTRUCTION, Const.StudentsLogicConst.SECTION_SIZE_LIMIT); assertEquals(expectedErrorMessage, ee.getMessage()); }

Target:
public void testExecute_withNumberOfStudentsMoreThanSectionLimit_shouldThrowInvalidHttpRequestBodyException() { String courseId = typicalBundle.students.get("student1InCourse1").getCourse(); String randomSectionName = "randomSectionName"; List<StudentAttributes> studentList = new ArrayList<>(); for (int i = 0; i < Const.StudentsLogicConst.SECTION_SIZE_LIMIT; i++) { StudentAttributes addedStudent = StudentAttributes .builder(courseId, i + "email@test.com") .withName("Name " + i) .withSectionName(randomSectionName) .withTeamName("Team " + i) .withComment("cmt" + i) .build(); studentList.add(addedStudent); } String[] params = new String[] { Const.ParamsNames.COURSE_ID, courseId, }; StudentsEnrollRequest req = prepareRequest(studentList); getAction(req, params).execute(); StudentAttributes oneMoreStudentToGoBeyondLimit = StudentAttributes .builder(courseId, "email@test.com") .withName("Name") .withSectionName(randomSectionName) .withTeamName("Team") .withComment("cmt") .build(); req = prepareRequest(Arrays.asList(oneMoreStudentToGoBeyondLimit)); EnrollStudentsAction action = getAction(req, params); InvalidHttpRequestBodyException ee = assertThrows(InvalidHttpRequestBodyException.class, () -> action.execute()); String expectedErrorMessage = String.format( Const.StudentsLogicConst.ERROR_ENROLL_EXCEED_SECTION_LIMIT, Const.StudentsLogicConst.SECTION_SIZE_LIMIT, randomSectionName) + " " + String.format(Const.StudentsLogicConst.ERROR_ENROLL_EXCEED_SECTION_LIMIT_INSTRUCTION, Const.StudentsLogicConst.SECTION_SIZE_LIMIT); assertEquals(expectedErrorMessage, ee.getMessage()); }