public void unregisterAndCloseAll(Closeable... toUnregisterAndClose) throws IOException {
        IOException suppressed = null;
        for (Closeable closeable : toUnregisterAndClose) {
            if (unregisterCloseable(closeable)) {
                try {
                    closeable.close();
                } catch (IOException ex) {
                    suppressed = ExceptionUtils.firstOrSuppressed(ex, suppressed);
                }
            }
        }

        if (suppressed != null) {
            throw suppressed;
        }
    }
@Test
    void testUnregisterAndCloseAll() throws IOException {
        try (CloseableRegistry closeableRegistry = new CloseableRegistry()) {

            int exTestSize = 5;
            int nonExTestSize = 5;

            List<TestClosable> registeredClosableList = new ArrayList<>(exTestSize + nonExTestSize);
            for (int i = 0; i < nonExTestSize; ++i) {
                registeredClosableList.add(new TestClosable());
            }

            unregisterAndCloseAllHelper(registeredClosableList, closeableRegistry, null);

            for (int i = 0; i < exTestSize; ++i) {
                // Register with exception messages from 1..6
                registeredClosableList.add(new TestClosable(String.valueOf(1 + i)));
            }

            unregisterAndCloseAllHelper(
                    registeredClosableList,
                    closeableRegistry,
                    ioex -> {
                        // Check that error messages and suppressed exceptions are correctly
                        // reported
                        int checksum = 0;
                        checksum += Integer.parseInt(ioex.getMessage());
                        Throwable[] suppressed = ioex.getSuppressed();
                        for (Throwable throwable : suppressed) {
                            checksum += Integer.parseInt(throwable.getMessage());
                        }
                        // Checksum is sum from 1..6 = 15
                        assertThat(checksum).isEqualTo(15);
                    });

            // Check that unregistered Closable isn't closed.
            TestClosable unregisteredClosable = new TestClosable();
            closeableRegistry.unregisterAndCloseAll(unregisteredClosable);
            assertThat(unregisteredClosable.getCallsToClose()).isZero();
        }
    }