81 lines
2.8 KiB
ABAP
81 lines
2.8 KiB
ABAP
CLASS {{p}}t21_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
METHODS fee_for
|
|
IMPORTING iv_postcode TYPE string
|
|
iv_weight TYPE decfloat34
|
|
iv_express TYPE abap_bool DEFAULT abap_false
|
|
EXPORTING ev_tour TYPE string
|
|
ev_skip TYPE abap_bool
|
|
ev_fee TYPE decfloat34.
|
|
METHODS standard_parcel FOR TESTING.
|
|
METHODS heavy_parcel FOR TESTING.
|
|
METHODS express_parcel FOR TESTING.
|
|
METHODS island_parcel FOR TESTING.
|
|
METHODS unknown_zone FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t21_test IMPLEMENTATION.
|
|
METHOD fee_for.
|
|
CALL FUNCTION '{{P}}PARCEL_FEE'
|
|
EXPORTING
|
|
iv_postcode = iv_postcode
|
|
iv_weight = iv_weight
|
|
iv_express = iv_express
|
|
IMPORTING
|
|
ev_tour = ev_tour
|
|
ev_skip = ev_skip
|
|
ev_fee = ev_fee
|
|
EXCEPTIONS
|
|
unknown_zone = 1
|
|
invalid_weight = 2
|
|
OTHERS = 3.
|
|
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD standard_parcel.
|
|
fee_for( EXPORTING iv_postcode = `20095` iv_weight = 3
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `W` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_false act = lv_skip ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '6.20' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD heavy_parcel.
|
|
fee_for( EXPORTING iv_postcode = `60311` iv_weight = '10.01'
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `EH` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '10.60' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD express_parcel.
|
|
fee_for( EXPORTING iv_postcode = `10115` iv_weight = 1 iv_express = abap_true
|
|
IMPORTING ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '8.40' ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD island_parcel.
|
|
fee_for( EXPORTING iv_postcode = `80331` iv_weight = 2
|
|
IMPORTING ev_tour = DATA(lv_tour) ev_skip = DATA(lv_skip) ev_fee = DATA(lv_fee) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `S` act = lv_tour ).
|
|
cl_abap_unit_assert=>assert_equals( exp = abap_true act = lv_skip ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 0 ) act = lv_fee ).
|
|
ENDMETHOD.
|
|
|
|
METHOD unknown_zone.
|
|
DATA lv_fee TYPE decfloat34.
|
|
CALL FUNCTION '{{P}}PARCEL_FEE'
|
|
EXPORTING
|
|
iv_postcode = `XYZ`
|
|
iv_weight = 1
|
|
CHANGING
|
|
cv_fee = lv_fee
|
|
EXCEPTIONS
|
|
unknown_zone = 1
|
|
invalid_weight = 2
|
|
OTHERS = 3.
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = sy-subrc ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|