@Test public void testVisit() { ResourceProvider provider = createStrictMock(ResourceProvider.class); Capture<Set<String>> propertiesCapture = EasyMock.newCapture(); SimplifyingPredicateVisitor visitor = new SimplifyingPredicateVisitor(provider); expect(provider.checkPropertyIds(capture(propertiesCapture))).andReturn(Collections.<String>emptySet()).anyTimes(); replay(provider); PredicateHelper.visit(PREDICATE_1, visitor); List<Predicate> simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(1, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(0)); Set<String> setProps = propertiesCapture.getValue(); assertEquals(1, setProps.size()); assertEquals(PROPERTY_A, setProps.iterator().next()); PredicateHelper.visit(PREDICATE_3, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(1, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_3, simplifiedPredicates.get(0)); PredicateHelper.visit(PREDICATE_4, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(2, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(0)); Assert.assertEquals(PREDICATE_2, simplifiedPredicates.get(1)); PredicateHelper.visit(PREDICATE_6, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(3, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_5, simplifiedPredicates.get(0)); Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(1)); Assert.assertEquals(PREDICATE_2, simplifiedPredicates.get(2)); PredicateHelper.visit(PREDICATE_8, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(4, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_5, simplifiedPredicates.get(0)); Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(1)); Assert.assertEquals(PREDICATE_2, simplifiedPredicates.get(2)); Assert.assertEquals(PREDICATE_7, simplifiedPredicates.get(3)); PredicateHelper.visit(PREDICATE_9, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(4, simplifiedPredicates.size()); PredicateHelper.visit(PREDICATE_11, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(4, simplifiedPredicates.size()); PredicateHelper.visit(PREDICATE_16, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(1, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_16, simplifiedPredicates.get(0)); verify(provider); reset(provider); expect(provider.checkPropertyIds(capture(propertiesCapture))).andReturn(Collections.<String>emptySet()); expect(provider.checkPropertyIds(capture(propertiesCapture))).andReturn(Collections.<String>singleton(PROPERTY_D)); replay(provider); PredicateHelper.visit(PREDICATE_13, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(1, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(0)); verify(provider); reset(provider); expect(provider.checkPropertyIds(capture(propertiesCapture))).andReturn(Collections.<String>emptySet()).anyTimes(); replay(provider); PredicateHelper.visit(PREDICATE_15, visitor); simplifiedPredicates = visitor.getSimplifiedPredicates(); Assert.assertEquals(1, simplifiedPredicates.size()); Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(0)); verify(provider); }
public List<Predicate> getSimplifiedPredicates() { if (lastVisited == null) { return Collections.emptyList(); } if (lastVisited instanceof OrPredicate) { return Arrays.asList(((OrPredicate) lastVisited).getPredicates()); } return Collections.singletonList(lastVisited); }
SimplifyingPredicateVisitor implements PredicateVisitor { public List<Predicate> getSimplifiedPredicates() { if (lastVisited == null) { return Collections.emptyList(); } if (lastVisited instanceof OrPredicate) { return Arrays.asList(((OrPredicate) lastVisited).getPredicates()); } return Collections.singletonList(lastVisited); } }
SimplifyingPredicateVisitor implements PredicateVisitor { public List<Predicate> getSimplifiedPredicates() { if (lastVisited == null) { return Collections.emptyList(); } if (lastVisited instanceof OrPredicate) { return Arrays.asList(((OrPredicate) lastVisited).getPredicates()); } return Collections.singletonList(lastVisited); } SimplifyingPredicateVisitor(ResourceProvider provider); }
SimplifyingPredicateVisitor implements PredicateVisitor { public List<Predicate> getSimplifiedPredicates() { if (lastVisited == null) { return Collections.emptyList(); } if (lastVisited instanceof OrPredicate) { return Arrays.asList(((OrPredicate) lastVisited).getPredicates()); } return Collections.singletonList(lastVisited); } SimplifyingPredicateVisitor(ResourceProvider provider); List<Predicate> getSimplifiedPredicates(); @Override void acceptComparisonPredicate(ComparisonPredicate predicate); @Override void acceptArrayPredicate(ArrayPredicate arrayPredicate); @Override void acceptUnaryPredicate(UnaryPredicate predicate); @Override void acceptAlwaysPredicate(AlwaysPredicate predicate); @Override void acceptCategoryPredicate(CategoryPredicate predicate); }
SimplifyingPredicateVisitor implements PredicateVisitor { public List<Predicate> getSimplifiedPredicates() { if (lastVisited == null) { return Collections.emptyList(); } if (lastVisited instanceof OrPredicate) { return Arrays.asList(((OrPredicate) lastVisited).getPredicates()); } return Collections.singletonList(lastVisited); } SimplifyingPredicateVisitor(ResourceProvider provider); List<Predicate> getSimplifiedPredicates(); @Override void acceptComparisonPredicate(ComparisonPredicate predicate); @Override void acceptArrayPredicate(ArrayPredicate arrayPredicate); @Override void acceptUnaryPredicate(UnaryPredicate predicate); @Override void acceptAlwaysPredicate(AlwaysPredicate predicate); @Override void acceptCategoryPredicate(CategoryPredicate predicate);  }