UriTransformer { public String[] toEbXML(String uri) { if (uri == null) { return new String[0]; } List<String> uriParts = new ArrayList<String>(); int slotIdx = 1; int start = 0; while (start < uri.length()) { String prefix = slotIdx + "|"; int validLength = 128 - prefix.length(); if (uri.length() < start + validLength) { validLength = uri.length() - start; } String uriPart = uri.substring(start, start + validLength); String slotValue = prefix + uriPart; uriParts.add(slotValue); start += validLength; ++slotIdx; } return uriParts.toArray(new String[uriParts.size()]); }  String fromEbXML(List<String> slotValues); String[] toEbXML(String uri);  }
@Test public void testURIThatFitsExactlyIntoOneSlot() { String uri = veryLongUriString.substring(0, 126); String[] ebXML = transformer.toEbXML(uri); assertEquals(1, ebXML.length); assertEquals("1|" + uri, ebXML[0]); }
@Test public void testToEbXMLWithShortestUriUsingTwoSlots() { String uri = veryLongUriString.substring(0, 127); String[] ebXML = transformer.toEbXML(uri); String uriPart1 = uri.substring(0, 126); String uriPart2 = uri.substring(126, 127); assertEquals(2, ebXML.length); assertEquals("1|" + uriPart1, ebXML[0]); assertEquals("2|" + uriPart2, ebXML[1]); }