### Question:
ConversionUtils { public static Set<PageRange> toPageRangeSet(String selection) throws ConversionException { if (isNotBlank(selection)) { Set<PageRange> pageRangeSet = new NullSafeSet<>(); String[] tokens = splitAndTrim(selection, ","); for (String current : tokens) { PageRange range = toPageRange(current); if (range.getEnd() < range.getStart()) { throw new ConversionException( DefaultI18nContext.getInstance().i18n("Invalid range: {0}.", range.toString())); } pageRangeSet.add(range); } return pageRangeSet; } return Collections.emptySet(); } private  ConversionUtils(); static Set<PageRange> toPageRangeSet(String selection);  }### Answer:
@Test(expected = ConversionException.class) public void invalid() { ConversionUtils.toPageRangeSet("Chuck Norris"); }
@Test(expected = ConversionException.class) public void invalidRange() { ConversionUtils.toPageRangeSet("1-2-3"); }
@Test(expected = ConversionException.class) public void endLower() { ConversionUtils.toPageRangeSet("10-5"); }
@Test public void singlePage() { Set<PageRange> pageSet = ConversionUtils.toPageRangeSet("5"); assertEquals(1, pageSet.size()); assertEquals(5, pageSet.stream().findFirst().get().getStart()); assertEquals(5, pageSet.stream().findFirst().get().getEnd()); }
@Test public void rangePage() { Set<PageRange> pageSet = ConversionUtils.toPageRangeSet("5-10"); assertEquals(1, pageSet.size()); assertEquals(5, pageSet.stream().findFirst().get().getStart()); assertEquals(10, pageSet.stream().findFirst().get().getEnd()); }
@Test public void endPage() { Set<PageRange> pageSet = ConversionUtils.toPageRangeSet("-10"); assertEquals(1, pageSet.size()); assertEquals(1, pageSet.stream().findFirst().get().getStart()); assertEquals(10, pageSet.stream().findFirst().get().getEnd()); }
@Test public void startPage() { Set<PageRange> pageSet = ConversionUtils.toPageRangeSet("10-"); assertEquals(1, pageSet.size()); assertEquals(10, pageSet.stream().findFirst().get().getStart()); assertTrue(pageSet.stream().findFirst().get().isUnbounded()); }
@Test public void multiple() { Set<PageRange> pageSet = ConversionUtils.toPageRangeSet("2-4,10-"); assertEquals(2, pageSet.size()); assertEquals(2, pageSet.stream().findFirst().get().getStart()); assertEquals(4, pageSet.stream().findFirst().get().getEnd()); assertTrue(pageSet.stream().anyMatch(PageRange::isUnbounded)); }