Skip to content

Commit 5916093

Browse files
added unit tests for #58
1 parent 1b8bf36 commit 5916093

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/test/java/org/cryptomator/cryptofs/ch/CleartextFileChannelTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,29 @@ public void writeAfterEof() throws IOException {
442442
Assertions.assertEquals(210l, inTest.size());
443443
}
444444

445+
@Test
446+
@DisplayName("write header if it isn't already written")
447+
public void testWriteHeaderIfNeeded() throws IOException {
448+
when(options.writable()).thenReturn(true);
449+
450+
inTest.force(true);
451+
inTest.force(true);
452+
inTest.force(true);
453+
454+
Mockito.verify(ciphertextFileChannel, Mockito.times(1)).write(Mockito.any(), Mockito.eq(0l));
455+
}
456+
457+
@Test
458+
@DisplayName("don't write header if it is already written")
459+
public void testDontRewriteHeader() throws IOException {
460+
when(options.writable()).thenReturn(true);
461+
inTest = new CleartextFileChannel(ciphertextFileChannel, header, false, readWriteLock, cryptor, chunkCache, options, fileSize, lastModified, attributeViewSupplier, exceptionsDuringWrite, closeListener, stats);
462+
463+
inTest.force(true);
464+
465+
Mockito.verify(ciphertextFileChannel, Mockito.never()).write(Mockito.any(), Mockito.eq(0l));
466+
}
467+
445468
}
446469

447470
@Nested

0 commit comments

Comments
 (0)