Debian Codegraph @

sejda-sambox/src/test/java/org/sejda/impl/sambox/component/PdfRotatorTest.java

raw
1 /*
2 * Created on 16/ago/2015
3 * Copyright 2015 by Andrea Vacondio ([email protected]).
4 * This file is part of Sejda.
5 *
6 * Sejda is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Sejda is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with Sejda. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package org.sejda.impl.sambox.component;
20
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24
25 import java.util.Arrays;
26 import java.util.HashSet;
27
28 import org.junit.Test;
29 import org.sejda.model.rotation.Rotation;
30 import org.sejda.sambox.pdmodel.PDDocument;
31 import org.sejda.sambox.pdmodel.PDPage;
32
33 /**
34 * @author Andrea Vacondio
35 *
36 */
37 public class PdfRotatorTest {
38 @Test
39 public void singlePage() {
40 PDDocument document = mock(PDDocument.class);
41 PDPage page = mock(PDPage.class);
42 when(page.getRotation()).thenReturn(180);
43 when(document.getPage(2)).thenReturn(page);
44 new PdfRotator(document).rotate(3, Rotation.DEGREES_270);
45 verify(page).setRotation(90);
46 }
47
48 @Test
49 public void multiplePages() {
50 PDDocument document = mock(PDDocument.class);
51 PDPage page1 = mock(PDPage.class);
52 when(page1.getRotation()).thenReturn(180);
53 when(document.getPage(0)).thenReturn(page1);
54 PDPage page2 = mock(PDPage.class);
55 when(page2.getRotation()).thenReturn(90);
56 when(document.getPage(1)).thenReturn(page2);
57 when(document.getNumberOfPages()).thenReturn(2);
58 PdfRotator victim = new PdfRotator(document);
59 new HashSet<>(Arrays.asList(1, 2)).forEach(page -> victim.rotate(page, Rotation.DEGREES_270));
60 verify(page1).setRotation(90);
61 verify(page2).setRotation(0);
62 }
63 }