}
@Test
void testCloserClosingState() throws InterruptedException {
Injector i = createInjector();
final Closer closer = i.getInstance(Closer.class);
final CountDownLatch closeDone = new CountDownLatch(1);
final CountDownLatch closeStart = new CountDownLatch(1);
closer.addToClose(new Closeable() {
@Override
public void close() throws IOException {
try {
closeStart.countDown();
assert closer.getState() == Closer.State.PROCESSING;
closeDone.await();
} catch (InterruptedException e) {
assert false : e.getMessage();
}
}
});
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
closer.close();
} catch (IOException e) {
assert false : e.getMessage();
}
}
});
thread.start();
closeStart.await();
assert closer.getState() == Closer.State.PROCESSING;
closeDone.countDown();
thread.join();
assert closer.getState() == Closer.State.DONE;
}