119 lines
4.6 KiB
ABAP
119 lines
4.6 KiB
ABAP
CLASS ltc_air_freight_pricer DEFINITION FINAL FOR TESTING
|
|
DURATION SHORT RISK LEVEL HARMLESS.
|
|
|
|
PRIVATE SECTION.
|
|
TYPES ty_expected TYPE c LENGTH 20.
|
|
|
|
DATA mo_cut TYPE REF TO {{p}}if_air_freight.
|
|
|
|
METHODS setup.
|
|
METHODS assert_weight
|
|
IMPORTING iv_expected TYPE ty_expected
|
|
iv_actual TYPE {{p}}if_air_freight=>ty_weight.
|
|
METHODS assert_amount
|
|
IMPORTING iv_expected TYPE ty_expected
|
|
iv_actual TYPE {{p}}if_air_freight=>ty_amount.
|
|
|
|
METHODS general_shipment_is_priced FOR TESTING.
|
|
METHODS volumetric_weight_wins FOR TESTING.
|
|
METHODS dangerous_goods_surcharge FOR TESTING.
|
|
METHODS zero_weight_is_rejected FOR TESTING.
|
|
METHODS bad_category_is_rejected FOR TESTING.
|
|
METHODS too_heavy_is_rejected FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS ltc_air_freight_pricer IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}air_freight_pricer( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD assert_weight.
|
|
DATA lv_expected TYPE {{p}}if_air_freight=>ty_weight.
|
|
lv_expected = iv_expected.
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = iv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD assert_amount.
|
|
DATA lv_expected TYPE {{p}}if_air_freight=>ty_amount.
|
|
lv_expected = iv_expected.
|
|
cl_abap_unit_assert=>assert_equals( exp = lv_expected act = iv_actual ).
|
|
ENDMETHOD.
|
|
|
|
METHOD general_shipment_is_priced.
|
|
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
|
|
|
ls_result = mo_cut->price( iv_weight = '12.000'
|
|
iv_volume = '48000.000'
|
|
iv_category = {{p}}if_air_freight=>c_category-general
|
|
iv_dangerous = abap_false ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-ok
|
|
act = ls_result-reason ).
|
|
assert_weight( iv_expected = '12.000' iv_actual = ls_result-chargeable_weight ).
|
|
assert_amount( iv_expected = '135.96' iv_actual = ls_result-total_amount ).
|
|
ENDMETHOD.
|
|
|
|
METHOD volumetric_weight_wins.
|
|
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
|
|
|
ls_result = mo_cut->price( iv_weight = '5.000'
|
|
iv_volume = '120000.000'
|
|
iv_category = {{p}}if_air_freight=>c_category-general
|
|
iv_dangerous = abap_false ).
|
|
|
|
assert_weight( iv_expected = '20.000' iv_actual = ls_result-chargeable_weight ).
|
|
assert_amount( iv_expected = '216.60' iv_actual = ls_result-total_amount ).
|
|
ENDMETHOD.
|
|
|
|
METHOD dangerous_goods_surcharge.
|
|
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
|
|
|
ls_result = mo_cut->price( iv_weight = '10.000'
|
|
iv_volume = '600.000'
|
|
iv_category = {{p}}if_air_freight=>c_category-valuable
|
|
iv_dangerous = abap_true ).
|
|
|
|
assert_amount( iv_expected = '54.00' iv_actual = ls_result-dangerous_fee ).
|
|
assert_amount( iv_expected = '226.68' iv_actual = ls_result-total_amount ).
|
|
ENDMETHOD.
|
|
|
|
METHOD zero_weight_is_rejected.
|
|
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
|
|
|
ls_result = mo_cut->price( iv_weight = '0.000'
|
|
iv_volume = '600.000'
|
|
iv_category = {{p}}if_air_freight=>c_category-general
|
|
iv_dangerous = abap_false ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-bad_weight
|
|
act = ls_result-reason ).
|
|
assert_amount( iv_expected = '0.00' iv_actual = ls_result-total_amount ).
|
|
ENDMETHOD.
|
|
|
|
METHOD bad_category_is_rejected.
|
|
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
|
|
|
ls_result = mo_cut->price( iv_weight = '10.000'
|
|
iv_volume = '600.000'
|
|
iv_category = 'EXPRESS'
|
|
iv_dangerous = abap_false ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-bad_category
|
|
act = ls_result-reason ).
|
|
ENDMETHOD.
|
|
|
|
METHOD too_heavy_is_rejected.
|
|
DATA ls_result TYPE {{p}}if_air_freight=>ty_result.
|
|
|
|
ls_result = mo_cut->price( iv_weight = '3000.500'
|
|
iv_volume = '600.000'
|
|
iv_category = {{p}}if_air_freight=>c_category-general
|
|
iv_dangerous = abap_false ).
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = {{p}}if_air_freight=>c_reason-too_heavy
|
|
act = ls_result-reason ).
|
|
assert_amount( iv_expected = '0.00' iv_actual = ls_result-total_amount ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|