Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
118 lines
4.2 KiB
ABAP
118 lines
4.2 KiB
ABAP
CLASS ltc_driving_test_check DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
DATA mo_cut TYPE REF TO {{p}}driving_test_check.
|
|
DATA mo_env TYPE REF TO if_osql_test_environment.
|
|
METHODS setup.
|
|
METHODS teardown.
|
|
METHODS add_pupil
|
|
IMPORTING iv_id TYPE string
|
|
iv_theory TYPE abap_bool
|
|
iv_lessons TYPE i
|
|
iv_fee TYPE abap_bool
|
|
iv_last_failed TYPE d.
|
|
METHODS ready_pupil_passes FOR TESTING.
|
|
METHODS unknown_pupil_raises FOR TESTING.
|
|
METHODS missing_theory_raises FOR TESTING.
|
|
METHODS few_lessons_raise FOR TESTING.
|
|
METHODS unpaid_fee_raises FOR TESTING.
|
|
METHODS recent_failure_raises FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS ltc_driving_test_check IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_env = cl_osql_test_environment=>create( VALUE #( ( '{{P}}PUPIL' ) ) ).
|
|
mo_cut = NEW {{p}}driving_test_check( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD teardown.
|
|
mo_env->destroy( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD add_pupil.
|
|
DATA ls_pupil TYPE {{p}}pupil.
|
|
ls_pupil-client = sy-mandt.
|
|
ls_pupil-pupil_id = iv_id.
|
|
ls_pupil-pupil_name = iv_id.
|
|
IF iv_theory = abap_true.
|
|
ls_pupil-theory_done = 'X'.
|
|
ENDIF.
|
|
ls_pupil-lessons_done = iv_lessons.
|
|
IF iv_fee = abap_true.
|
|
ls_pupil-fee_paid = 'X'.
|
|
ENDIF.
|
|
ls_pupil-last_failed = iv_last_failed.
|
|
INSERT {{p}}pupil FROM @ls_pupil.
|
|
ENDMETHOD.
|
|
|
|
METHOD ready_pupil_passes.
|
|
add_pupil( iv_id = 'P001' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P001' iv_test_date = '20250201' ).
|
|
CATCH cx_root INTO DATA(lx_error).
|
|
cl_abap_unit_assert=>fail( msg = lx_error->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD unknown_pupil_raises.
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P999' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'exception expected' ).
|
|
CATCH {{p}}cx_pupil_unknown.
|
|
CATCH cx_root INTO DATA(lx_wrong).
|
|
cl_abap_unit_assert=>fail( msg = lx_wrong->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD missing_theory_raises.
|
|
add_pupil( iv_id = 'P002' iv_theory = abap_false iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P002' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'exception expected' ).
|
|
CATCH {{p}}cx_theory_missing.
|
|
CATCH cx_root INTO DATA(lx_wrong).
|
|
cl_abap_unit_assert=>fail( msg = lx_wrong->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD few_lessons_raise.
|
|
add_pupil( iv_id = 'P003' iv_theory = abap_true iv_lessons = 9
|
|
iv_fee = abap_true iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P003' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'exception expected' ).
|
|
CATCH {{p}}cx_lessons_missing INTO DATA(lx_lessons).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = lx_lessons->mv_missing ).
|
|
CATCH cx_root INTO DATA(lx_wrong).
|
|
cl_abap_unit_assert=>fail( msg = lx_wrong->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD unpaid_fee_raises.
|
|
add_pupil( iv_id = 'P004' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_false iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P004' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'exception expected' ).
|
|
CATCH {{p}}cx_fee_unpaid.
|
|
CATCH cx_root INTO DATA(lx_wrong).
|
|
cl_abap_unit_assert=>fail( msg = lx_wrong->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD recent_failure_raises.
|
|
add_pupil( iv_id = 'P005' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '20250127' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P005' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'exception expected' ).
|
|
CATCH {{p}}cx_recent_failure INTO DATA(lx_recent).
|
|
cl_abap_unit_assert=>assert_equals( exp = 9 act = lx_recent->mv_days_left ).
|
|
CATCH cx_root INTO DATA(lx_wrong).
|
|
cl_abap_unit_assert=>fail( msg = lx_wrong->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
ENDCLASS.
|