All files / src/xml zcl_abapgit_xml_pretty.clas.testclasses.abap

35.18% Statements 38/108
100% Branches 0/0
0% Functions 0/7
35.18% Lines 38/108

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 1091x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
    DATA:
      mo_cut TYPE REF TO zcl_abapgit_xml_pretty.
 
    METHODS:
      setup,
      pretty1 FOR TESTING RAISING cx_static_check,
      pretty2 FOR TESTING RAISING cx_static_check,
      pretty3 FOR TESTING RAISING cx_static_check,
      malformatted FOR TESTING RAISING cx_static_check,
      dont_ignore_error FOR TESTING RAISING cx_static_check,
      unpretty FOR TESTING RAISING cx_static_check.
 
ENDCLASS.
 
 
CLASS ltcl_test IMPLEMENTATION.
 
  METHOD setup.
    CREATE OBJECT mo_cut.
  ENDMETHOD.
 
  METHOD pretty1.

    DATA lv_result TYPE string.

    lv_result = mo_cut->print( '<foo></foo>' ).
    lv_result = lv_result+1.

    cl_abap_unit_assert=>assert_equals(
      act = lv_result
      exp = |<?xml version="1.0" encoding="utf-16"?>\n<foo/>\n| ).

  ENDMETHOD.
 
  METHOD pretty2.

    DATA lv_result TYPE string.

    lv_result = mo_cut->print( '<foo>2</foo>' ).
    lv_result = lv_result+1.

    cl_abap_unit_assert=>assert_equals(
      act = lv_result
      exp = |<?xml version="1.0" encoding="utf-16"?>\n<foo>2</foo>\n| ).

  ENDMETHOD.
 
  METHOD pretty3.

    DATA lv_result TYPE string.

    lv_result = mo_cut->print( '<foo><bar>2</bar></foo>' ).
    lv_result = lv_result+1.

    cl_abap_unit_assert=>assert_equals(
      act = lv_result
      exp = |<?xml version="1.0" encoding="utf-16"?>\n<foo>\n <bar>2</bar>\n</foo>\n| ).

  ENDMETHOD.
 
  METHOD malformatted.

    DATA lv_result TYPE string.

    lv_result = mo_cut->print( 'abc' ).

    cl_abap_unit_assert=>assert_equals(
      act = lv_result
      exp = 'abc' ).

  ENDMETHOD.
 
  METHOD dont_ignore_error.

    TRY.
        mo_cut->print(
          iv_xml           = 'abc'
          iv_ignore_errors = abap_false ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception.
        RETURN.
    ENDTRY.

  ENDMETHOD.
 
  METHOD unpretty.

    DATA lv_result TYPE string.

    lv_result = mo_cut->print(
      iv_xml      = |<foo>\n <bar>2</bar>\n</foo>|
      iv_unpretty = abap_true ).

    lv_result = lv_result+1.

    cl_abap_unit_assert=>assert_equals(
      act = lv_result
      exp = |<?xml version="1.0" encoding="utf-16"?><foo><bar>2</bar></foo>| ).

  ENDMETHOD.
 
ENDCLASS.