<?xml version="1.0" encoding="UTF-8"?>
<test-data
    xmlns="http://pmd.sourceforge.net/rule-tests"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">

    <code-fragment id="full-example"><![CDATA[
public class Foo {
  public static void bar() {
    boolean a, b = true;
    try { // 2 * 2 + 2
      if (true) { // 2
        List buz = new ArrayList();
      }

      for(int i = 0; i < 19; i++) { // 2
        List buz = new ArrayList();
      }
    } catch(Exception e) {
      if (true) { // 2
        e.printStackTrace();
      }
    }

    int j = 0;
    if (true || a && b) { // 4
      j = 10;
      return;
    }

    while (j++ < 20) { // 2
      List buz = new ArrayList();
    }

    switch(j) { // 7
      case 1:
      case 2: break;
      case 3: j = 5; break;
      case 4: if (b && a) { bar(); } break;
      default: break;
    }

    do { // 3
        List buz = new ArrayList();
    } while (a && j++ < 30);

    if (b) { // 2
      return;
    }
  }
}
     ]]></code-fragment>


    <test-code>
        <description>Full example</description>
        <expected-problems>1</expected-problems>
        <expected-messages>
            <message>The method 'bar()' has an NPath complexity of 2016</message>
        </expected-messages>
        <code-ref id="full-example"/>
    </test-code>


    <test-code>
        <description>Test default report level - report 200</description>
        <rule-property name="reportLevel">0</rule-property>
        <expected-problems>1</expected-problems>
        <expected-messages>
            <message>The method 'bar()' has an NPath complexity of 200</message>
        </expected-messages>
        <code><![CDATA[
        public class Foo {
          public static void bar() {
            boolean a, b = true;
            int j = 0;

            switch (j) { // 5
              case 0:
              case 1:
              case 3: if (a || b) {} break;
            }

            switch (j) { // * 5
              case 0:
              case 1:
              case 3: if (a || b) {} break;
            }

            if (true || a && b); // * 4
            while (j++ < 20);    // * 2
          }
        }
        ]]></code>
    </test-code>

    <test-code>
        <description>Test default report level - ignore 199</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
        class Foo {
          void bar() {
            boolean a, b;
            try {
              switch(j) { // 7
              case 1:
              case 2: break;
              case 3: j = 5; break;
              case 4: if (b && a) { bar(); } break;
              default: break;
              }

              switch(j) { // * 7
              case 1:
              case 2: break;
              case 3: j = 5; break;
              case 4: if (b && a) { bar(); } break;
              default: break;
              }

              if (true || a || b); // * 4

            } catch (ScaryException e) {
              if (true || a); // + 3
            }
          }
        }
        ]]></code>
    </test-code>

    <test-code>
        <description>Boolean operators</description>
        <rule-property name="reportLevel">2</rule-property>
        <expected-problems>1</expected-problems>
        <expected-messages>
            <message>The method 'bar()' has an NPath complexity of 4</message>
        </expected-messages>
        <code><![CDATA[
        class Foo {
          void bar() {
            if (a && b || c);
          }
        }
        ]]></code>
    </test-code>


    <code-fragment id="bug3484404"><![CDATA[
class Bar {
  public void x(boolean x, boolean y) {
    z((x ? 1 : 2), (y ? 3 : 4));
  }

  public int y(boolean x, boolean y) {
    return z((x ? 1 : 2), (y ? 3 : 4));
  }

  public int z(int x, int y) {
    return x + y;
  }
}
    ]]></code-fragment>

    <test-code>
        <description>test case for bug 3484404 (Invalid NPath calculation in return statement)</description>
        <rule-property name="reportLevel">4</rule-property>
        <expected-problems>2</expected-problems>
        <expected-messages>
            <message>The method 'x(boolean, boolean)' has an NPath complexity of 4</message>
            <message>The method 'y(boolean, boolean)' has an NPath complexity of 4</message>
        </expected-messages>
        <code-ref id="bug3484404"/>
    </test-code>


    <test-code>
        <description>NPath supports constructors</description>
        <rule-property name="reportLevel">6</rule-property>
        <expected-problems>1</expected-problems>
        <expected-messages>
            <message>The constructor 'Foo()' has an NPath complexity of 7</message>
        </expected-messages>
        <code><![CDATA[
        class Foo {
          Foo() {
            boolean a, b;
            int j = 23;
            switch(j) {
              case 1:
              case 2: break;
              case 3: j = 5; break;
              case 4: if (b && a) { bar(); } break;
              default: break;
            }
          }
        }
        ]]></code>
    </test-code>
    
    <test-code>
        <description>Backwards compatibility with minimum property</description>
        <rule-property name="minimum">300</rule-property>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
        class Foo {
          Foo() {
            boolean a, b;
            int j = 23;
            switch(j) {
              case 1:
              case 2: break;
              case 3: j = 5; break;
              case 4: if (b && a) { bar(); } break;
              default: break;
            }
          }
        }
        ]]></code>
    </test-code>
    
</test-data>
