CLASS {{p}}key_test DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. METHODS price_for IMPORTING iv_key_type TYPE string iv_quantity TYPE i RETURNING VALUE(rv_price) TYPE decfloat34. METHODS standard_price FOR TESTING. METHODS security_price FOR TESTING. METHODS transponder_price FOR TESTING. METHODS discount FOR TESTING. METHODS invalid_quantity FOR TESTING. ENDCLASS. CLASS {{p}}key_test IMPLEMENTATION. METHOD price_for. DATA lv_valid TYPE abap_bool. CALL FUNCTION '{{P}}KEY_PRICE' EXPORTING iv_key_type = iv_key_type iv_quantity = iv_quantity IMPORTING ev_price = rv_price ev_valid = lv_valid EXCEPTIONS invalid_quantity = 1 OTHERS = 2. cl_abap_unit_assert=>assert_subrc( exp = 0 ). ENDMETHOD. METHOD standard_price. cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '10.50' ) act = price_for( iv_key_type = 'ST' iv_quantity = 3 ) ). ENDMETHOD. METHOD security_price. cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '24.00' ) act = price_for( iv_key_type = 'SE' iv_quantity = 2 ) ). ENDMETHOD. METHOD transponder_price. cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '45.00' ) act = price_for( iv_key_type = 'TR' iv_quantity = 1 ) ). ENDMETHOD. METHOD discount. cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '31.50' ) act = price_for( iv_key_type = 'ST' iv_quantity = 10 ) ). ENDMETHOD. METHOD invalid_quantity. DATA lv_price TYPE decfloat34. DATA lv_valid TYPE abap_bool. CALL FUNCTION '{{P}}KEY_PRICE' EXPORTING iv_key_type = 'ST' iv_quantity = 0 IMPORTING ev_price = lv_price ev_valid = lv_valid EXCEPTIONS invalid_quantity = 1 OTHERS = 2. cl_abap_unit_assert=>assert_equals( exp = 1 act = sy-subrc ). ENDMETHOD. ENDCLASS.