All files / src/repo/utils zcl_abapgit_version.clas.testclasses.abap

100% Statements 84/84
100% Branches 3/3
100% Functions 3/3
100% Lines 84/84

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 851x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_version DEFINITION DEFERRED.
CLASS zcl_abapgit_version DEFINITION LOCAL FRIENDS ltcl_version.
 
CLASS ltcl_version DEFINITION FINAL FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
 
  PRIVATE SECTION.
 
    METHODS:
      version_to_numeric FOR TESTING,
      compare            FOR TESTING,
      normalize          FOR TESTING.
 
ENDCLASS.
 
CLASS ltcl_version IMPLEMENTATION.
 
  METHOD version_to_numeric.
 
    DATA: lv_version_exp TYPE i VALUE 1023010,
          lv_version_act TYPE i.
 
    lv_version_act = zcl_abapgit_version=>version_to_numeric( '1.23.10' ).
 
    cl_abap_unit_assert=>assert_equals( exp = lv_version_exp
                                        act = lv_version_act
                                        msg = ' Error during conversion of version to numeric value' ).
 
  ENDMETHOD.
 
  METHOD compare.
 
    DATA lv_result TYPE i.
 
    " Case 1: version A > version B
    lv_result = zcl_abapgit_version=>compare( iv_a = '1.28.10'
                                              iv_b = '1.23.10' ).
 
    cl_abap_unit_assert=>assert_equals( exp = 1
                                        act = lv_result
                                        msg = ' Error during comparison of versions. Case: A > B' ).
 
    CLEAR: lv_result.
 
    " Case 2: version A < version B
    lv_result = zcl_abapgit_version=>compare( iv_a = '1.28.10'
                                              iv_b = '2.23.10' ).
 
    cl_abap_unit_assert=>assert_equals( exp = -1
                                        act = lv_result
                                        msg = ' Error during comparison of versions. Case: A < B' ).
 
    CLEAR: lv_result.
 
    " Case 3: version A = version B
    lv_result = zcl_abapgit_version=>compare( iv_a = '1.28.10'
                                              iv_b = '1.28.10' ).
 
    cl_abap_unit_assert=>assert_equals( exp = 0
                                        act = lv_result
                                        msg = ' Error during comparison of versions. Case: A = B' ).
 
  ENDMETHOD.
 
  METHOD normalize.
 
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_version=>normalize( '1.28.10' )
      exp = '1.28.10' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_version=>normalize( 'v1.28.10' )
      exp = '1.28.10' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_version=>normalize( 'b1.28.10' )
      exp = '' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_version=>normalize( 'x.y.z' )
      exp = '' ).
 
  ENDMETHOD.
 
ENDCLASS.