### Question:
TokenConverter { public Token convert(TokenInfo tokenInfo) { Token token = new Token(); token.setId(tokenInfo.getId()); token.setName(tokenInfo.getFriendlyName()); if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) { token.setType(TokenType.SOFTWARE); } else { token.setType(TokenType.HARDWARE); } token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo())); Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus()); token.setStatus(status.orElse(null)); token.setLoggedIn(tokenInfo.isActive()); token.setAvailable(tokenInfo.isAvailable()); token.setSavedToConfiguration(isSavedToConfiguration(tokenInfo)); token.setReadOnly(tokenInfo.isReadOnly()); token.setSerialNumber(tokenInfo.getSerialNumber()); token.setTokenInfos(new ArrayList<>()); for (String key: tokenInfo.getTokenInfo().keySet()) { KeyValuePair keyValuePair = new KeyValuePair(); keyValuePair.setKey(key); keyValuePair.setValue(tokenInfo.getTokenInfo().get(key)); token.getTokenInfos().add(keyValuePair); } return token; } @Autowired  TokenConverter(KeyConverter keyConverter); Token convert(TokenInfo tokenInfo); List<Token> convert(Iterable<TokenInfo> tokenInfos);  }### Answer:
@Test public void convert() throws Exception { Map<String, String> tokenInfos = new HashMap<>(); tokenInfos.put("key1", "value1"); tokenInfos.put("key2", "value2"); KeyInfo dummyKeyInfo = new KeyInfo(false, KeyUsageInfo.SIGNING, null, null, null, null, new ArrayList<>(), new ArrayList<>(), null); TokenInfo tokenInfo = new TokenInfo(TokenInfo.SOFTWARE_MODULE_TYPE, "friendly-name", "id", false, true, true, "serial-number", "label", 123, TokenStatusInfo.OK, Collections.singletonList(dummyKeyInfo), tokenInfos); Token token = tokenConverter.convert(tokenInfo); assertEquals(true, token.getLoggedIn()); assertEquals(true, token.getAvailable()); assertEquals("id", token.getId()); assertNotNull(token.getKeys()); assertEquals(1, token.getKeys().size()); assertEquals("friendly-name", token.getName()); assertEquals(false, token.getReadOnly()); assertEquals(false, token.getSavedToConfiguration()); assertEquals("serial-number", token.getSerialNumber()); assertEquals(TokenStatus.OK, token.getStatus()); assertEquals(TokenType.SOFTWARE, token.getType()); assertNotNull(token.getTokenInfos()); assertEquals(2, token.getTokenInfos().size()); assertTrue(token.getTokenInfos().contains(new KeyValuePair().key("key1").value("value1"))); assertTrue(token.getTokenInfos().contains(new KeyValuePair().key("key2").value("value2"))); tokenInfo = new TokenInfo("hsm-uid-1234", "friendly-name", "id", false, true, true, "serial-number", "label", 123, TokenStatusInfo.USER_PIN_COUNT_LOW, Collections.singletonList(dummyKeyInfo), tokenInfos); token = tokenConverter.convert(tokenInfo); assertEquals(TokenType.HARDWARE, token.getType()); assertEquals(TokenStatus.USER_PIN_COUNT_LOW, token.getStatus()); }