ListHeaderProducer { public List<T> createQualitySortedList(String header) { final List<T> tokens = new ArrayList<>(); int n; int p = 0; final int length = header.length(); while (p < length) { n = scan(header, p, ','); String token; if (charAtIs(header, n, ',')) { token = header.substring(p, n); } else { token = header.substring(p); n = length; } tokens.add(itemFactory.createItem(token)); p = n + 1; } if (tokens.size() > 1) { Collections.sort(tokens, QUALITY_VALUE_COMPARATOR); } return tokens; } ListHeaderProducer(ListItemFactory<T> itemFactory); List<T> createQualitySortedList(String header);  }
@Test public void parsesGivenStringToSortedListOfQualityValues() { List<QualityValue> qualitySortedList = listHeaderProducer.createQualitySortedList(header); assertEquals(expectedQualityValueList, qualitySortedList); }
@Test public void parsesGivenStringWithSpacesToSortedListOfQualityValues() { List<QualityValue> qualitySortedList = listHeaderProducer.createQualitySortedList(headerWithSpaces); assertEquals(expectedQualityValueList, qualitySortedList); }