  @Test
  void cleanIdempotent() {

    long rawNativeHandle = 1L;
    NativeHandle handle = spy(new NativeHandle(rawNativeHandle));
    LongConsumer destructor = mock(LongConsumer.class);

    ProxyDestructor d = newDestructor(handle, destructor);

    // Clean multiple times.
    int attemptsToClean = 3;
    for (int i = 0; i < attemptsToClean; i++) {
      d.clean();
    }

    assertFalse(handle.isValid());

    // Verify that the expected interactions happened exactly once.
    verify(handle).close();
    verify(destructor).accept(rawNativeHandle);
  }