@Test
    public void testCloseOperationOnSingleSeq() {
        Consumer<Function<Seq<Integer>, Seq<?>>> test = f -> {
            AtomicBoolean closed1 = new AtomicBoolean();
            
            Seq<Integer> s1 = seq(Stream.of(1, 2).onClose(() -> closed1.set(true)));
            
            try (Seq<?> s2 = f.apply(s1)) {
                s2.limit(1000).collect(Collectors.toList());
            }

            assertTrue(closed1.get());
        };
        
        test.accept(s1 -> s1);
        test.accept(s1 -> s1.onEmpty(1));
        test.accept(s1 -> s1.remove(1));
        test.accept(s1 -> s1.removeAll(1, 2));
        test.accept(s1 -> s1.retainAll(1, 2));
        test.accept(s1 -> s1.cycle());
        test.accept(s1 -> s1.cycle(5));
        test.accept(s1 -> s1.distinct(i -> i));
        test.accept(s1 -> s1.zipWithIndex());
        test.accept(s1 -> s1.scanLeft(0, (a, b) -> a + b));
        test.accept(s1 -> s1.scanRight(0, (a, b) -> a + b));
        test.accept(s1 -> s1.reverse());
        test.accept(s1 -> s1.shuffle());
        test.accept(s1 -> s1.skipWhile(a -> true));
        test.accept(s1 -> s1.skipWhileClosed(a -> true));
        test.accept(s1 -> s1.skipUntil(a -> true));
        test.accept(s1 -> s1.skipUntilClosed(a -> true));
        test.accept(s1 -> s1.limitWhile(a -> true));
        test.accept(s1 -> s1.limitWhileClosed(a -> true));
        test.accept(s1 -> s1.limitUntil(a -> true));
        test.accept(s1 -> s1.limitUntilClosed(a -> true));
        test.accept(s1 -> s1.intersperse(0));
        test.accept(s1 -> s1.grouped(i -> i));
        test.accept(s1 -> s1.slice(0, 1));
        test.accept(s1 -> s1.sorted(i -> i));
        test.accept(s1 -> s1.ofType(Number.class));
        test.accept(s1 -> s1.cast(Number.class));
        test.accept(s1 -> s1.sliding(1));
        test.accept(s1 -> s1.window());
    }
@author Lukas Eder
@author Roman Tkalenko
jOOL-java-8/src/test/java/org/jooq/lambda/SeqTest.java