### Question:
SqlQueryParser implements QueryParser { protected Constraint parsePropertyExistance( TokenStream tokens, TypeSystem typeSystem, Source source ) { if (tokens.matches(ANY_VALUE, ".", ANY_VALUE, "IS", "NOT", "NULL") || tokens.matches(ANY_VALUE, ".", ANY_VALUE, "IS", "NULL") || tokens.matches(ANY_VALUE, "IS", "NOT", "NULL") || tokens.matches(ANY_VALUE, "IS", "NULL")) { Position pos = tokens.nextPosition(); String firstWord = tokens.consume(); SelectorName selectorName = null; String propertyName = null; if (tokens.canConsume('.')) { selectorName = new SelectorName(firstWord); propertyName = parseName(tokens, typeSystem); } else { if (!(source instanceof Selector)) { String msg = GraphI18n.mustBeScopedAtLineAndColumn.text(firstWord, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } selectorName = ((Selector)source).name(); propertyName = parseName(firstWord, typeSystem); } if (tokens.canConsume("IS", "NOT", "NULL")) { return propertyExistence(selectorName, propertyName); } tokens.consume("IS", "NULL"); return not(propertyExistence(selectorName, propertyName)); } return null; }  String getLanguage(); @Override String toString(); @Override boolean equals( Object obj ); QueryCommand parseQuery( String query,
                                    TypeSystem typeSystem ); static final String LANGUAGE; }### Answer:
@Test public void shouldParsePropertyExistanceFromPropertyNameWithSelectorNameAndPropertyNameFollowedByIsNotNull() { Constraint constraint = parser.parsePropertyExistance(tokens("tableA.property1 IS NOT NULL"), typeSystem, mock(Source.class)); assertThat(constraint, is(instanceOf(PropertyExistence.class))); PropertyExistence p = (PropertyExistence)constraint; assertThat(p.propertyName(), is("property1")); assertThat(p.selectorName(), is(selectorName("tableA"))); }
@Test public void shouldParsePropertyExistanceFromPropertyNameWithPropertyNameAndNoSelectorNameFollowedByIsNotNull() { NamedSelector source = new NamedSelector(selectorName("tableA")); Constraint constraint = parser.parsePropertyExistance(tokens("property1 IS NOT NULL"), typeSystem, source); assertThat(constraint, is(instanceOf(PropertyExistence.class))); PropertyExistence p = (PropertyExistence)constraint; assertThat(p.propertyName(), is("property1")); assertThat(p.selectorName(), is(selectorName("tableA"))); }
@Test( expected = ParsingException.class ) public void shouldFailToParsePropertyExistanceFromPropertyNameWithNoSelectorNameIfSourceIsNotSelector() { parser.parsePropertyExistance(tokens("property1 IS NOT NULL"), typeSystem, mock(Source.class)); }
@Test public void shouldParseNotPropertyExistanceFromPropertyNameWithSelectorNameAndPropertyNameFollowedByIsNull() { Constraint constraint = parser.parsePropertyExistance(tokens("tableA.property1 IS NULL"), typeSystem, mock(Source.class)); assertThat(constraint, is(instanceOf(Not.class))); Not not = (Not)constraint; assertThat(not.constraint(), is(instanceOf(PropertyExistence.class))); PropertyExistence p = (PropertyExistence)not.constraint(); assertThat(p.propertyName(), is("property1")); assertThat(p.selectorName(), is(selectorName("tableA"))); }
@Test public void shouldReturnNullFromParsePropertyExistanceIfExpressionDoesNotMatchPattern() { Source s = mock(Source.class); assertThat(parser.parsePropertyExistance(tokens("tableA WILL NOT"), typeSystem, s), is(nullValue())); assertThat(parser.parsePropertyExistance(tokens("tableA.property1 NOT NULL"), typeSystem, s), is(nullValue())); assertThat(parser.parsePropertyExistance(tokens("tableA.property1 IS NOT SOMETHING"), typeSystem, s), is(nullValue())); }