Changed the test to use try-with-resources.