170 lines
6.5 KiB
ABAP
170 lines
6.5 KiB
ABAP
CLASS {{p}}balloon_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
|
|
PRIVATE SECTION.
|
|
DATA mo_cut TYPE REF TO {{p}}balloon_checker.
|
|
|
|
METHODS setup.
|
|
METHODS free_payload
|
|
IMPORTING iv_passengers TYPE i
|
|
iv_weight_kg TYPE i
|
|
iv_wind_kmh TYPE i
|
|
iv_cloud_base_m TYPE i
|
|
RETURNING VALUE(rv_free_kg) TYPE i.
|
|
|
|
METHODS valid_flight_is_released FOR TESTING.
|
|
METHODS crew_above_limit FOR TESTING.
|
|
METHODS weight_above_limit FOR TESTING.
|
|
METHODS wind_above_limit FOR TESTING.
|
|
METHODS cloud_base_below_limit FOR TESTING.
|
|
METHODS crew_is_checked_first FOR TESTING.
|
|
METHODS weight_is_checked_second FOR TESTING.
|
|
METHODS wind_is_checked_third FOR TESTING.
|
|
METHODS limits_are_accepted FOR TESTING.
|
|
METHODS free_payload_is_returned FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}balloon_hidden IMPLEMENTATION.
|
|
METHOD setup.
|
|
mo_cut = NEW {{p}}balloon_checker( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD free_payload.
|
|
TRY.
|
|
rv_free_kg = mo_cut->check_flight( iv_passengers = iv_passengers
|
|
iv_weight_kg = iv_weight_kg
|
|
iv_wind_kmh = iv_wind_kmh
|
|
iv_cloud_base_m = iv_cloud_base_m ).
|
|
CATCH {{p}}cx_balloon_flight.
|
|
rv_free_kg = -1.
|
|
ENDTRY.
|
|
ENDMETHOD.
|
|
|
|
METHOD valid_flight_is_released.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 140
|
|
act = free_payload( iv_passengers = 4 iv_weight_kg = 500
|
|
iv_wind_kmh = 10 iv_cloud_base_m = 2000 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD crew_above_limit.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 9 iv_weight_kg = 500
|
|
iv_wind_kmh = 10 iv_cloud_base_m = 2000 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_crew INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Passengers 9 exceeds the limit 8'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD weight_above_limit.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 4 iv_weight_kg = 700
|
|
iv_wind_kmh = 10 iv_cloud_base_m = 2000 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_weight INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Weight 700 kg exceeds the limit 640 kg'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD wind_above_limit.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 4 iv_weight_kg = 500
|
|
iv_wind_kmh = 25 iv_cloud_base_m = 2000 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_wind INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Wind 25 km/h exceeds the limit 18 km/h'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD cloud_base_below_limit.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 4 iv_weight_kg = 500
|
|
iv_wind_kmh = 10 iv_cloud_base_m = 200 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_cloud INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Cloud base 200 m is below the limit 300 m'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD crew_is_checked_first.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 9 iv_weight_kg = 700
|
|
iv_wind_kmh = 25 iv_cloud_base_m = 100 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_crew INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Passengers 9 exceeds the limit 8'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD weight_is_checked_second.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 4 iv_weight_kg = 700
|
|
iv_wind_kmh = 25 iv_cloud_base_m = 100 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_weight INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Weight 700 kg exceeds the limit 640 kg'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD wind_is_checked_third.
|
|
DATA lv_text TYPE string.
|
|
TRY.
|
|
mo_cut->check_flight( iv_passengers = 4 iv_weight_kg = 500
|
|
iv_wind_kmh = 25 iv_cloud_base_m = 100 ).
|
|
cl_abap_unit_assert=>fail( msg = 'No exception was raised' ).
|
|
CATCH {{p}}cx_balloon_wind INTO DATA(lo_exc).
|
|
lv_text = lo_exc->mv_text.
|
|
CATCH {{p}}cx_balloon_flight.
|
|
cl_abap_unit_assert=>fail( msg = 'Wrong exception type' ).
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'Wind 25 km/h exceeds the limit 18 km/h'
|
|
act = lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD limits_are_accepted.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 0
|
|
act = free_payload( iv_passengers = 8 iv_weight_kg = 640
|
|
iv_wind_kmh = 18 iv_cloud_base_m = 300 ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD free_payload_is_returned.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = 40
|
|
act = free_payload( iv_passengers = 2 iv_weight_kg = 600
|
|
iv_wind_kmh = 12 iv_cloud_base_m = 1200 ) ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|