All files / src/git zcl_abapgit_git_commit.clas.testclasses.abap

100% Statements 320/320
100% Branches 21/21
100% Functions 21/21
100% Lines 320/320

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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 3211x 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 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 1x 1x 4x 4x 4x 4x 4x 4x 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_test DEFINITION DEFERRED.
CLASS zcl_abapgit_git_commit DEFINITION LOCAL FRIENDS ltcl_test.
 
 
CLASS ltcl_test DEFINITION FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS FINAL.
 
  PRIVATE SECTION.
 
    METHODS:
      parse_commits FOR TESTING RAISING zcx_abapgit_exception,
      check_author_regex FOR TESTING RAISING zcx_abapgit_exception.
 
ENDCLASS.
 
 
CLASS ltcl_test IMPLEMENTATION.
 
  METHOD parse_commits.
 
    DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt,
          lt_commits TYPE zif_abapgit_git_definitions=>ty_commit_tt,
          ls_commit  LIKE LINE OF lt_commits,
          ls_object  LIKE LINE OF lt_objects.
 
 
    ls_object-type = zif_abapgit_git_definitions=>c_type-commit.
    ls_object-data = '7472656520396335376238613931336465306539' &&
      '3735333630633261306330643638363037306162' &&
      '61343965650A706172656E742036393532346462' &&
      '3139363263383839366566343364323861616131' &&
      '396536366533373263653364620A617574686F72' &&
      '206C6172736870203C6C617273687040686F746D' &&
      '61696C2E636F6D3E203135333236313133353020' &&
      '2B303030300A636F6D6D6974746572206C617273' &&
      '6870203C6C617273687040686F746D61696C2E63' &&
      '6F6D3E2031353332363131333530202B30303030' &&
      '0A0A56494557'.
    APPEND ls_object TO lt_objects.
 
    lt_commits = zcl_abapgit_git_commit=>parse_commits( lt_objects ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( lt_commits )
      exp = 1 ).
 
    READ TABLE lt_commits INTO ls_commit INDEX 1.
    cl_abap_unit_assert=>assert_subrc( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = ls_commit-message
      exp = 'VIEW' ).
 
  ENDMETHOD.
 
  METHOD check_author_regex.
 
    DATA: lt_objects         TYPE zif_abapgit_definitions=>ty_objects_tt,
          lt_commits         TYPE zif_abapgit_git_definitions=>ty_commit_tt,
          ls_object          LIKE LINE OF lt_objects,
          ls_git_pack_commit TYPE zcl_abapgit_git_pack=>ty_commit.
 
 
    ls_object-type = zif_abapgit_git_definitions=>c_type-commit.
    ls_git_pack_commit-tree      = 'dummy'.
    ls_git_pack_commit-committer = 'dummy'.
 
    ls_git_pack_commit-author = 'Lastname, Firstname <mail@mail.com> 1532611350 +0000'.
    ls_object-data = zcl_abapgit_git_pack=>encode_commit( ls_git_pack_commit ).
    APPEND ls_object TO lt_objects.
 
    ls_git_pack_commit-author = 'Soeren Mueller <mail@mail.com> 1532611350 +0000'.
    ls_object-data = zcl_abapgit_git_pack=>encode_commit( ls_git_pack_commit ).
    APPEND ls_object TO lt_objects.
 
    ls_git_pack_commit-author = 'S#ren M#ller <mail@mail.com> 1532611350 +0000'.
    ls_object-data = zcl_abapgit_git_pack=>encode_commit( ls_git_pack_commit ).
    APPEND ls_object TO lt_objects.
 
    ls_git_pack_commit-author = 'Dr. Werner Mueller <mail@mail.com> 1532611350 +0000'.
    ls_object-data = zcl_abapgit_git_pack=>encode_commit( ls_git_pack_commit ).
    APPEND ls_object TO lt_objects.
 
    ls_git_pack_commit-author = 'SAP*........ <SAP*........@localhost> 1535375483 +0200'.
    ls_object-data = zcl_abapgit_git_pack=>encode_commit( ls_git_pack_commit ).
    APPEND ls_object TO lt_objects.
 
    ls_git_pack_commit-author = |Soeren %26 Sascha <soerenschlegel87@gmail.com> 1557574255 +0000|.
    ls_object-data = zcl_abapgit_git_pack=>encode_commit( ls_git_pack_commit ).
    APPEND ls_object TO lt_objects.
 
    lt_commits = zcl_abapgit_git_commit=>parse_commits( lt_objects ).
 
    cl_abap_unit_assert=>assert_equals(
       act = lines( lt_commits )
       exp = 6 ).
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltc_parent_handling DEFINITION DEFERRED.
CLASS zcl_abapgit_git_commit DEFINITION LOCAL FRIENDS ltc_parent_handling.
CLASS ltc_parent_handling DEFINITION FINAL FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
    DATA mt_commits TYPE zif_abapgit_git_definitions=>ty_commit_tt.
    METHODS blank_not_missing FOR TESTING RAISING cx_static_check.
    METHODS parent_is_missing FOR TESTING RAISING cx_static_check.
    METHODS parent_is_found FOR TESTING RAISING cx_static_check.
    METHODS missing_parent1_cleared FOR TESTING RAISING cx_static_check.
    METHODS missing_parent2_cleared FOR TESTING RAISING cx_static_check.
    METHODS matched_parent1_remains FOR TESTING RAISING cx_static_check.
    METHODS given_commit_sha1 IMPORTING iv_sha1 TYPE zif_abapgit_git_definitions=>ty_sha1.
    METHODS parent_should_be_missing IMPORTING iv_sha1 TYPE zif_abapgit_git_definitions=>ty_sha1.
    METHODS parent_should_not_be_missing IMPORTING iv_sha1 TYPE zif_abapgit_git_definitions=>ty_sha1.
    METHODS given_commit IMPORTING iv_sha1    TYPE zif_abapgit_git_definitions=>ty_sha1
                                   iv_parent1 TYPE zif_abapgit_git_definitions=>ty_sha1 OPTIONAL
                                   iv_parent2 TYPE zif_abapgit_git_definitions=>ty_sha1 OPTIONAL.
ENDCLASS.
 
 
CLASS ltc_parent_handling IMPLEMENTATION.
 
  METHOD blank_not_missing.
    given_commit_sha1( 'F00' ).
    parent_should_not_be_missing( '' ).
  ENDMETHOD.
 
  METHOD parent_is_missing.
    given_commit_sha1( 'F00' ).
    parent_should_be_missing( 'BA5' ).
  ENDMETHOD.
 
  METHOD parent_is_found.
    given_commit_sha1( 'F00' ).
    parent_should_not_be_missing( 'F00' ).
  ENDMETHOD.
 
  METHOD missing_parent1_cleared.
 
    DATA ls_commit TYPE zif_abapgit_git_definitions=>ty_commit.
 
    given_commit( iv_sha1 = 'F00'
                  iv_parent1 = 'BA5' ).
    zcl_abapgit_git_commit=>clear_missing_parents( CHANGING ct_commits = mt_commits ).
 
    READ TABLE mt_commits INDEX 1 INTO ls_commit.
    cl_abap_unit_assert=>assert_equals( act = ls_commit-parent1
                                        exp = '' ).
  ENDMETHOD.
 
  METHOD missing_parent2_cleared.
 
    DATA ls_commit TYPE zif_abapgit_git_definitions=>ty_commit.
 
    given_commit( iv_sha1 = 'F00'
                  iv_parent2 = 'BA5' ).
    zcl_abapgit_git_commit=>clear_missing_parents( CHANGING ct_commits = mt_commits ).
 
    READ TABLE mt_commits INDEX 1 INTO ls_commit.
    cl_abap_unit_assert=>assert_equals( act = ls_commit-parent2
                                        exp = '' ).
 
  ENDMETHOD.
 
  METHOD matched_parent1_remains.
 
    DATA ls_commit TYPE zif_abapgit_git_definitions=>ty_commit.
 
    given_commit( 'F00' ).
    given_commit( iv_sha1 = 'BA5'
                  iv_parent1 = 'F00' ).
 
    zcl_abapgit_git_commit=>clear_missing_parents( CHANGING ct_commits = mt_commits ).
 
    READ TABLE mt_commits INDEX 2 INTO ls_commit.
    cl_abap_unit_assert=>assert_equals( act = ls_commit-parent1
                                        exp = 'F00' ).
 
  ENDMETHOD.
 
  METHOD given_commit_sha1.
    DATA ls_commit TYPE zif_abapgit_git_definitions=>ty_commit.
 
    ls_commit-sha1 = iv_sha1.
    APPEND ls_commit TO mt_commits.
 
  ENDMETHOD.
 
 
  METHOD parent_should_be_missing.
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_git_commit=>is_missing( it_commits = mt_commits
                                                iv_sha1    = iv_sha1 )
      exp = abap_true ).
  ENDMETHOD.
 
  METHOD parent_should_not_be_missing.
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_git_commit=>is_missing( it_commits = mt_commits
                                                iv_sha1    = iv_sha1 )
      exp = abap_false ).
  ENDMETHOD.
 
  METHOD given_commit.
    FIELD-SYMBOLS: <ls_commit> TYPE zif_abapgit_git_definitions=>ty_commit.
    APPEND INITIAL LINE TO mt_commits ASSIGNING <ls_commit>.
    <ls_commit>-sha1 = iv_sha1.
    <ls_commit>-parent1 = iv_parent1.
    <ls_commit>-parent2 = iv_parent2.
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_extract_author_data DEFINITION DEFERRED.
CLASS zcl_abapgit_git_commit DEFINITION LOCAL FRIENDS ltcl_extract_author_data.
 
CLASS ltcl_extract_author_data DEFINITION FINAL
  FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
    METHODS extract_author_data1 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data2 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data3 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data4 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data5 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data6 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data7 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data8 FOR TESTING RAISING cx_static_check.
    METHODS extract_author_data9 FOR TESTING RAISING cx_static_check.
 
ENDCLASS.
 
CLASS ltcl_extract_author_data IMPLEMENTATION.
 
  METHOD extract_author_data1.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data( 'Volker Jägle äÖüß <github@beimir.net> 1573216988 +0000' ).
      CATCH zcx_abapgit_exception.
        cl_abap_unit_assert=>fail( |Language-related special characters in author name are allowed.| ).
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data2.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data(
          'pull[bot&%#$] <39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000' ).
      CATCH zcx_abapgit_exception.
        cl_abap_unit_assert=>fail( |Special characters in author name are allowed.| ).
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data3.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data(
          'pull[bot] <39814207+pull[bot]@users.noreply.github.com> 1573216988 +00001' ).
        cl_abap_unit_assert=>fail( |+00001 shouldn't be valid cause it's too long.| ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data4.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data(
          'pull[bot] <39814207+pull[bot]@users.noreply.github.com> 15732169881 +0000' ).
        cl_abap_unit_assert=>fail( |Value shouldn't be valid cause time is invalid.| ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data5.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data(
          '<39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000' ).
        cl_abap_unit_assert=>fail( |Value shouldn't be valid cause no author name was supplied.| ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data6.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data( 'pull[bot] 1573216988 +0000' ).
        cl_abap_unit_assert=>fail( |Value shouldn't be valid cause no email was supplied.| ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data7.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data( 'pull[bot] <39814207+pull[bot]@users.noreply.github.com> +0000' ).
        cl_abap_unit_assert=>fail( |Value shouldn't be valid cause no time was supplied.| ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data8.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data(
          'pull[bot] <39814207+pull[bot]@users.noreply.github.com> 1573216988' ).
        cl_abap_unit_assert=>fail( |Value shouldn't be valid cause +0000 wasn't supplied.| ).
      CATCH zcx_abapgit_exception.
    ENDTRY.
  ENDMETHOD.
 
  METHOD extract_author_data9.
    TRY.
        zcl_abapgit_git_commit=>extract_author_data(
          '<pull[bot]()> <39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000' ).
      CATCH zcx_abapgit_exception.
        cl_abap_unit_assert=>fail( |Value should be valid though brackets are in author name.| ).
    ENDTRY.
  ENDMETHOD.
 
ENDCLASS.