super.tearDown()
method that are not performed inside a finally
block.
If there are other method calls in the tearDown()
method that may throw
an exception before the super.tearDown()
call, this may lead to inconsistencies and leaks.
Example:
public class AnotherTest extends CompanyTestCase {
private Path path;
@Override
protected void setUp() throws Exception {
super.setUp();
path = Files.createTempFile("abcde", ".tmp");
}
@Override
protected void tearDown() throws Exception {
Files.delete(path);
super.tearDown();
}
}
Improved code:
public class AnotherTest extends CompanyTestCase {
private Path path;
@Override
protected void setUp() throws Exception {
super.setUp();
path = Files.createTempFile("abcde", ".tmp");
}
@Override
protected void tearDown() throws Exception {
try {
Files.delete(path);
} finally {
super.tearDown();
}
}
}