Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- METHOD simple_configuration.
- DATA: lo_currency_converter_double TYPE REF TO if_td_currency_converter,
- lo_expense_manager TYPE REF TO cl_td_expense_manager,
- lv_total_expense TYPE i.
- *create test double object
- lo_currency_converter_double ?= cl_abap_testdouble=>create( ‘if_td_currency_converter’ ).
- *configuration for stubbing method ‘convert’:
- *step 1: set the desired returning value for the method call
- cl_abap_testdouble=>configure_call( lo_currency_converter_double )->returning( 80 ).
- *step 2: specifying which method should get stubbed
- lo_currency_converter_double->convert(
- EXPORTING
- amount = 100
- source_currency = ‘USD’
- target_currency = ‘EUR’
- ).
- *injecting the test double into the object being tested
- CREATE OBJECT lo_expense_manager EXPORTING currency_converter = lo_currency_converter_double.
- *add one expense item
- lo_expense_manager->add_expense_item(
- EXPORTING
- description = ‘Line item 1’
- currency_code = ‘USD’
- amount = ‘100’
- ).
- *actual method call
- lv_total_expense = lo_expense_manager->calculate_total_expense( currency_code = ‘EUR’ ).
- *assertion
- cl_abap_unit_assert=>assert_equals( exp = 80 act = lv_total_expense ).
- ENDMETHOD.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement