Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
168 lines
6.3 KiB
ABAP
168 lines
6.3 KiB
ABAP
CLASS {{p}}t_driving_check DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
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 rejects_unknown_pupil FOR TESTING.
|
|
METHODS rejects_missing_theory FOR TESTING.
|
|
METHODS rejects_too_few_lessons FOR TESTING.
|
|
METHODS rejects_unpaid_fee FOR TESTING.
|
|
METHODS rejects_recent_failure FOR TESTING.
|
|
METHODS accepts_ready_pupil FOR TESTING.
|
|
METHODS first_failure_wins FOR TESTING.
|
|
METHODS failure_14_days_ago_ok FOR TESTING.
|
|
METHODS lessons_12_ok FOR TESTING.
|
|
METHODS failure_13_days_rejected FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t_driving_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 rejects_unknown_pupil.
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P999' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'CX_PUPIL_UNKNOWN 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 rejects_missing_theory.
|
|
add_pupil( iv_id = 'P001' iv_theory = abap_false iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P001' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'CX_THEORY_MISSING 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 rejects_too_few_lessons.
|
|
add_pupil( iv_id = 'P002' iv_theory = abap_true iv_lessons = 9
|
|
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 = 'CX_LESSONS_MISSING 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 rejects_unpaid_fee.
|
|
add_pupil( iv_id = 'P003' iv_theory = abap_true iv_lessons = 18
|
|
iv_fee = abap_false iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P003' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'CX_FEE_UNPAID 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 rejects_recent_failure.
|
|
add_pupil( iv_id = 'P004' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '20250127' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P004' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'CX_RECENT_FAILURE 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.
|
|
|
|
METHOD accepts_ready_pupil.
|
|
add_pupil( iv_id = 'P005' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P005' iv_test_date = '20250201' ).
|
|
CATCH cx_root INTO DATA(lx_error).
|
|
cl_abap_unit_assert=>fail( msg = lx_error->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD first_failure_wins.
|
|
add_pupil( iv_id = 'P006' iv_theory = abap_false iv_lessons = 5
|
|
iv_fee = abap_false iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P006' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'CX_THEORY_MISSING 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 failure_14_days_ago_ok.
|
|
add_pupil( iv_id = 'P007' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '20250118' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P007' iv_test_date = '20250201' ).
|
|
CATCH cx_root INTO DATA(lx_error).
|
|
cl_abap_unit_assert=>fail( msg = lx_error->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD lessons_12_ok.
|
|
add_pupil( iv_id = 'P008' iv_theory = abap_true iv_lessons = 12
|
|
iv_fee = abap_true iv_last_failed = '00000000' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P008' iv_test_date = '20250201' ).
|
|
CATCH cx_root INTO DATA(lx_error).
|
|
cl_abap_unit_assert=>fail( msg = lx_error->get_text( ) ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD failure_13_days_rejected.
|
|
add_pupil( iv_id = 'P009' iv_theory = abap_true iv_lessons = 20
|
|
iv_fee = abap_true iv_last_failed = '20250119' ).
|
|
TRY.
|
|
mo_cut->check( iv_pupil_id = 'P009' iv_test_date = '20250201' ).
|
|
cl_abap_unit_assert=>fail( msg = 'CX_RECENT_FAILURE expected' ).
|
|
CATCH {{p}}cx_recent_failure INTO DATA(lx_recent).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 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.
|