Skip to content

Commit ffede33

Browse files
committed
more unit tests
1 parent 8e72527 commit ffede33

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/test/java/org/cryptomator/cryptofs/FileNameDecryptorTest.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.junit.jupiter.api.Test;
1212
import org.junit.jupiter.api.io.TempDir;
1313
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.CsvSource;
1415
import org.junit.jupiter.params.provider.ValueSource;
1516
import org.mockito.Mockito;
1617

@@ -167,9 +168,41 @@ public void validateTooShort() {
167168
}
168169
}
169170

170-
@Test
171-
public void testIsAtCipherNodeLevelRequiresAbsolutePath() {
172-
Assertions.assertThrows(IllegalArgumentException.class, () -> testObj.isAtCipherNodeLevel(Path.of("relative/path")));
171+
@Nested
172+
public class IsAtCipherNodeLevel {
173+
174+
@TempDir
175+
Path tmpDir;
176+
177+
@Test
178+
@DisplayName("cipherNodeLevel test requires an absolute path")
179+
public void requiresAbsolutePath() {
180+
var relativePath = Path.of("relative/path");
181+
Assertions.assertThrows(IllegalArgumentException.class, () -> testObj.isAtCipherNodeLevel(relativePath));
182+
}
183+
184+
@Test
185+
public void success() {
186+
when(vaultPath.getNameCount()).thenReturn(tmpDir.getNameCount());
187+
var p = tmpDir.resolve("d/AA/BBBBBBBBBBBBBBB/encrypted.file");
188+
Assertions.assertTrue(testObj.isAtCipherNodeLevel(p));
189+
}
190+
191+
@Test
192+
public void failure() {
193+
when(vaultPath.getNameCount()).thenReturn(tmpDir.getNameCount());
194+
var p = tmpDir.resolve("d/AA/other.file");
195+
Assertions.assertFalse(testObj.isAtCipherNodeLevel(p));
196+
}
197+
}
198+
199+
@ParameterizedTest
200+
@DisplayName("Only c9r and c9s are accepted file extensions")
201+
@CsvSource(value = {"file.c9r,true", "file.c9s,true", "filec9r,false", "file.c9l,false",})
202+
public void testHasCipherNodeExtension(String filename, boolean expected) {
203+
var p = Path.of(filename);
204+
var result = testObj.hasCipherNodeExtension(p);
205+
Assertions.assertEquals(expected, result, "The filename %s is WRONGLY %s".formatted(filename, result ? "accepted" : "rejected"));
173206
}
174207

175208

0 commit comments

Comments
 (0)