All files / src/utils zcl_abapgit_string_map.clas.testclasses.abap

100% Statements 181/181
100% Branches 4/4
100% Functions 4/4
100% Lines 181/181

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 1821x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS ltcl_sm_test DEFINITION
  FINAL
  FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
  PRIVATE SECTION.
 
    TYPES:
      BEGIN OF ty_struc,
        a TYPE string,
        b TYPE abap_bool,
        c TYPE i,
      END OF ty_struc.
 
    METHODS simple FOR TESTING RAISING zcx_abapgit_exception.
    METHODS freeze FOR TESTING RAISING zcx_abapgit_exception.
    METHODS strict FOR TESTING RAISING zcx_abapgit_exception.
    METHODS case_insensitive FOR TESTING RAISING zcx_abapgit_exception.
 
ENDCLASS.
 
CLASS ltcl_sm_test IMPLEMENTATION.
 
  METHOD simple.
 
    DATA lo_cut TYPE REF TO zcl_abapgit_string_map.
 
    lo_cut = zcl_abapgit_string_map=>create( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->is_empty( )
      exp = abap_true ).
 
    lo_cut->set(
      iv_key = 'A'
      iv_val = '1' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->is_empty( )
      exp = abap_false ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->has( 'A' )
      exp = abap_true ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->get( 'A' )
      exp = '1' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->has( 'B' )
      exp = abap_false ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->get( 'B' )
      exp = '' ).
 
    lo_cut->delete( 'A' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->is_empty( )
      exp = abap_true ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->has( 'A' )
      exp = abap_false ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lo_cut->get( 'A' )
      exp = '' ).
 
  ENDMETHOD.
 
  METHOD freeze.
 
    DATA lo_cut TYPE REF TO zcl_abapgit_string_map.
 
    lo_cut = zcl_abapgit_string_map=>create( ).
    lo_cut->set(
      iv_key = 'A'
      iv_val = '1' )->freeze( ).
 
    TRY.
        lo_cut->set(
          iv_key = 'B'
          iv_val = '2' ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
 
    TRY.
        lo_cut->delete( 'A' ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
 
    TRY.
        lo_cut->clear( ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
 
  ENDMETHOD.
 
  METHOD strict.
 
    DATA ls_struc_act TYPE ty_struc.
    DATA ls_struc_exp TYPE ty_struc.
    DATA lo_x TYPE REF TO cx_root.
    DATA lo_cut TYPE REF TO zcl_abapgit_string_map.
    DATA lo_map TYPE REF TO zcl_abapgit_string_map.
 
    lo_cut = zcl_abapgit_string_map=>create( ).
 
    lo_cut->set(
      iv_key = 'a'
      iv_val = 'avalue' ).
    lo_cut->set(
      iv_key = 'b'
      iv_val = 'X' ).
    lo_cut->set(
      iv_key = 'c'
      iv_val = '123' ).
    lo_cut->set(
      iv_key = 'z'
      iv_val = 'xyz' ).
 
    ls_struc_exp-a = 'avalue'.
    ls_struc_exp-b = abap_true.
    ls_struc_exp-c = 123.
 
    TRY.
        lo_cut->to_abap( CHANGING cs_container = ls_struc_act ).
        cl_abap_unit_assert=>fail( ).
      CATCH cx_root INTO lo_x.
        cl_abap_unit_assert=>assert_equals(
          exp = 'Component Z not found in target'
          act = lo_x->get_text( ) ).
    ENDTRY.
 
    lo_map = lo_cut->strict( abap_false ).
    lo_map->to_abap( CHANGING cs_container = ls_struc_act ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = ls_struc_exp
      act = ls_struc_act ).
 
  ENDMETHOD.
 
  METHOD case_insensitive.
 
    DATA lo_cut TYPE REF TO zcl_abapgit_string_map.
    lo_cut = zcl_abapgit_string_map=>create( abap_true ).
 
    lo_cut->set(
      iv_key = 'A'
      iv_val = 'avalue' ).
    lo_cut->set(
      iv_key = 'b'
      iv_val = 'bvalue' ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'avalue'
      act = lo_cut->get( 'A' ) ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'avalue'
      act = lo_cut->get( 'a' ) ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'bvalue'
      act = lo_cut->get( 'B' ) ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'bvalue'
      act = lo_cut->get( 'b' ) ).
 
  ENDMETHOD.
 
 
ENDCLASS.