DefaultKeyStorage implements KeyStorage { @Override public void store(KeyEntry keyEntry) { String name = keyEntry.getName(); KeyEntry entry; if (keyEntry instanceof JsonKeyEntry) { entry = keyEntry; } else { entry = new JsonKeyEntry(keyEntry.getName(), keyEntry.getValue()); entry.setMeta(keyEntry.getMeta()); } synchronized (this) { Entries entries = load(); if (entries.containsKey(name)) { throw new KeyEntryAlreadyExistsException(); } entries.put(name, (JsonKeyEntry) entry); save(entries); } } DefaultKeyStorage();  DefaultKeyStorage(String directoryName, String fileName); @Override void delete(String keyName); @Override boolean exists(String keyName); @Override KeyEntry load(String keyName); @Override Set<String> names(); @Override void store(KeyEntry keyEntry); @Override KeyEntry createEntry(String name, byte[] value); @Override void update(KeyEntry keyEntry);  }
@Test public void store() { storage.store(entry); assertTrue(storage.exists(alias)); }
@Test public void store_duplicated() { storage.store(entry); assertThrows(KeyEntryAlreadyExistsException.class, () -> { storage.store(entry); }); }