### Question:
ClientConverter { public String convertId(ClientId clientId) { return convertId(clientId, false); } @Autowired  ClientConverter(GlobalConfFacade globalConfFacade); Client convert(ClientType clientType); List<Client> convert(Iterable<ClientType> clientTypes); String convertId(ClientId clientId); String convertId(ClientId clientId, boolean includeType); ClientId convertId(String encodedId); List<ClientId> convertIds(List<String> encodedIds); Client convertMemberInfoToClient(MemberInfo memberInfo); List<Client> convertMemberInfosToClients(List<MemberInfo> memberInfos); static final int INSTANCE_INDEX; static final int MEMBER_CLASS_INDEX; static final int MEMBER_CODE_INDEX; static final int SUBSYSTEM_CODE_INDEX; }### Answer:
@Test public void convertStringId() throws Exception { ClientId clientId = clientConverter.convertId("XRD2:GOV:M4:SS1"); assertEquals("XRD2", clientId.getXRoadInstance()); assertEquals("GOV", clientId.getMemberClass()); assertEquals("M4", clientId.getMemberCode()); assertEquals("SS1", clientId.getSubsystemCode()); clientId = clientConverter.convertId("XRD2:GOV:M4"); assertNull(clientId.getSubsystemCode()); }
@Test public void convertDifficultStringId() throws Exception { String difficultSubsystemId = "FOO SS-;/?@=&-X<!-- o -->BAR"; ClientId clientId = clientConverter.convertId("XRD2:GOV:M4:" + difficultSubsystemId); assertEquals("XRD2", clientId.getXRoadInstance()); assertEquals("GOV", clientId.getMemberClass()); assertEquals("M4", clientId.getMemberCode()); assertEquals(difficultSubsystemId, clientId.getSubsystemCode()); }
@Test(expected = BadRequestException.class) public void convertBadStringId() throws Exception { clientConverter.convertId("XRD2:GOV:M4:SS1:aa"); }
@Test(expected = BadRequestException.class) public void convertBadStringId2() throws Exception { clientConverter.convertId("XRD2"); }
@Test(expected = BadRequestException.class) public void convertBadStringId3() throws Exception { clientConverter.convertId("XRD2:GOV:M4:SS1::::::"); }
@Test public void convertClientId() throws Exception { ClientId clientId = ClientId.create("XRD2", "GOV", "M4", "SS1"); String encoded = clientConverter.convertId(clientId); assertEquals("XRD2:GOV:M4:SS1", encoded); clientId = ClientId.create("XRD2", "GOV", "M4"); encoded = clientConverter.convertId(clientId); assertEquals("XRD2:GOV:M4", encoded); }