Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
105 lines
3.9 KiB
ABAP
105 lines
3.9 KiB
ABAP
CLASS ltc_presc_check DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
DATA mo_cut TYPE REF TO {{p}}prescription_check.
|
|
|
|
METHODS setup.
|
|
METHODS valid_prescription FOR TESTING.
|
|
METHODS empty_prescription FOR TESTING.
|
|
METHODS expired_prescription FOR TESTING.
|
|
METHODS unknown_drug FOR TESTING.
|
|
METHODS bad_quantity FOR TESTING.
|
|
METHODS bad_dose FOR TESTING.
|
|
METHODS duplicate_drug FOR TESTING.
|
|
METHODS message_of_empty FOR TESTING.
|
|
|
|
METHODS valid_item
|
|
RETURNING VALUE(rt_item) TYPE {{p}}prescription_check=>tt_item.
|
|
METHODS expect_reason
|
|
IMPORTING iv_reason TYPE {{p}}cx_presc_error=>ty_reason
|
|
it_item TYPE {{p}}prescription_check=>tt_item.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS ltc_presc_check IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}prescription_check( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD valid_item.
|
|
rt_item = VALUE #( ( drug_id = 'IBU400' quantity = 10 daily_dose = 1200 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD expect_reason.
|
|
DATA lv_raised TYPE abap_bool.
|
|
TRY.
|
|
mo_cut->validate( iv_issue_date = '20240101'
|
|
iv_valid_days = 30
|
|
iv_as_of_date = '20240110'
|
|
it_item = it_item ).
|
|
CATCH {{p}}cx_presc_error INTO DATA(lx_error).
|
|
lv_raised = abap_true.
|
|
cl_abap_unit_assert=>assert_equals( exp = iv_reason
|
|
act = lx_error->get_reason( ) ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_true( act = lv_raised ).
|
|
ENDMETHOD.
|
|
|
|
METHOD valid_prescription.
|
|
TRY.
|
|
mo_cut->validate( iv_issue_date = '20240101'
|
|
iv_valid_days = 30
|
|
iv_as_of_date = '20240110'
|
|
it_item = valid_item( ) ).
|
|
CATCH {{p}}cx_presc_error.
|
|
cl_abap_unit_assert=>fail( msg = 'Unexpected exception' ).
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD empty_prescription.
|
|
expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-empty
|
|
it_item = VALUE {{p}}prescription_check=>tt_item( ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD expired_prescription.
|
|
DATA lv_raised TYPE abap_bool.
|
|
TRY.
|
|
mo_cut->validate( iv_issue_date = '20240101'
|
|
iv_valid_days = 30
|
|
iv_as_of_date = '20240201'
|
|
it_item = valid_item( ) ).
|
|
CATCH {{p}}cx_presc_error INTO DATA(lx_error).
|
|
lv_raised = abap_true.
|
|
cl_abap_unit_assert=>assert_equals( exp = {{p}}cx_presc_error=>c_reason-expired
|
|
act = lx_error->get_reason( ) ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_true( act = lv_raised ).
|
|
ENDMETHOD.
|
|
|
|
METHOD unknown_drug.
|
|
expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-unknown
|
|
it_item = VALUE #( ( drug_id = 'NODRUG' quantity = 5 daily_dose = 10 ) ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD bad_quantity.
|
|
expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-quantity
|
|
it_item = VALUE #( ( drug_id = 'IBU400' quantity = 0 daily_dose = 1200 ) ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD bad_dose.
|
|
expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-dose
|
|
it_item = VALUE #( ( drug_id = 'META50' quantity = 5 daily_dose = 500 ) ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD duplicate_drug.
|
|
expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-duplicate
|
|
it_item = VALUE #( ( drug_id = 'IBU400' quantity = 10 daily_dose = 1200 )
|
|
( drug_id = 'IBU400' quantity = 10 daily_dose = 1200 ) ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD message_of_empty.
|
|
DATA(lo_error) = NEW {{p}}cx_presc_error( iv_reason = {{p}}cx_presc_error=>c_reason-empty ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'The prescription has no items'
|
|
act = lo_error->get_message_text( ) ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|