@Test
    public void testCloseBeforeThrows() {
        IdempotentCloser ic = new IdempotentCloser();

        // Verify initial invariants.
        assertFalse(ic.isClosed());

        // maybeThrowIllegalStateException doesn't throw anything since the closer is still in its "open" state.
        assertDoesNotThrow(() -> ic.assertOpen(() -> "test"));

        // Post-close, our call to maybeThrowIllegalStateException will, in fact, throw said exception.
        ic.close();
        assertTrue(ic.isClosed());
        assertThrows(IllegalStateException.class, () -> ic.assertOpen(() -> "test"));
    }
Tests that the {@link IdempotentCloser#assertOpen(String)} method will not throw an
exception if the closer is in the "open" state, but if invoked after it's in the "closed" state, it will
throw the exception.
clients/src/test/java/org/apache/kafka/common/internals/IdempotentCloserTest.java