STRU and exception tasks accepted; G6 cascade fix, exception class mutants, RTTI unit notes
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
73
tasks_gen/train/G1904/reference/cx_issue_error.clas.abap
Normal file
73
tasks_gen/train/G1904/reference/cx_issue_error.clas.abap
Normal file
@@ -0,0 +1,73 @@
|
||||
CLASS {{p}}cx_issue_error DEFINITION
|
||||
PUBLIC
|
||||
INHERITING FROM cx_static_check
|
||||
FINAL
|
||||
CREATE PUBLIC.
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES {{p}}if_issue_error_info.
|
||||
|
||||
CONSTANTS:
|
||||
BEGIN OF c_case,
|
||||
unknown_material TYPE {{p}}if_issue_error_info=>ty_case VALUE 'UNKNOWN_MATERIAL',
|
||||
zero_quantity TYPE {{p}}if_issue_error_info=>ty_case VALUE 'ZERO_QUANTITY',
|
||||
over_limit TYPE {{p}}if_issue_error_info=>ty_case VALUE 'OVER_LIMIT',
|
||||
END OF c_case.
|
||||
|
||||
METHODS constructor
|
||||
IMPORTING
|
||||
iv_case TYPE {{p}}if_issue_error_info=>ty_case
|
||||
iv_material TYPE string
|
||||
iv_quantity TYPE i
|
||||
iv_limit TYPE i.
|
||||
|
||||
METHODS get_text REDEFINITION.
|
||||
|
||||
PRIVATE SECTION.
|
||||
DATA mv_case TYPE {{p}}if_issue_error_info=>ty_case.
|
||||
DATA mv_material TYPE string.
|
||||
DATA mv_quantity TYPE i.
|
||||
DATA mv_limit TYPE i.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS {{p}}cx_issue_error IMPLEMENTATION.
|
||||
|
||||
METHOD constructor.
|
||||
super->constructor( ).
|
||||
mv_case = iv_case.
|
||||
mv_material = iv_material.
|
||||
mv_quantity = iv_quantity.
|
||||
mv_limit = iv_limit.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD {{p}}if_issue_error_info~get_case.
|
||||
rv_case = mv_case.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD {{p}}if_issue_error_info~get_material.
|
||||
rv_material = mv_material.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD {{p}}if_issue_error_info~get_quantity.
|
||||
rv_quantity = mv_quantity.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD {{p}}if_issue_error_info~get_limit.
|
||||
rv_limit = mv_limit.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD get_text.
|
||||
CASE mv_case.
|
||||
WHEN c_case-unknown_material.
|
||||
result = |Material { mv_material } is not known|.
|
||||
WHEN c_case-zero_quantity.
|
||||
result = |Quantity must not be zero for material { mv_material }|.
|
||||
WHEN c_case-over_limit.
|
||||
result = |Quantity { mv_quantity } exceeds limit { mv_limit } for material { mv_material }|.
|
||||
WHEN OTHERS.
|
||||
result = |Stock issue failed for material { mv_material }|.
|
||||
ENDCASE.
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
@@ -0,0 +1,81 @@
|
||||
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.
|
||||
Reference in New Issue
Block a user