CLASS zcl_unit_test_example_class DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
METHODS get_completed_items_count
IMPORTING
!iv_key TYPE /bobf/conf_key
RETURNING
VALUE(rv_count) TYPE int4 .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_unit_test_example_class IMPLEMENTATION.
METHOD get_completed_items_count.
DATA: t_items TYPE bo_items.
rv_count = 0.
TEST-SEAM srv_mngr.
DATA(o_srv_mngr) = /bobf/cl_tra_serv_mgr_factory=>get_service_manager( if_i_status_bo_c=>sc_bo_key ).
END-TEST-SEAM.
o_srv_mngr->retrieve_by_association(
EXPORTING
iv_node_key = if_i_status_bo_c=>sc_node-header
it_key = VALUE #( ( key = iv_key ) )
iv_association = if_i_status_bo_c=>sc_association-header-items
iv_fill_data = abap_true
IMPORTING
et_data = t_items
).
rv_count = REDUCE int4( INIT result = 0
FOR wa IN t_items WHERE ( wa-status = 'Completed' )
( result = result + 1 ) ).
ENDMETHOD.
ENDCLASS.
CLASS lcl_bo_mock DEFINITION FINAL.
PUBLIC SECTION.
INTERFACES /bobf/if_tra_service_manager.
CLASS-METHODS set_data
IMPORTING
is_header TYPE bo_header
it_items TYPE bo_items.
PRIVATE SECTION.
CLASS-DATA: s_header TYPE bo_header,
t_items TYPE bo_items.
ENDCLASS.
CLASS lcl_bo_mock IMPLEMENTATION.
METHOD set_data.
s_header = is_header.
t_items = it_items.
ENDMETHOD.
METHOD /bobf/if_tra_service_manager~retrieve_by_association.
IF iv_association = if_i_status_bo_c=>sc_association-header-items.
et_data = VALUE bo_items( FOR wa IN t_items WHERE ( key = it_key[ 1 ]-key ) ( wa ) ).
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS lcl_unit DEFINITION
FOR TESTING
FINAL
DURATION SHORT
RISK LEVEL HARMLESS.
PUBLIC SECTION.
METHODS setup.
methods t_2_completed FOR TESTING.
PRIVATE SECTION.
DATA m_cut TYPE REF TO zcl_unit_test_example_class.
ENDCLASS.
CLASS lcl_unit IMPLEMENTATION.
METHOD setup.
TEST-INJECTION srv_mngr.
o_srv_mngr = new lo_mock_bo( ).
end-test-injection.
CREATE OBJECT m_cut.
ENDMETHOD.
METHOD t_2_completed.
" Check if 2 items in the list is completed
lcl_bo_mock=>set_data( s_header = VALUE #( key = '1' )
t_items = VALUE #( ( key = '2' parent_key = '1' Status = 'Completed' )
( key = '2' parent_key = '1' Status = 'Completed' ) ) ).
data(result) = m_cut->get_completed_items_count( iv_key = '1' ).
cl_abap_unit_assert=>assert_equals( act = result exp = 2 ).
ENDMETHOD.
ENDCLASS.
METHOD t_0_completed.
" Check if 0 items in the list is completed
lcl_bo_mock=>set_data( s_header = VALUE #( key = '1' )
t_items = VALUE #( ( key = '2' parent_key = '1' Status = 'Not started' )
( key = '2' parent_key = '1' Status = 'Not started' ) ) ).
data(result) = m_cut->get_completed_items_count( iv_key = '1' ).
cl_abap_unit_assert=>assert_equals( act = result exp = 0 ).
ENDMETHOD.
METHOD t_1_completed.
" Check if 1 items in the list is completed
lcl_bo_mock=>set_data( s_header = VALUE #( key = '1' )
t_items = VALUE #( ( key = '2' parent_key = '1' Status = 'Not started' )
( key = '2' parent_key = '1' Status = 'Completed' ) ) ).
data(result) = m_cut->get_completed_items_count( iv_key = '1' ).
cl_abap_unit_assert=>assert_equals( act = result exp = 1 ).
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |