CLASS ltc_exam_check DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. CONSTANTS c_deadline TYPE d VALUE '20240331'. DATA mo_cut TYPE REF TO {{p}}exam_check. METHODS setup. METHODS ok_request RETURNING VALUE(rs_request) TYPE {{p}}if_exam_request=>ty_request. METHODS allowed FOR TESTING. METHODS not_enrolled FOR TESTING. METHODS prereq_missing FOR TESTING. METHODS no_attempt_left FOR TESTING. METHODS deadline_passed FOR TESTING. ENDCLASS. CLASS ltc_exam_check IMPLEMENTATION. METHOD setup. mo_cut = NEW {{p}}exam_check( iv_max_attempts = 3 iv_deadline = c_deadline ). ENDMETHOD. METHOD ok_request. rs_request = VALUE #( student_id = 'S4711' enrolled = abap_true prereq_passed = abap_true prereq_id = 'P100' attempts = 0 reg_date = CONV d( '20240115' ) ). ENDMETHOD. METHOD allowed. TRY. mo_cut->check( ok_request( ) ). CATCH {{p}}cx_exam_error. cl_abap_unit_assert=>fail( |The registration must be allowed| ). ENDTRY. ENDMETHOD. METHOD not_enrolled. DATA(ls_request) = ok_request( ). ls_request-enrolled = abap_false. TRY. mo_cut->check( ls_request ). cl_abap_unit_assert=>fail( |Exception expected| ). CATCH {{p}}cx_not_enrolled INTO DATA(lo_error). cl_abap_unit_assert=>assert_equals( exp = 'S4711' act = lo_error->mv_student_id ). CATCH {{p}}cx_exam_error. cl_abap_unit_assert=>fail( |Wrong exception type| ). ENDTRY. ENDMETHOD. METHOD prereq_missing. DATA(ls_request) = ok_request( ). ls_request-prereq_passed = abap_false. TRY. mo_cut->check( ls_request ). cl_abap_unit_assert=>fail( |Exception expected| ). CATCH {{p}}cx_prereq_missing INTO DATA(lo_error). cl_abap_unit_assert=>assert_equals( exp = 'P100' act = lo_error->mv_prereq ). CATCH {{p}}cx_exam_error. cl_abap_unit_assert=>fail( |Wrong exception type| ). ENDTRY. ENDMETHOD. METHOD no_attempt_left. DATA(ls_request) = ok_request( ). ls_request-attempts = 3. TRY. mo_cut->check( ls_request ). cl_abap_unit_assert=>fail( |Exception expected| ). CATCH {{p}}cx_no_attempt_left INTO DATA(lo_error). cl_abap_unit_assert=>assert_equals( exp = 3 act = lo_error->mv_attempts ). CATCH {{p}}cx_exam_error. cl_abap_unit_assert=>fail( |Wrong exception type| ). ENDTRY. ENDMETHOD. METHOD deadline_passed. DATA(ls_request) = ok_request( ). ls_request-reg_date = CONV d( '20240401' ). TRY. mo_cut->check( ls_request ). cl_abap_unit_assert=>fail( |Exception expected| ). CATCH {{p}}cx_deadline_passed INTO DATA(lo_error). cl_abap_unit_assert=>assert_equals( exp = CONV d( '20240401' ) act = lo_error->mv_reg_date ). CATCH {{p}}cx_exam_error. cl_abap_unit_assert=>fail( |Wrong exception type| ). ENDTRY. ENDMETHOD. ENDCLASS.