### Question:
KeyConverter { public Key convert(KeyInfo keyInfo) { return convertInternal(keyInfo, null); } @Autowired  KeyConverter(TokenCertificateConverter tokenCertificateConverter,
            TokenCertificateSigningRequestConverter tokenCsrConverter,
            PossibleActionsRuleEngine possibleActionsRuleEngine,
            PossibleActionConverter possibleActionConverter); Key convert(KeyInfo keyInfo); Key convert(KeyInfo keyInfo, TokenInfo tokenInfo); List<Key> convert(Iterable<KeyInfo> keyInfos); List<Key> convert(Iterable<KeyInfo> keyInfos, TokenInfo tokenInfo);  }### Answer:
@Test public void convert() throws Exception { List<CertificateInfo> certs = new ArrayList<>(); certs.add(new CertificateInfoBuilder().build()); List<CertRequestInfo> csrs = new ArrayList<>(); csrs.add(new CertRequestInfo("id", ClientId.create("a", "b", "c"), "sujbect-name")); KeyInfo info = new KeyInfo(true, KeyUsageInfo.SIGNING, "friendly-name", "id", "label", "public-key", certs, csrs, "sign-mechanism-name"); Key key = keyConverter.convert(info); assertEquals(true, key.getAvailable()); assertNotNull(key.getCertificates()); assertEquals(1, key.getCertificates().size()); assertNotNull(key.getCertificateSigningRequests()); assertEquals(1, key.getCertificateSigningRequests().size()); assertEquals("id", key.getId()); assertEquals("label", key.getLabel()); assertEquals("friendly-name", key.getName()); assertEquals(true, key.getSavedToConfiguration()); assertEquals(KeyUsageType.SIGNING, key.getUsage()); }
@Test public void isSavedToConfiguration() throws Exception { KeyInfo info = new TokenTestUtils.KeyInfoBuilder().build(); info.getCerts().clear(); info.getCertRequests().clear(); info.getCertRequests().add(createTestCsr()); assertEquals(true, keyConverter.convert(info).getSavedToConfiguration()); info.getCerts().clear(); info.getCertRequests().clear(); assertEquals(false, keyConverter.convert(info).getSavedToConfiguration()); info.getCerts().clear(); info.getCertRequests().clear(); info.getCerts().add(new CertificateInfoBuilder().savedToConfiguration(false).build()); info.getCerts().add(new CertificateInfoBuilder().savedToConfiguration(false).build()); assertEquals(false, keyConverter.convert(info).getSavedToConfiguration()); info.getCerts().clear(); info.getCertRequests().clear(); info.getCerts().add(new CertificateInfoBuilder().savedToConfiguration(false).build()); info.getCerts().add(new CertificateInfoBuilder().savedToConfiguration(true).build()); assertEquals(true, keyConverter.convert(info).getSavedToConfiguration()); info.getCerts().clear(); info.getCertRequests().clear(); info.getCerts().add(new CertificateInfoBuilder().savedToConfiguration(true).build()); info.getCerts().add(new CertificateInfoBuilder().savedToConfiguration(false).build()); assertEquals(true, keyConverter.convert(info).getSavedToConfiguration()); }