### Question:
RootNegationCheckVisitor { public static Boolean hasTopLevelNegation(JexlNode script) { RootNegationCheckVisitor visitor = new RootNegationCheckVisitor(); JexlNode pushedDownTree = PushdownNegationVisitor.pushdownNegations(script); return !visitor.hasLeafWithoutNegation(pushedDownTree); }  static Boolean hasTopLevelNegation(JexlNode script);  }### Answer:
@Test public void testNEq() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("FOO != 'bar'"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testWrappedNegation() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!(FOO == 'bar')"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testEq() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("FOO == 'bar'"); Assert.assertFalse(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testWrappedNEq() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!(FOO != 'bar')"); Assert.assertFalse(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testNegatedAnd() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!(FOO == 'bar' && FOO == 'baz')"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testNegatedOneLeafAnd() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!(FOO != 'bar' && FOO == 'baz')"); Assert.assertFalse(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testNegatedMarker() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("((ASTDelayedPredicate = true) && !(FOO == 'bar' && FOO == 'baz'))"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testWrappedNegatedMarker() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!((ASTDelayedPredicate = true) && (FOO == 'bar' && FOO == 'baz'))"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testNegatedMarkerOneLeaf() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("((ASTDelayedPredicate = true) && !(FOO != 'bar' && FOO == 'baz'))"); Assert.assertFalse(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testNR() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("FOO !~ 'bar.*'"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testWrappedER() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!(FOO =~ 'bar.*')"); Assert.assertTrue(RootNegationCheckVisitor.hasTopLevelNegation(script)); }
@Test public void testDoubleNegatedNR() throws ParseException { ASTJexlScript script = JexlASTHelper.parseJexlQuery("!(FOO !~ 'bar.*')"); Assert.assertFalse(RootNegationCheckVisitor.hasTopLevelNegation(script)); }