### Question:
PublicApiKeyDataConverter { public PublicApiKeyData convert(PersistentApiKeyType persistentApiKeyType) { PublicApiKeyData publicApiKeyData = new PublicApiKeyData(); publicApiKeyData.setId(persistentApiKeyType.getId()); publicApiKeyData.setKey(persistentApiKeyType.getPlaintTextKey()); publicApiKeyData.setRoles(persistentApiKeyType.getRoles()); return publicApiKeyData; }  PublicApiKeyData convert(PersistentApiKeyType persistentApiKeyType); List<PublicApiKeyData> convert(Iterable<PersistentApiKeyType> apiKeys);  }### Answer:
@Test public void convertNewKey() throws InvalidRoleNameException { Set<Role> roles = Role.getForNames(Arrays.asList("XROAD_SECURITY_OFFICER", "XROAD_REGISTRATION_OFFICER")); PersistentApiKeyType key = new PersistentApiKeyType(PLAIN, ENCODED, roles); PublicApiKeyData publicApiKeyData = publicApiKeyDataConverter.convert(key); assertEquals(null, publicApiKeyData.getId()); assertEquals(PLAIN, publicApiKeyData.getKey()); assertEquals(2, publicApiKeyData.getRoles().size()); assertTrue(publicApiKeyData.getRoles().contains(Role.XROAD_REGISTRATION_OFFICER)); }
@Test public void convertUpdatedKey() throws InvalidRoleNameException { Set<Role> roles = Role.getForNames(Arrays.asList("XROAD_SECURITY_OFFICER")); PersistentApiKeyType key = new PersistentApiKeyType(ENCODED, roles); PublicApiKeyData publicApiKeyData = publicApiKeyDataConverter.convert(key); assertEquals(null, publicApiKeyData.getId()); assertEquals(null, publicApiKeyData.getKey()); assertEquals(1, publicApiKeyData.getRoles().size()); assertTrue(publicApiKeyData.getRoles().contains(Role.XROAD_SECURITY_OFFICER)); }
@Test public void convertList() throws InvalidRoleNameException { Set<Role> roles1 = Role.getForNames(Arrays.asList("XROAD_SECURITY_OFFICER")); PersistentApiKeyType key1 = new PersistentApiKeyType(ENCODED, roles1); Set<Role> roles2 = Role.getForNames(Arrays.asList("XROAD_SECURITY_OFFICER", "XROAD_REGISTRATION_OFFICER")); PersistentApiKeyType key2 = new PersistentApiKeyType(ENCODED, roles2); List<PublicApiKeyData> list = publicApiKeyDataConverter.convert(Arrays.asList(key1, key2)); assertEquals(2, list.size()); }