daily pastebin goal
6%
SHARE
TWEET

Untitled

isavchenko Dec 17th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. METHOD simple_configuration.
  2.  
  3.     DATA:  lo_currency_converter_double TYPE REF TO      if_td_currency_converter,
  4.           lo_expense_manager          TYPE REF TO      cl_td_expense_manager,
  5.           lv_total_expense            TYPE              i.
  6.  
  7. *create test double object
  8.     lo_currency_converter_double ?= cl_abap_testdouble=>create( ‘if_td_currency_converter’ ).
  9.  
  10. *configuration for stubbing method ‘convert’:
  11.  
  12. *step 1: set the desired returning value for the method call
  13.     cl_abap_testdouble=>configure_call( lo_currency_converter_double )->returning( 80 ).
  14.  
  15. *step 2: specifying which method should get stubbed
  16.     lo_currency_converter_double->convert(
  17.           EXPORTING
  18.         amount          = 100
  19.         source_currency = ‘USD’
  20.         target_currency = ‘EUR’
  21.         ).
  22.  
  23. *injecting the test double into the object being tested
  24.     CREATE OBJECT lo_expense_manager EXPORTING currency_converter = lo_currency_converter_double.
  25.  
  26. *add one expense item
  27.     lo_expense_manager->add_expense_item(
  28.           EXPORTING
  29.         description  = ‘Line item 1’
  30.         currency_code = ‘USD’
  31.         amount        = ‘100’
  32.         ).
  33.  
  34. *actual method call
  35.     lv_total_expense = lo_expense_manager->calculate_total_expense( currency_code = ‘EUR’ ).
  36.  
  37. *assertion
  38.     cl_abap_unit_assert=>assert_equals( exp = 80 act = lv_total_expense ).
  39.  
  40.   ENDMETHOD.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top