package org.javarosa.core.model.test;

import org.javarosa.core.test.FormParseInit;
import org.javarosa.xform.parse.XFormParseException;
import org.junit.Test;

import static org.junit.Assert.fail;

/**
 * Tests for cyclic references
 *
 * @author wpride
 */

public class CyclicReferenceTests {
    /**
     * Test that XPath cyclic reference that references parent throws usable error
     */
    @Test
    public void testCyclicReferenceWithGroup() {
        try {
            new FormParseInit("/xform_tests/group_cyclic_reference.xml");
        } catch (XFormParseException e) {
            String detailMessage = e.getMessage();
            // Assert that we're using the shortest cycle algorithm
            assert detailMessage.contains("Shortest Cycle");
            // There should only be three newlines since only the three core cyclic references were included
            int newlineCount = detailMessage.length() - detailMessage.replace("\n", "").length();
            assert newlineCount == 3;
            return;
        }
        fail("Cyclical reference did not throw XFormParseException");
    }
}

@@ -150,24 +150,67 @@
 unit.Test;%0A%0A
+import static org.junit.Assert.assertTrue;%0A
 import stati
@@ -757,17 +757,21 @@
   assert
- 
+True(
 detailMe
@@ -802,16 +802,17 @@
  Cycle%22)
+)
 ;%0A      
@@ -1030,17 +1030,21 @@
   assert
- 
+True(
 newlineC
@@ -1052,16 +1052,17 @@
 unt == 3
+)
 ;%0A      

assert -> Assert.assertTrue