michelchenrich

-mocks +fakes

Sep 22nd, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 1.96 KB | None | 0 0
  1. CLASS ltd_fake_invoice_operator DEFINITION FOR TESTING.
  2.   PUBLIC SECTION.
  3.     INTERFACES: <aquelas interfaces de modifier, retriever & so on>
  4.     METHODS put IMPORTING invoice <...bla>
  5.     METHODS get IMPORTING id TYPE <...invoice id bla>
  6.                 RETURNING value(return) TYPE <invoice type bla>
  7. ENDCLASS.
  8. CLASS ltd_fake_invoice_operator IMPLEMENTATION.
  9. < BLA BLA >.
  10. ENDCLASS.
  11.  
  12. CLASS ltc_invoid_paid_action DEFINITION FOR TESTING
  13. INHERITING FROM /deal/tct_bobf_operations_test
  14.   DURATION SHORT
  15.   RISK LEVEL HARMLESS.
  16.  
  17.   PRIVATE SECTION.
  18.     DATA fake_invoice_operator TYPE REF TO ltd_fake_invoice_operator.
  19.     METHODS:
  20.       setup,
  21.       <helpers bla>,
  22.       update_invoice_to_paid        FOR TESTING,
  23.       update_invoices_to_paid_value FOR TESTING,
  24.       no_invoices_retrieved         FOR TESTING.
  25. ENDCLASS.
  26.  
  27. CLASS ltc_invoid_paid_action IMPLEMENTATION.
  28.  
  29.   METHOD setup.
  30.     me->setup_test_infrastructure( ).
  31.     fake_invoice_operator = NEW ltd_fake_invoice_operator( ).
  32.   ENDMETHOD.
  33.  
  34.   METHOD update_invoice_to_paid.
  35.     given_invoice( id = '123' payment_status = '01' ).
  36.     when_updating_invoice_to_paid( id = '123' ).
  37.     then_invoice_should_be_updated( id = '123' payment_status = '02' ).
  38.   ENDMETHOD.
  39.  
  40.   METHOD given_invoice.
  41.     DATA(invoice) = VALUE zec_t_cust_invoice_root_d(
  42.                       ( key = |{ id }_key|
  43.                         invoice_id = id
  44.                         payment_status = payment_status ) ).
  45.     fake_invoice_operator->put( invoice ).
  46.   ENDMETHOD.
  47.  
  48.   METHOD when_updating_invoice_to_paid.
  49.     execute_action(
  50.       i_action      = NEW zec_a_invoice_paid( )
  51.       i_context     = VALUE #( )
  52.       i_keys        = VALUE #( ( key = |{ id }_key| ) )
  53.     ).
  54.   ENDMETHOD.
  55.  
  56.   METHOD then_invoice_should_be_updated.
  57.     DATA(actual_invoice) = fake_invoice_operator->get( id ).
  58.     cl_abap_unit_assert=>assert_equals(
  59.       exp = payment_status
  60.       act = actual-payment_status
  61.     ).
  62.   ENDMETHOD.
  63.  
  64. <bla bla>
Advertisement
Add Comment
Please, Sign In to add comment