@Test
void testChainedStreams() {

    // This test makes sure that "chained" streams gets closed all the way up to the "root"
    final AtomicBoolean fClosed = new AtomicBoolean();
    final Stream<String> f = StreamComposition.concatAndAutoClose(
            Stream.of("F").onClose(() -> fClosed.set(true))
    );
    List<Integer> result = f
            .mapToInt(String::length)
            .boxed()
            .mapToLong(l -> l)
            .mapToInt((long l) -> (int) l)
            .boxed()
            .collect(toList());
    assertEquals(Collections.singletonList(1), result);
    assertTrue(fClosed.get());
}