CLASS {{p}}t02_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. DATA mo_cut TYPE REF TO {{p}}prescription_check. METHODS setup. METHODS empty_prescription FOR TESTING. METHODS expired_prescription FOR TESTING. METHODS valid_on_last_day FOR TESTING. METHODS unknown_drug FOR TESTING. METHODS zero_quantity FOR TESTING. METHODS zero_daily_dose FOR TESTING. METHODS dose_above_max FOR TESTING. METHODS duplicate_drug FOR TESTING. METHODS expired_before_quantity FOR TESTING. METHODS dose_before_duplicate FOR TESTING. METHODS valid_prescription FOR TESTING. METHODS message_texts 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 iv_as_of TYPE d DEFAULT '20240110'. METHODS expect_no_error IMPORTING it_item TYPE {{p}}prescription_check=>tt_item iv_as_of TYPE d DEFAULT '20240110'. ENDCLASS. CLASS {{p}}t02_hidden IMPLEMENTATION. METHOD setup. mo_cut = NEW {{p}}prescription_check( ). ENDMETHOD. METHOD valid_item. rt_item = VALUE #( ( drug_id = 'PARA500' quantity = 20 daily_dose = 1000 ) ). 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 = iv_as_of 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 msg = |No exception with reason { iv_reason }| ). ENDMETHOD. METHOD expect_no_error. DATA lv_raised TYPE abap_bool. TRY. mo_cut->validate( iv_issue_date = '20240101' iv_valid_days = 30 iv_as_of_date = iv_as_of it_item = it_item ). CATCH {{p}}cx_presc_error. lv_raised = abap_true. ENDTRY. cl_abap_unit_assert=>assert_false( act = lv_raised ). 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. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-expired it_item = valid_item( ) iv_as_of = '20240201' ). ENDMETHOD. METHOD valid_on_last_day. expect_no_error( it_item = valid_item( ) iv_as_of = '20240131' ). ENDMETHOD. METHOD unknown_drug. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-unknown it_item = VALUE #( ( drug_id = 'XXXXXX' quantity = 5 daily_dose = 10 ) ) ). ENDMETHOD. METHOD zero_quantity. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-quantity it_item = VALUE #( ( drug_id = 'PARA500' quantity = 0 daily_dose = 1000 ) ) ). ENDMETHOD. METHOD zero_daily_dose. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-dose it_item = VALUE #( ( drug_id = 'PARA500' quantity = 5 daily_dose = 0 ) ) ). ENDMETHOD. METHOD dose_above_max. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-dose it_item = VALUE #( ( drug_id = 'META50' quantity = 5 daily_dose = 250 ) ) ). ENDMETHOD. METHOD duplicate_drug. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-duplicate it_item = VALUE #( ( drug_id = 'PARA500' quantity = 5 daily_dose = 1000 ) ( drug_id = 'PARA500' quantity = 5 daily_dose = 1000 ) ) ). ENDMETHOD. METHOD expired_before_quantity. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-expired it_item = VALUE #( ( drug_id = 'PARA500' quantity = 0 daily_dose = 1000 ) ) iv_as_of = '20240201' ). ENDMETHOD. METHOD dose_before_duplicate. expect_reason( iv_reason = {{p}}cx_presc_error=>c_reason-dose it_item = VALUE #( ( drug_id = 'META50' quantity = 5 daily_dose = 250 ) ( drug_id = 'META50' quantity = 5 daily_dose = 100 ) ) ). ENDMETHOD. METHOD valid_prescription. expect_no_error( it_item = VALUE #( ( drug_id = 'PARA500' quantity = 20 daily_dose = 4000 ) ( drug_id = 'IBU400' quantity = 10 daily_dose = 1200 ) ) ). ENDMETHOD. METHOD message_texts. DATA lo_error TYPE REF TO {{p}}cx_presc_error. lo_error = NEW #( 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( ) ). lo_error = NEW #( iv_reason = {{p}}cx_presc_error=>c_reason-expired ). cl_abap_unit_assert=>assert_equals( exp = 'The prescription is expired' act = lo_error->get_message_text( ) ). lo_error = NEW #( iv_reason = {{p}}cx_presc_error=>c_reason-quantity ). cl_abap_unit_assert=>assert_equals( exp = 'The quantity is not positive' act = lo_error->get_message_text( ) ). lo_error = NEW #( iv_reason = {{p}}cx_presc_error=>c_reason-unknown ). cl_abap_unit_assert=>assert_equals( exp = 'The drug is not in the drug master' act = lo_error->get_message_text( ) ). lo_error = NEW #( iv_reason = {{p}}cx_presc_error=>c_reason-dose ). cl_abap_unit_assert=>assert_equals( exp = 'The daily dose is not allowed' act = lo_error->get_message_text( ) ). lo_error = NEW #( iv_reason = {{p}}cx_presc_error=>c_reason-duplicate ). cl_abap_unit_assert=>assert_equals( exp = 'The drug appears more than once' act = lo_error->get_message_text( ) ). ENDMETHOD. ENDCLASS.