@Override
    public Predicate accept(Visitor visitor, IndexRegistry indexes) {
        Predicate[] result = VisitorUtils.acceptVisitor(predicates, visitor, indexes);
        if (result != predicates) {
            //inner predicates were modified by a visitor
            AndPredicate newPredicate = new AndPredicate(result);
            return visitor.visit(newPredicate, indexes);
        }
        return visitor.visit(this, indexes);
    }
@Test
    public void accept_whenVisitorReturnsNewInstance_thenReturnTheNewInstance() {
        Predicate delegate = mock(Predicate.class);
        Visitor mockVisitor = createDelegatingVisitor(delegate);
        IndexRegistry mockIndexes = mock(IndexRegistry.class);
        Predicate innerPredicate = mock(Predicate.class);
        Predicate[] innerPredicates = new Predicate[1];
        innerPredicates[0] = innerPredicate;

        AndPredicate andPredicate = new AndPredicate(innerPredicates);
        Predicate result = andPredicate.accept(mockVisitor, mockIndexes);

        assertThat(result).isSameAs(delegate);
    }