You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/11/25 18:49:31 UTC
[commons-vfs] 02/02: Use try-with-resources
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
commit 432aeb6f84c56d229667f3453f40337756f1ddb5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 25 13:49:24 2022 -0500
Use try-with-resources
---
.../vfs2/operations/BasicOperationsTest.java | 42 ++++++++++++----------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/operations/BasicOperationsTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/operations/BasicOperationsTest.java
index 04a6f9ec..96034289 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/operations/BasicOperationsTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/operations/BasicOperationsTest.java
@@ -69,6 +69,7 @@ public class BasicOperationsTest {
/** This FileOperationsProvider is no VfsComponent. */
static class MyFileOperationProviderNoncomp extends MyFileOperationProviderBase {
+ // empty
}
/**
@@ -106,6 +107,7 @@ public class BasicOperationsTest {
@BeforeEach
public void setUp() throws FileSystemException {
manager = new DefaultFileSystemManager();
+ @SuppressWarnings("resource") // manager is closed on @AfterEach
final FileProvider fp = new DefaultLocalFileProvider();
manager.addProvider("file", fp);
manager.init();
@@ -129,13 +131,13 @@ public class BasicOperationsTest {
*/
@Test
public void testLifecycleComp() throws FileSystemException {
- final MyFileOperationProviderBase myop = new MyFileOperationProviderComp();
- assertEquals(0, myop.ops);
- manager.addOperationProvider("file", myop);
- assertEquals(7, myop.ops);
- manager.close();
- assertEquals(15, myop.ops, "close() not called"); // VFS-577
-
+ try (final MyFileOperationProviderComp myop = new MyFileOperationProviderComp()) {
+ assertEquals(0, myop.ops);
+ manager.addOperationProvider("file", myop);
+ assertEquals(7, myop.ops);
+ manager.close();
+ assertEquals(15, myop.ops, "close() not called"); // VFS-577
+ }
// fixture will close again
}
@@ -163,14 +165,15 @@ public class BasicOperationsTest {
public void testNotFoundAny() throws FileSystemException {
final MyFileOperationProviderBase myop = new MyFileOperationProviderNoncomp();
manager.addOperationProvider("file", myop);
- final FileObject fo = manager.toFileObject(new File("."));
+ try (final FileObject fo = manager.toFileObject(new File("."))) {
- final FileOperations ops = fo.getFileOperations();
- assertNotNull(ops);
+ final FileOperations ops = fo.getFileOperations();
+ assertNotNull(ops);
- final Class<? extends FileOperation>[] oparray = ops.getOperations();
- assertSame(0, oparray.length, "no ops should be found");
- assertSame(16, myop.ops); // collect
+ final Class<? extends FileOperation>[] oparray = ops.getOperations();
+ assertSame(0, oparray.length, "no ops should be found");
+ assertSame(16, myop.ops); // collect
+ }
}
/**
@@ -182,14 +185,15 @@ public class BasicOperationsTest {
public void testNotFoundOperation() throws FileSystemException {
final MyFileOperationProviderBase myop = new MyFileOperationProviderNoncomp();
manager.addOperationProvider("file", myop);
- final FileObject fo = manager.toFileObject(new File("."));
+ try (final FileObject fo = manager.toFileObject(new File("."))) {
- final FileOperations ops = fo.getFileOperations();
- assertNotNull(ops);
+ final FileOperations ops = fo.getFileOperations();
+ assertNotNull(ops);
- FileSystemException thrown = assertThrows(FileSystemException.class, () -> ops.getOperation(VcsLog.class));
- assertEquals("vfs.operation/operation-not-supported.error", thrown.getCode());
- assertSame(32, myop.ops); // getOperation was called
+ FileSystemException thrown = assertThrows(FileSystemException.class, () -> ops.getOperation(VcsLog.class));
+ assertEquals("vfs.operation/operation-not-supported.error", thrown.getCode());
+ assertSame(32, myop.ops); // getOperation was called
+ }
}
}