You're not testing that the app closes the bean, you're testing that the bean closes properly when closed. If the implementation is non-trivial, then you should write a test for that behaviour. If all your method does is call close on a single field then don't bother testing it. However, if your close method calls close on multiple fields or does something a bit more complicated then you should test it.
For instance, given the following Closer
class that must close all its Reader
s when it is closed...
public class Closer implements AutoCloseable {
private Reader[] readers;
public Closer(Reader... readers) {
this.readers = readers;
}
@Override
public void close() {
try {
for (Reader reader : readers) {
reader.close();
}
} catch (IOException ex) {
// ignore
}
}
}
You may wish to test as such:
public class CloserTest {
@Test
public void allReadersClosedWhenOneReaderThrowsException() {
// given
Reader badReader = mock(Reader.class);
Reader secondReader = mock(Reader.class);
doThrow(new IOException()).when(badReader).close();
Closer closer = new Closer(badReader, secondReader);
// when
closer.close();
// then
verify(badReader).close();
verify(secondReader).close(); // fails as loop stops on first exception
}
}
Excessively high code coverage can be a bad thing if it means that your unit tests contain large amounts of trivial tests, especially if those tests are fragile. They will increase the amount of effort required to maintain the unit tests, without actually adding anything.