CLASS ltc_fire DEFINITION FOR TESTING DURATION LONG RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS ci_fire_when_everything_fits FOR TESTING.
METHODS ci_no_fire_not_enough_heat FOR TESTING.
METHODS si_fire_when_everything_fits FOR TESTING.
METHODS si_no_fire_not_enough_heat FOR TESTING.
ENDCLASS.
CLASS ltc_fire IMPLEMENTATION.
METHOD ci_fire_when_everything_fits.
DATA(lo_fuel) = NEW zcl_fuel( iv_flammable = abap_true ).
DATA(lo_oxygen) = NEW zcl_oxygen( iv_sufficient_quantity = abap_true ).
DATA(lo_heat) = NEW zcl_heat( iv_sufficient_heat = abap_true ).
DATA(lo_fire) = NEW zcl_fire( io_fuel = lo_fuel
io_oxygen = lo_oxygen
io_heat = lo_heat ).
DATA(lv_is_burning) = lo_fire->is_burning( ).
cl_abap_unit_assert=>assert_true( act = lv_is_burning ).
ENDMETHOD.
METHOD ci_no_fire_not_enough_heat.
DATA(lo_fuel) = NEW zcl_fuel( iv_flammable = abap_true ).
DATA(lo_oxygen) = NEW zcl_oxygen( iv_sufficient_quantity = abap_true ).
DATA(lo_heat) = NEW zcl_heat( iv_sufficient_heat = abap_false ).
DATA(lo_fire) = NEW zcl_fire( io_fuel = lo_fuel
io_oxygen = lo_oxygen
io_heat = lo_heat ).
DATA(lv_is_burning) = lo_fire->is_burning( ).
cl_abap_unit_assert=>assert_false( act = lv_is_burning ).
ENDMETHOD.
METHOD si_fire_when_everything_fits.
DATA(lo_fuel) = NEW zcl_fuel( iv_flammable = abap_true ).
DATA(lo_oxygen) = NEW zcl_oxygen( iv_sufficient_quantity = abap_true ).
DATA(lo_heat) = NEW zcl_heat( iv_sufficient_heat = abap_true ).
DATA(lo_fire) = NEW zcl_fire( ).
lo_fire->set_fuel( lo_fuel ).
lo_fire->set_head( lo_heat ).
lo_fire->set_oxygen( lo_oxygen ).
DATA(lv_is_burning) = lo_fire->is_burning( ).
cl_abap_unit_assert=>assert_true( act = lv_is_burning ).
ENDMETHOD.
METHOD si_no_fire_not_enough_heat.
DATA(lo_fuel) = NEW zcl_fuel( iv_flammable = abap_true ).
DATA(lo_oxygen) = NEW zcl_oxygen( iv_sufficient_quantity = abap_true ).
DATA(lo_heat) = NEW zcl_heat( iv_sufficient_heat = abap_false ).
DATA(lo_fire) = NEW zcl_fire( ).
lo_fire->set_fuel( lo_fuel ).
lo_fire->set_head( lo_heat ).
lo_fire->set_oxygen( lo_oxygen ).
DATA(lv_is_burning) = lo_fire->is_burning( ).
cl_abap_unit_assert=>assert_false( act = lv_is_burning ).
ENDMETHOD.
ENDCLASS.
class test_si definition for testing duration long risk level harmless
abstract.
protected section.
data cut type ref to zcl_fire.
"prerequisite flags set by the test case
data given_flammable type abap_bool.
data given_sufficient_oxygen type abap_bool.
data given_enough_heat type abap_bool.
"expected result of the test call
data expected_result type abap_bool.
"general setup and test
methods setup_low.
methods test_low.
endclass.
class test_si implementation.
method setup_low.
cut = new #( ).
cut->set_fuel( new zcl_fuel( given_flammable ) ).
cut->set_heat( new zcl_heat( given_enough_heat ) ).
cut->set_oxygen( new zcl_oxygen( given_sufficient_oxygen ) ).
endmethod.
method test_low.
cl_abap_unit_assert=>assert_equals(
exp = expected_result
act = cut->is_burning( ) ).
endmethod.
endclass.
class test_everything_fits_si
definition for testing duration long risk level harmless
inheriting from test_si
final.
private section.
methods setup.
methods test for testing.
endclass.
class test_everything_fits_si implementation.
method setup.
"set concrete prerequisites
given_flammable = abap_true.
given_enough_heat = abap_true.
given_sufficient_oxygen = abap_true.
setup_low( ).
endmethod.
method test.
"set concrete expected result
expected_result = abap_true.
test_low( ).
endmethod.
endclass.
class test_not_enough_heat_si
definition for testing duration long risk level harmless
inheriting from test_si
final.
private section.
methods setup.
methods test for testing.
endclass.
class test_not_enough_heat_si implementation.
method setup.
given_flammable = abap_true.
given_enough_heat = abap_false.
given_sufficient_oxygen = abap_true.
setup_low( ).
endmethod.
method test.
expected_result = abap_false.
test_low( ).
endmethod.
endclass.
class test_not_enough_oxygene " name changed after copy
definition for testing duration long risk level harmless
inheriting from test
final.
private section.
methods setup.
methods test for testing.
endclass.
class test_not_enough_oxygene implementation. " name changed
method setup.
given_flammable = abap_true.
given_enough_heat = abap_true. " changed from abap_false
given_sufficient_oxygen = abap_false. "changed from abap_true
setup_low( ).
endmethod.
method test.
expected_result = abap_false. " not changed, the result is the same
test_low( ).
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 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |