### Question:
SecurityServerConverter { public SecurityServerId convertId(String encodedId) { validateEncodedString(encodedId); int serverCodeSeparatorIndex = encodedId.lastIndexOf( ENCODED_ID_SEPARATOR); String encodedMemberClientId = encodedId.substring(0, serverCodeSeparatorIndex); ClientId memberClientId = clientConverter.convertId(encodedMemberClientId); String serverCode = encodedId.substring(serverCodeSeparatorIndex + 1); SecurityServerId securityServerId = SecurityServerId.create(memberClientId, serverCode); return securityServerId; } @Autowired  SecurityServerConverter(ClientConverter clientConverter); SecurityServerId convertId(String encodedId); String convertId(SecurityServerId securityServerId); SecurityServer convert(SecurityServerId securityServerId); static final int SECURITY_SERVER_CODE_INDEX; }### Answer:
@Test public void convertEncodedId() { String securityServerCode = "security-server-foo"; String memberCode = "XRD2:GOV:M4"; SecurityServerId id = securityServerConverter.convertId( memberCode + ":" + securityServerCode); assertEquals("XRD2", id.getXRoadInstance()); assertEquals("GOV", id.getMemberClass()); assertEquals("M4", id.getMemberCode()); assertEquals(securityServerCode, id.getServerCode()); String difficultServerCode = "FOO SS-;/?@=&-X<!-- o -->BAR"; id = securityServerConverter.convertId( memberCode + ":" + difficultServerCode); assertEquals("XRD2", id.getXRoadInstance()); assertEquals("GOV", id.getMemberClass()); assertEquals("M4", id.getMemberCode()); assertEquals(difficultServerCode, id.getServerCode()); }
@Test(expected = BadRequestException.class) public void convertEncodedIdWithSubsystem() { securityServerConverter.convertId("XRD2:GOV:M4:SS1:serverCode"); }
@Test(expected = BadRequestException.class) public void convertEncodedIdWithMissingMember() { securityServerConverter.convertId("XRD2:GOV:serverCode"); }
@Test(expected = BadRequestException.class) public void convertEncodedIdWithTooManyElements() { securityServerConverter.convertId("XRD2:GOV:M4:SS1:serverCode::::"); }
@Test(expected = BadRequestException.class) public void convertEmptyEncodedId() { securityServerConverter.convertId(""); }
@Test(expected = BadRequestException.class) public void convertNullEncodedId() { String id = null; securityServerConverter.convertId(id); }
@Test(expected = BadRequestException.class) public void convertEncodedIdWithoutDelimiter() { securityServerConverter.convertId(";;;;asdsdas"); }
@Test public void convertSecurityServerId() { SecurityServerId securityServerId = SecurityServerId.create( "XRD2", "GOV", "M4", "server1"); String id = securityServerConverter.convertId(securityServerId); assertEquals("XRD2:GOV:M4:server1", id); }