Debian Codegraph @

sejda-conversion/src/test/java/org/sejda/conversion/PageRangeSetAdapterTest.java

raw
1 /*
2 * Created on 15/ott/2011
3 * Copyright 2011 by Andrea Vacondio ([email protected]).
4 *
5 * This file is part of the Sejda source code
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 package org.sejda.conversion;
21
22 import static org.junit.Assert.assertEquals;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.apache.commons.lang3.ArrayUtils;
28 import org.apache.commons.lang3.StringUtils;
29 import org.junit.Test;
30 import org.sejda.model.pdf.page.PageRange;
31
32 /**
33 * @author Andrea Vacondio
34 *
35 */
36 public class PageRangeSetAdapterTest {
37
38 @Test
39 public void insertionOrder() {
40 PageRange[] inputRanges = { new PageRange(4), new PageRange(6, 9), new PageRange(1, 2) };
41 doTestInsertionOrder(inputRanges);
42 ArrayUtils.reverse(inputRanges);
43 doTestInsertionOrder(inputRanges);
44 }
45
46 private void doTestInsertionOrder(PageRange... pageRanges) {
47 String inputString = StringUtils.join(pageRanges, ',');
48 List<PageRange> ranges = new ArrayList<PageRange>(new PageRangeSetAdapter(inputString).getPageRangeSet());
49 for (int i = 0; i < pageRanges.length; i++) {
50 assertEquals(pageRanges[i], ranges.get(i));
51 }
52 }
53 }