XPathParser { protected ElementTest parseElementTest( TokenStream tokens ) { if (tokens.canConsume("element", "(")) { if (tokens.canConsume(")") || tokens.canConsume("*", ")")) { return new ElementTest(new NameTest(null, null), new NameTest(null, null)); } ElementTest result = null; NameTest elementName = parseNameTest(tokens); if (tokens.canConsume(",")) { NameTest typeName = parseNameTest(tokens); result = new ElementTest(elementName, typeName); tokens.canConsume('?'); } else { result = new ElementTest(elementName, new NameTest(null, null)); } tokens.consume(")"); return result; } return null; } XPathParser( TypeSystem context ); Component parseXPath( String xpath );  }
@Test public void shouldParseElementTest() { ElementTest result = parser.parseElementTest(tokenize("element(foo)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(nameTest("foo"))); assertThat(result.getTypeName(), is(wildcard())); result = parser.parseElementTest(tokenize("element(foo:bar)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(nameTest("foo", "bar"))); assertThat(result.getTypeName(), is(wildcard())); result = parser.parseElementTest(tokenize("element(foo:bar,baz)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(nameTest("foo", "bar"))); assertThat(result.getTypeName(), is(nameTest("baz"))); result = parser.parseElementTest(tokenize("element(foo:bar,baz:bam)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(nameTest("foo", "bar"))); assertThat(result.getTypeName(), is(nameTest("baz", "bam"))); result = parser.parseElementTest(tokenize("element(foo:bar,*)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(nameTest("foo", "bar"))); assertThat(result.getTypeName(), is(wildcard())); result = parser.parseElementTest(tokenize("element(*,foo:bar)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(wildcard())); assertThat(result.getTypeName(), is(nameTest("foo", "bar"))); result = parser.parseElementTest(tokenize("element(*,*)")); assertThat(result, is(notNullValue())); assertThat(result.getElementName(), is(wildcard())); assertThat(result.getTypeName(), is(wildcard())); }
@Test public void shouldReturnNullFromParseElementTestIfOpenParenthesisIsNotIncluded() { ElementTest result = parser.parseElementTest(tokenize("attribute foo")); assertThat(result, is(nullValue())); }