// Path: src/main/java/com/github/phantomthief/failover/util/SharedResource.java
// public static class UnregisterFailedException extends RuntimeException {
// 
//     private final Object removed;
// 
//     private UnregisterFailedException(Throwable cause, Object removed) {
//         super(cause);
//         this.removed = removed;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <T> T getRemoved() {
//         return (T) removed;
//     }
// }


import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.failover.util.SharedResource.UnregisterFailedException;
        MockResource mockResource1 = resources.get("1");
        MockResource mockResource2 = resources.get("1");
        assertNotNull(mockResource1);
        assertSame(mockResource1, mockResource2);
        assertFalse(mockResource1.isShutdown());

        resources.unregister("1", MockResource::close);
        mockResource1 = resources.get("1");
        assertNotNull(mockResource1);
        assertFalse(mockResource1.isShutdown());

        resources.unregister("1", MockResource::close);
        assertTrue(mockResource1.isShutdown());
        mockResource1 = resources.get("1");
        assertNull(mockResource1);
    }

    @Test
    void testUnpairUnregister() {
        resources.register("3", MockResource::new);
        MockResource mock = resources.get("3");
        assertSame(mock, resources.unregister("3", MockResource::close));
        assertThrows(IllegalStateException.class,
                () -> resources.unregister("3", MockResource::close));
    }

    @Test
    void testCleanupFailed() {
        resources.register("4", MockResource::new);
        MockResource mock = resources.get("4");
// Path: src/main/java/com/github/phantomthief/failover/util/SharedResource.java
// public static class UnregisterFailedException extends RuntimeException {
// 
//     private final Object removed;
// 
//     private UnregisterFailedException(Throwable cause, Object removed) {
//         super(cause);
//         this.removed = removed;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <T> T getRemoved() {
//         return (T) removed;
//     }
// }


// Path: src/test/java/com/github/phantomthief/failover/util/SharedResourceTest.java
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.failover.util.SharedResource.UnregisterFailedException;

        MockResource mockResource1 = resources.get("1");
        MockResource mockResource2 = resources.get("1");
        assertNotNull(mockResource1);
        assertSame(mockResource1, mockResource2);
        assertFalse(mockResource1.isShutdown());

        resources.unregister("1", MockResource::close);
        mockResource1 = resources.get("1");
        assertNotNull(mockResource1);
        assertFalse(mockResource1.isShutdown());

        resources.unregister("1", MockResource::close);
        assertTrue(mockResource1.isShutdown());
        mockResource1 = resources.get("1");
        assertNull(mockResource1);
    }

    @Test
    void testUnpairUnregister() {
        resources.register("3", MockResource::new);
        MockResource mock = resources.get("3");
        assertSame(mock, resources.unregister("3", MockResource::close));
        assertThrows(IllegalStateException.class,
                () -> resources.unregister("3", MockResource::close));
    }

    @Test
    void testCleanupFailed() {
        resources.register("4", MockResource::new);
        MockResource mock = resources.get("4");
        UnregisterFailedException e = assertThrows(UnregisterFailedException.class,