CLASS {{p}}t42_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. CLASS-DATA go_env TYPE REF TO if_cds_test_environment. CLASS-METHODS class_setup. CLASS-METHODS class_teardown. METHODS setup. METHODS small_class FOR TESTING. METHODS medium_class FOR TESTING. METHODS large_class FOR TESTING. METHODS length_in_centimetres FOR TESTING. METHODS fee_without_power FOR TESTING. METHODS power_surcharge FOR TESTING. METHODS rounds_after_days FOR TESTING. METHODS large_boat_fee FOR TESTING. METHODS unknown_pier_ignored FOR TESTING. METHODS boat_name_shown FOR TESTING. ENDCLASS. CLASS {{p}}t42_hidden IMPLEMENTATION. METHOD class_setup. go_env = cl_cds_test_environment=>create( i_for_entity = '{{P}}I_BERTH_FEE' ). ENDMETHOD. METHOD class_teardown. go_env->destroy( ). ENDMETHOD. METHOD setup. DATA lt_pier TYPE STANDARD TABLE OF {{p}}pier WITH EMPTY KEY. DATA lt_berth TYPE STANDARD TABLE OF {{p}}berth WITH EMPTY KEY. go_env->clear_doubles( ). lt_pier = VALUE #( ( pier_code = 'A' base_fee = '20.00' rate_per_m = '3.00' power_fee = '5.00' ) ( pier_code = 'B' base_fee = '10.00' rate_per_m = '1.55' power_fee = '2.00' ) ( pier_code = 'C' base_fee = '40.00' rate_per_m = '5.00' power_fee = '8.00' ) ). lt_berth = VALUE #( ( berth_id = 'H1' boat_name = 'SEAGULL' length_m = '7.50' pier_code = 'A' shore_power = 'N' stay_days = 2 ) ( berth_id = 'H2' boat_name = 'MARLIN' length_m = '8.00' pier_code = 'A' shore_power = 'Y' stay_days = 3 ) ( berth_id = 'H3' boat_name = 'OTTER' length_m = '15.00' pier_code = 'B' shore_power = 'N' stay_days = 1 ) ( berth_id = 'H4' boat_name = 'PELICAN' length_m = '15.01' pier_code = 'B' shore_power = 'Y' stay_days = 2 ) ( berth_id = 'H5' boat_name = 'DOLPHIN' length_m = '9.99' pier_code = 'B' shore_power = 'N' stay_days = 3 ) ( berth_id = 'H6' boat_name = 'SKUA' length_m = '9.99' pier_code = 'B' shore_power = 'Y' stay_days = 3 ) ( berth_id = 'H7' boat_name = 'TERN' length_m = '12.34' pier_code = 'C' shore_power = 'N' stay_days = 4 ) ( berth_id = 'H8' boat_name = 'GULL' length_m = '6.00' pier_code = 'Z' shore_power = 'N' stay_days = 1 ) ( berth_id = 'H9' boat_name = 'HERON' length_m = '20.00' pier_code = 'C' shore_power = 'Y' stay_days = 1 ) ). go_env->insert_test_data( lt_pier ). go_env->insert_test_data( lt_berth ). ENDMETHOD. METHOD small_class. SELECT SINGLE size_class FROM {{p}}i_berth_fee WHERE berth_id = 'H1' INTO @DATA(lv_class). cl_abap_unit_assert=>assert_equals( exp = 'SMALL' act = condense( val = lv_class ) ). ENDMETHOD. METHOD medium_class. SELECT SINGLE size_class FROM {{p}}i_berth_fee WHERE berth_id = 'H2' INTO @DATA(lv_lower). SELECT SINGLE size_class FROM {{p}}i_berth_fee WHERE berth_id = 'H3' INTO @DATA(lv_upper). cl_abap_unit_assert=>assert_equals( exp = 'MEDIUM' act = condense( val = lv_lower ) ). cl_abap_unit_assert=>assert_equals( exp = 'MEDIUM' act = condense( val = lv_upper ) ). ENDMETHOD. METHOD large_class. SELECT SINGLE size_class FROM {{p}}i_berth_fee WHERE berth_id = 'H4' INTO @DATA(lv_class). cl_abap_unit_assert=>assert_equals( exp = 'LARGE' act = condense( val = lv_class ) ). ENDMETHOD. METHOD length_in_centimetres. SELECT SINGLE length_cm FROM {{p}}i_berth_fee WHERE berth_id = 'H1' INTO @DATA(lv_small). SELECT SINGLE length_cm FROM {{p}}i_berth_fee WHERE berth_id = 'H5' INTO @DATA(lv_medium). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 750 ) act = CONV decfloat34( lv_small ) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 999 ) act = CONV decfloat34( lv_medium ) ). ENDMETHOD. METHOD fee_without_power. SELECT SINGLE total_fee FROM {{p}}i_berth_fee WHERE berth_id = 'H1' INTO @DATA(lv_fee). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '85.00' ) act = CONV decfloat34( lv_fee ) ). ENDMETHOD. METHOD power_surcharge. SELECT SINGLE total_fee FROM {{p}}i_berth_fee WHERE berth_id = 'H2' INTO @DATA(lv_fee). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '147.00' ) act = CONV decfloat34( lv_fee ) ). ENDMETHOD. METHOD rounds_after_days. SELECT SINGLE total_fee FROM {{p}}i_berth_fee WHERE berth_id = 'H5' INTO @DATA(lv_plain). SELECT SINGLE total_fee FROM {{p}}i_berth_fee WHERE berth_id = 'H6' INTO @DATA(lv_power). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '76.45' ) act = CONV decfloat34( lv_plain ) ). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '82.45' ) act = CONV decfloat34( lv_power ) ). ENDMETHOD. METHOD large_boat_fee. SELECT SINGLE total_fee FROM {{p}}i_berth_fee WHERE berth_id = 'H9' INTO @DATA(lv_fee). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '148.00' ) act = CONV decfloat34( lv_fee ) ). ENDMETHOD. METHOD unknown_pier_ignored. SELECT COUNT(*) FROM {{p}}i_berth_fee INTO @DATA(lv_rows). cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( 8 ) act = CONV decfloat34( lv_rows ) ). ENDMETHOD. METHOD boat_name_shown. SELECT SINGLE boat_name FROM {{p}}i_berth_fee WHERE berth_id = 'H3' INTO @DATA(lv_name). cl_abap_unit_assert=>assert_equals( exp = 'OTTER' act = condense( val = lv_name ) ). ENDMETHOD. ENDCLASS.