XPathParser { protected DocumentTest parseDocumentTest( TokenStream tokens ) { if (tokens.canConsume("document-node", "(")) { ElementTest elementTest = parseElementTest(tokens); DocumentTest result = null; if (elementTest != null) { result = new DocumentTest(elementTest); } else { SchemaElementTest schemaTest = parseSchemaElementTest(tokens); result = schemaTest != null ? new DocumentTest(schemaTest) : null; } tokens.consume(")"); return result; } return null; } XPathParser( TypeSystem context ); Component parseXPath( String xpath );  }
@Test public void shouldParseDocumentTest() { DocumentTest result = parser.parseDocumentTest(tokenize("document-node(element(foo:bar))")); assertThat(result, is(notNullValue())); assertThat(result.getElementTest().getElementName(), is(nameTest("foo", "bar"))); assertThat(result.getElementTest().getTypeName(), is(wildcard())); assertThat(result.getSchemaElementTest(), is(nullValue())); result = parser.parseDocumentTest(tokenize("document-node(schema-element(foo))")); assertThat(result, is(notNullValue())); assertThat(result.getSchemaElementTest().getElementDeclarationName(), is(nameTest("foo"))); assertThat(result.getElementTest(), is(nullValue())); }
@Test public void shouldReturnNullFromParseDocumentTestIfOpenParenthesisIsNotIncluded() { assertThat(parser.parseDocumentTest(tokenize("document-node foo")), is(nullValue())); assertThat(parser.parseDocumentTest(tokenize("document-node foo")), is(nullValue())); }
@Test( expected = ParsingException.class ) public void shouldFailToParseDocumentTestIfDocumentNodeDoesNotContainElementOrSchemaElement() { parser.parseDocumentTest(tokenize("document-node(foo)")); }