FilesystemKeyValueStore implements KeyValueStore<byte[]> { @Nullable public static File keyToFile(@NotNull final File rootDirectory, @NotNull final String key) throws IllegalArgumentException { if (rootDirectory == null || key == null) { throw new IllegalArgumentException("The rootDirectory and key must both be non-null."); } if (KeyValueStoreHelper.isValidKey(key)) { final String pathKey = key.replace(".", File.separator); return new File(rootDirectory, pathKey + VALUE_FILE_EXTENSION); } return null; } FilesystemKeyValueStore(@NotNull final File rootDirectory); @Nullable static File keyToFile(@NotNull final File rootDirectory, @NotNull final String key); @Override boolean hasKey(@Nullable final String key); @Override boolean set(@NotNull final String key, @NotNull final byte[] value); @Override @Nullable byte[] get(@Nullable final String key); @Override boolean delete(@Nullable final String key);  }
@SuppressWarnings("ConstantConditions") @Test public void testKeyToFile() { try { FilesystemKeyValueStore.keyToFile(null, null); Assert.fail("Calling FilesystemKeyValueStore.keyToFile with null arguments should fail with an IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { FilesystemKeyValueStore.keyToFile(keystoreRootDirectory, null); Assert.fail("Calling FilesystemKeyValueStore.keyToFile with null arguments should fail with an IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { FilesystemKeyValueStore.keyToFile(null, "the.key"); Assert.fail("Calling FilesystemKeyValueStore.keyToFile with null arguments should fail with an IllegalArgumentException"); } catch (IllegalArgumentException e) { } Assert.assertNull(FilesystemKeyValueStore.keyToFile(keystoreRootDirectory, EMPTY_KEY)); Assert.assertNull(FilesystemKeyValueStore.keyToFile(keystoreRootDirectory, INVALID_KEY)); final File valueFile1 = FilesystemKeyValueStore.keyToFile(keystoreRootDirectory, VALUE_1_KEY); Assert.assertNotNull(valueFile1); Assert.assertEquals(valueFile1.getAbsolutePath(), new File(keystoreRootDirectory, "feynman/quote.val").getAbsolutePath()); final File valueFile2 = FilesystemKeyValueStore.keyToFile(keystoreRootDirectory, VALUE_2_KEY); Assert.assertNotNull(valueFile2); Assert.assertEquals(valueFile2.getAbsolutePath(), new File(keystoreRootDirectory, "feynman/photo.val").getAbsolutePath()); }