### Question:
ServiceClientIdentifierConverter { public ServiceClientIdentifierDto convertId(String encodedServiceClientIdentifier) throws BadServiceClientIdentifierException { ServiceClientIdentifierDto dto = new ServiceClientIdentifierDto(); if (clientConverter.isEncodedSubsystemId(encodedServiceClientIdentifier)) { ClientId clientId = clientConverter.convertId(encodedServiceClientIdentifier); dto.setXRoadId(clientId); } else if (globalGroupConverter.isEncodedGlobalGroupId(encodedServiceClientIdentifier)) { GlobalGroupId globalGroupId = globalGroupConverter.convertId(encodedServiceClientIdentifier); dto.setXRoadId(globalGroupId); } else if (StringUtils.isNumeric(encodedServiceClientIdentifier)) { Long id; try { id = Long.parseLong(encodedServiceClientIdentifier); } catch (NumberFormatException e) { throw new BadServiceClientIdentifierException(encodedServiceClientIdentifier); } dto.setLocalGroupId(id); } else { throw new BadServiceClientIdentifierException(encodedServiceClientIdentifier); } return dto; } @Autowired  ServiceClientIdentifierConverter(ClientConverter clientConverter,
            GlobalGroupConverter globalGroupConverter); ServiceClientIdentifierDto convertId(String encodedServiceClientIdentifier); List<ServiceClientIdentifierDto> convertIds(Iterable<String> encodedServiceClientIdentifiers);  }### Answer:
@Test public void convertLocalGroup() throws Exception { ServiceClientIdentifierDto dto = converter.convertId("1234"); assertEquals(true, dto.isLocalGroup()); assertEquals(new Long("1234"), dto.getLocalGroupId()); assertEquals(null, dto.getXRoadId()); }
@Test public void convertGlobalGroup() throws Exception { ServiceClientIdentifierDto dto = converter.convertId("DEV:security-server-owners"); assertEquals(false, dto.isLocalGroup()); assertEquals(null, dto.getLocalGroupId()); assertEquals(XRoadObjectType.GLOBALGROUP, dto.getXRoadId().getObjectType()); assertTrue(dto.getXRoadId() instanceof GlobalGroupId); GlobalGroupId globalGroupId = (GlobalGroupId) dto.getXRoadId(); assertEquals("security-server-owners", globalGroupId.getGroupCode()); assertEquals("DEV", globalGroupId.getXRoadInstance()); }
@Test public void convertSubsystem() throws Exception { ServiceClientIdentifierDto dto = converter.convertId("DEV:ORG:1234:Subsystem"); assertEquals(false, dto.isLocalGroup()); assertEquals(null, dto.getLocalGroupId()); assertEquals(XRoadObjectType.SUBSYSTEM, dto.getXRoadId().getObjectType()); assertTrue(dto.getXRoadId() instanceof ClientId); ClientId clientId = (ClientId) dto.getXRoadId(); assertEquals("DEV", clientId.getXRoadInstance()); assertEquals("ORG", clientId.getMemberClass()); assertEquals("1234", clientId.getMemberCode()); assertEquals("Subsystem", clientId.getSubsystemCode()); }
@Test(expected = ServiceClientIdentifierConverter.BadServiceClientIdentifierException.class) public void convertMember() throws Exception { ServiceClientIdentifierDto dto = converter.convertId("DEV:ORG:1234"); }
@Test(expected = ServiceClientIdentifierConverter.BadServiceClientIdentifierException.class) public void convertNonNumeric() throws Exception { ServiceClientIdentifierDto dto = converter.convertId("foobar"); }