### Question:
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public Optional<SettingsKeyModel> getSettingsKeyByKey(String key) { return settingsKeyRepository.findByKey(key).map(this::convertToSettingsKeyModel); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); @Override List<SettingsKeyModel> getSettingsKeys(); @Override Optional<SettingsKeyModel> getSettingsKeyByKey(String key); @Override SettingsKeyModel saveSettingsKey(String key, String value); @Override void deleteSettingsKeyByKey(String key); @Override void deleteSettingsKeyById(Long id);  }### Answer:
@Test public void getSettingsByKeyTest() { final String key = "key1"; final String value1 = "value1"; SettingsKeyEntity settingsKeyEntity = new SettingsKeyEntity(key, value1); settingsKeyEntity.setId(1L); SettingsKeyRepository settingsKeyRepository = new MockSettingsKeyRepository(); settingsKeyRepository.save(settingsKeyEntity); DefaultSettingsKeyAccessor settingsKeyAccessor = new DefaultSettingsKeyAccessor(settingsKeyRepository); Optional<SettingsKeyModel> settingsKeyModelOptional = settingsKeyAccessor.getSettingsKeyByKey("key1"); Optional<SettingsKeyModel> settingsKeyModelOptionalNull = settingsKeyAccessor.getSettingsKeyByKey("-1"); assertTrue(settingsKeyModelOptional.isPresent()); assertFalse(settingsKeyModelOptionalNull.isPresent()); SettingsKeyModel settingsKeyModel = settingsKeyModelOptional.get(); assertEquals(key, settingsKeyModel.getKey()); assertEquals(value1, settingsKeyModel.getValue()); }