Added comments on unit tests.

This commit is contained in:
Philippe Soares 2020-01-12 17:31:59 -05:00
parent 9e93614755
commit 8c3099d712

View File

@ -26,7 +26,7 @@ class FileLocksTest {
} }
/** /**
* Getting and exclusive lock from a RandomAccessFile * Getting an exclusive lock from a RandomAccessFile
* @throws IOException * @throws IOException
*/ */
@Test @Test
@ -48,6 +48,18 @@ class FileLocksTest {
} }
// Shared locks
/**
* Getting a shared (read) lock on the entire file.
* Fails when getting the lock from a FileChannel obtained through a FileOutputStream.
*/
@Test
void givenAFileOutputStream_whenGetSharedLock_throwNonReadableChannelException() {
assertThrows(NonReadableChannelException.class,
() -> FileLocks.getReadLockFromOutputStream(0, 10));
}
/** /**
* Getting a shared (read) lock works fine when getting the lock from a FileChannel obtained through a FileInputStream. * Getting a shared (read) lock works fine when getting the lock from a FileChannel obtained through a FileInputStream.
* @throws IOException * @throws IOException
@ -60,13 +72,10 @@ class FileLocksTest {
} }
/**
@Test * Getting a shared lock from a RandomAccessFile
void givenAFileOutputStream_whenGetSharedLock_throwNonReadableChannelException() { * @throws IOException
assertThrows(NonReadableChannelException.class, */
() -> FileLocks.getReadLockFromOutputStream(0, 10));
}
@Test @Test
void givenARandomAccessFile_whenGetSharedLock_lock() throws IOException { void givenARandomAccessFile_whenGetSharedLock_lock() throws IOException {
FileLock lock = FileLocks.getReadLockFromRandomAccessFile(0, 10); FileLock lock = FileLocks.getReadLockFromRandomAccessFile(0, 10);