82 lines
3.5 KiB
ABAP
82 lines
3.5 KiB
ABAP
CLASS ltc_issue_error DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
METHODS unknown_material_text FOR TESTING.
|
|
METHODS zero_quantity_text FOR TESTING.
|
|
METHODS over_limit_text FOR TESTING.
|
|
METHODS default_text FOR TESTING.
|
|
METHODS keeps_context_data FOR TESTING.
|
|
METHODS caught_error
|
|
IMPORTING iv_case TYPE {{p}}if_issue_error_info=>ty_case
|
|
iv_material TYPE string
|
|
iv_quantity TYPE i
|
|
iv_limit TYPE i
|
|
RETURNING VALUE(ro_error) TYPE REF TO {{p}}cx_issue_error.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS ltc_issue_error IMPLEMENTATION.
|
|
|
|
METHOD caught_error.
|
|
TRY.
|
|
RAISE EXCEPTION TYPE {{p}}cx_issue_error
|
|
EXPORTING
|
|
iv_case = iv_case
|
|
iv_material = iv_material
|
|
iv_quantity = iv_quantity
|
|
iv_limit = iv_limit.
|
|
CATCH {{p}}cx_issue_error INTO ro_error.
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD unknown_material_text.
|
|
DATA(lo_error) = caught_error( iv_case = {{p}}cx_issue_error=>c_case-unknown_material
|
|
iv_material = 'MAT-A'
|
|
iv_quantity = 1
|
|
iv_limit = 10 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `Material MAT-A is not known`
|
|
act = lo_error->get_text( ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD zero_quantity_text.
|
|
DATA(lo_error) = caught_error( iv_case = {{p}}cx_issue_error=>c_case-zero_quantity
|
|
iv_material = 'MAT-B'
|
|
iv_quantity = 0
|
|
iv_limit = 20 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `Quantity must not be zero for material MAT-B`
|
|
act = lo_error->get_text( ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD over_limit_text.
|
|
DATA(lo_error) = caught_error( iv_case = {{p}}cx_issue_error=>c_case-over_limit
|
|
iv_material = 'MAT-C'
|
|
iv_quantity = 30
|
|
iv_limit = 20 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `Quantity 30 exceeds limit 20 for material MAT-C`
|
|
act = lo_error->get_text( ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD default_text.
|
|
DATA(lo_error) = caught_error( iv_case = 'OTHER'
|
|
iv_material = 'MAT-D'
|
|
iv_quantity = 5
|
|
iv_limit = 50 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = `Stock issue failed for material MAT-D`
|
|
act = lo_error->get_text( ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD keeps_context_data.
|
|
DATA(lo_error) = caught_error( iv_case = {{p}}cx_issue_error=>c_case-over_limit
|
|
iv_material = 'MAT-E'
|
|
iv_quantity = 99
|
|
iv_limit = 90 ).
|
|
DATA lo_info TYPE REF TO {{p}}if_issue_error_info.
|
|
lo_info = lo_error.
|
|
cl_abap_unit_assert=>assert_equals( exp = {{p}}cx_issue_error=>c_case-over_limit
|
|
act = lo_info->get_case( ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'MAT-E' act = lo_info->get_material( ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 99 act = lo_info->get_quantity( ) ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 90 act = lo_info->get_limit( ) ).
|
|
ENDMETHOD.
|
|
|
|
ENDCLASS.
|