@Override
    public Predicate visit(AndPredicate andPredicate, IndexRegistry indexes) {
        Predicate[] originalPredicates = andPredicate.predicates;
        List<Predicate> toBeAdded = null;
        boolean modified = false;
        Predicate[] target = originalPredicates;
        for (int i = 0; i < target.length; i++) {
            Predicate predicate = target[i];
            if (predicate instanceof AndPredicate andPredicateInstance) {
                Predicate[] subPredicates = andPredicateInstance.predicates;
                if (!modified) {
                    modified = true;
                    target = createCopy(target);
                }
                toBeAdded = replaceFirstAndStoreOthers(target, subPredicates, i, toBeAdded);
            }
        }
        Predicate[] newInners = createNewInners(target, toBeAdded);
        if (newInners == originalPredicates) {
            return andPredicate;
        }
        return new AndPredicate(newInners);
    }
@Test
    public void visitNotPredicate_whenContainsNegatablePredicate_thenFlattenIt() {
        // (not(equals(foo, 1)))  -->  (notEquals(foo, 1))

        Predicate negated = mock(Predicate.class);
        NegatablePredicate negatablePredicate = mock(NegatablePredicate.class, withSettings().extraInterfaces(Predicate.class));
        when(negatablePredicate.negate()).thenReturn(negated);

        NotPredicate outerPredicate = (NotPredicate) not((Predicate) negatablePredicate);

        Predicate result = visitor.visit(outerPredicate, indexes);
        assertEquals(negated, result);
    }