Page { public static Page pageRange(int start, int end) { if (start < 0 || end < 0) { throw new IllegalArgumentException("Invalid pages: (" + start + " ," + end + ")"); } if (end < start) { throw new IllegalArgumentException("Starting page should be less than or equal to ending page"); } return new Page(start, end); } private  Page(int start, int end); static Page allPages(); static Page singlePage(int page); static Page pageRange(int start, int end);  }
@Test public void testPageRange() throws Exception { Page page = Page.pageRange(0, 5); assertEquals(page.start, 0); assertEquals(page.end, 5); }
@Test(expected = IllegalArgumentException.class) public void testNegativeStartPage() throws Exception { Page.pageRange(-1, 0); }
@Test(expected = IllegalArgumentException.class) public void testNegativeEndPage() throws Exception { Page.pageRange(0, -1); }
@Test(expected = IllegalArgumentException.class) public void testEndLarger() throws Exception { Page.pageRange(1, 0); }