|
@@ -85,16 +85,6 @@ public class SharedFileChannelTest {
|
|
verify(nioAccess).open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE);
|
|
verify(nioAccess).open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE);
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- public void testOpenIfClosedOpensAChannelIfChannelIsNotOpenOpenModeIsReadAndFileExists() throws IOException {
|
|
|
|
- when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
|
|
- when(nioAccess.isRegularFile(path)).thenReturn(true);
|
|
|
|
-
|
|
|
|
- inTest.openIfClosed(OpenMode.READ);
|
|
|
|
-
|
|
|
|
- verify(nioAccess).open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void testOpenOpensAChannelIfOpenModeIsWriteAndFileExists() throws IOException {
|
|
public void testOpenOpensAChannelIfOpenModeIsWriteAndFileExists() throws IOException {
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
@@ -128,41 +118,6 @@ public class SharedFileChannelTest {
|
|
inTest.open(OpenMode.WRITE);
|
|
inTest.open(OpenMode.WRITE);
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- public void testOpenFailsIfInvokedTwiceBeforeClose() {
|
|
|
|
- when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
|
|
- when(nioAccess.isRegularFile(path)).thenReturn(false);
|
|
|
|
-
|
|
|
|
- inTest.open(OpenMode.WRITE);
|
|
|
|
-
|
|
|
|
- thrown.expect(IllegalStateException.class);
|
|
|
|
- thrown.expectMessage("already open for current thread");
|
|
|
|
-
|
|
|
|
- inTest.open(OpenMode.WRITE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Test
|
|
|
|
- public void testOpenIfClosedDoesDoNothingIfInvokedOnOpenChannel() {
|
|
|
|
- when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
|
|
- when(nioAccess.isRegularFile(path)).thenReturn(false);
|
|
|
|
-
|
|
|
|
- inTest.open(OpenMode.WRITE);
|
|
|
|
-
|
|
|
|
- inTest.openIfClosed(OpenMode.READ);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Test
|
|
|
|
- public void testOpenWorksIfInvokedTwiceAfterClose() throws IOException {
|
|
|
|
- when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
|
|
- when(nioAccess.isRegularFile(path)).thenReturn(false);
|
|
|
|
- when(nioAccess.open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE)).thenReturn(mock(FileChannel.class));
|
|
|
|
-
|
|
|
|
- inTest.open(OpenMode.WRITE);
|
|
|
|
- inTest.close();
|
|
|
|
-
|
|
|
|
- inTest.open(OpenMode.WRITE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void testOpenDoesNotOpenChannelTwiceIfInvokedTwiceByDifferentThreads() throws IOException {
|
|
public void testOpenDoesNotOpenChannelTwiceIfInvokedTwiceByDifferentThreads() throws IOException {
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
@@ -182,16 +137,11 @@ public class SharedFileChannelTest {
|
|
@Test
|
|
@Test
|
|
public void testCloseIfNotOpenFails() {
|
|
public void testCloseIfNotOpenFails() {
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("Close without corresponding open");
|
|
|
|
|
|
inTest.close();
|
|
inTest.close();
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- public void testCloseIfOpenDoesNothingIfNotOpen() {
|
|
|
|
- inTest.closeIfOpen();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void testCloseIfClosedFails() throws IOException {
|
|
public void testCloseIfClosedFails() throws IOException {
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
@@ -201,7 +151,7 @@ public class SharedFileChannelTest {
|
|
inTest.close();
|
|
inTest.close();
|
|
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("Close without corresponding open");
|
|
|
|
|
|
inTest.close();
|
|
inTest.close();
|
|
}
|
|
}
|
|
@@ -257,19 +207,6 @@ public class SharedFileChannelTest {
|
|
inTest.close();
|
|
inTest.close();
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- public void testCloseIfOpenClosesChannelIfOpen() throws IOException {
|
|
|
|
- when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
|
|
- when(nioAccess.isRegularFile(path)).thenReturn(false);
|
|
|
|
- FileChannel channel = mock(FileChannel.class);
|
|
|
|
- when(nioAccess.open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE)).thenReturn(channel);
|
|
|
|
- inTest.open(OpenMode.WRITE);
|
|
|
|
-
|
|
|
|
- inTest.closeIfOpen();
|
|
|
|
-
|
|
|
|
- verify(nioAccess).close(channel);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void testCloseDoesNotCloseChannelIfOpenedTwice() throws IOException {
|
|
public void testCloseDoesNotCloseChannelIfOpenedTwice() throws IOException {
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
when(nioAccess.isDirectory(path)).thenReturn(false);
|
|
@@ -686,7 +623,7 @@ public class SharedFileChannelTest {
|
|
ByteBuffer irrelevant = null;
|
|
ByteBuffer irrelevant = null;
|
|
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("SharedFileChannel is not open");
|
|
|
|
|
|
inTest.readFully(0, irrelevant);
|
|
inTest.readFully(0, irrelevant);
|
|
}
|
|
}
|
|
@@ -694,7 +631,7 @@ public class SharedFileChannelTest {
|
|
@Test
|
|
@Test
|
|
public void testTruncateFailsIfNotOpen() {
|
|
public void testTruncateFailsIfNotOpen() {
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("SharedFileChannel is not open");
|
|
|
|
|
|
inTest.truncate(0);
|
|
inTest.truncate(0);
|
|
}
|
|
}
|
|
@@ -702,7 +639,7 @@ public class SharedFileChannelTest {
|
|
@Test
|
|
@Test
|
|
public void testSizeFailsIfNotOpen() {
|
|
public void testSizeFailsIfNotOpen() {
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("SharedFileChannel is not open");
|
|
|
|
|
|
inTest.size();
|
|
inTest.size();
|
|
}
|
|
}
|
|
@@ -712,7 +649,7 @@ public class SharedFileChannelTest {
|
|
SharedFileChannel irrelevant = null;
|
|
SharedFileChannel irrelevant = null;
|
|
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("SharedFileChannel is not open");
|
|
|
|
|
|
inTest.transferTo(0, 0, irrelevant, 0);
|
|
inTest.transferTo(0, 0, irrelevant, 0);
|
|
}
|
|
}
|
|
@@ -724,7 +661,7 @@ public class SharedFileChannelTest {
|
|
inTest.open(OpenMode.WRITE);
|
|
inTest.open(OpenMode.WRITE);
|
|
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("SharedFileChannel is not open");
|
|
|
|
|
|
inTest.transferTo(0, 0, targetInTest, 0);
|
|
inTest.transferTo(0, 0, targetInTest, 0);
|
|
}
|
|
}
|
|
@@ -734,7 +671,7 @@ public class SharedFileChannelTest {
|
|
ByteBuffer irrelevant = null;
|
|
ByteBuffer irrelevant = null;
|
|
|
|
|
|
thrown.expect(IllegalStateException.class);
|
|
thrown.expect(IllegalStateException.class);
|
|
- thrown.expectMessage("closed for current thread");
|
|
|
|
|
|
+ thrown.expectMessage("SharedFileChannel is not open");
|
|
|
|
|
|
inTest.writeFully(0, irrelevant);
|
|
inTest.writeFully(0, irrelevant);
|
|
}
|
|
}
|