|
11 | 11 | import org.junit.jupiter.api.Test; |
12 | 12 | import org.junit.jupiter.api.io.TempDir; |
13 | 13 | import org.junit.jupiter.params.ParameterizedTest; |
| 14 | +import org.junit.jupiter.params.provider.CsvSource; |
14 | 15 | import org.junit.jupiter.params.provider.ValueSource; |
15 | 16 | import org.mockito.Mockito; |
16 | 17 |
|
@@ -167,9 +168,41 @@ public void validateTooShort() { |
167 | 168 | } |
168 | 169 | } |
169 | 170 |
|
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")); |
173 | 206 | } |
174 | 207 |
|
175 | 208 |
|
|
0 commit comments