### Question:
DatabaseKeyService implements KeyService { @Override public Key getKey(String id) { if (id == null) { throw new IllegalArgumentException("Id cannot be null"); } Key key = null; readLock.lock(); try { final String sql = "SELECT * FROM SIGNING_KEY WHERE id = ?"; KeyEntity keyEntity; try { keyEntity = jdbcTemplate.queryForObject(sql, new KeyEntityRowMapper(), id); } catch (EmptyResultDataAccessException e) { keyEntity = null; } if (keyEntity != null) { key = KeyMappings.map(keyEntity); } else { logger.debug("No signing key found with id='" + id + "'"); } } finally { readLock.unlock(); } return key; } @Autowired  DatabaseKeyService(final JdbcTemplate jdbcTemplate); @Override Key getKey(String id); @Override Key getOrCreateKey(String tenantIdentity); @Override void deleteKey(String tenantIdentity);  }### Answer:
@Test public void testGetKeyByIdWhenExists() { final Key existingKey = keyService.getKey("1"); assertNotNull(existingKey); assertEquals("1", existingKey.getId()); assertEquals("unit_test_tenant_identity", existingKey.getIdentity()); assertEquals("0123456789abcdef", existingKey.getKey()); }
@Test public void testGetKeyByIdWhenDoesNotExist() { final Key existingKey = keyService.getKey("2"); assertNull(existingKey); }