Debian Codegraph @

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

raw
1 /*
2 * Created on 19 ott 2016
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.conversion;
20
21 import static org.junit.Assert.assertEquals;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.TemporaryFolder;
29 import org.sejda.conversion.exception.ConversionException;
30
31 /**
32 * @author Andrea Vacondio
33 *
34 */
35 public class WildcardsPdfFileSourceAdapterTest {
36 @Rule
37 public TemporaryFolder folder = new TemporaryFolder();
38
39 private File setUpFiles() throws IOException {
40 folder.newFile("test_file.pdf");
41 folder.newFile("test2_file.pdf");
42 folder.newFile("another_test_file.pdf");
43 folder.newFile("ignore_this.something");
44 return folder.getRoot();
45 }
46
47 @Test(expected = ConversionException.class)
48 public void testNegative() {
49 new WildcardsPdfFileSourceAdapter("/I/dont/exist");
50 }
51
52 @Test(expected = ConversionException.class)
53 public void testNegativeWildcardNonExistingParent() {
54 new WildcardsPdfFileSourceAdapter("/I/dont/exist/*.pdf");
55 }
56
57 @Test
58 public void testPositive() throws IOException {
59 WildcardsPdfFileSourceAdapter victim = new WildcardsPdfFileSourceAdapter(
60 setUpFiles().getAbsolutePath() + "/*.pdf");
61 assertEquals(3, victim.getPdfFileSources().size());
62 }
63
64 @Test
65 public void testPositiveCaseInsensitive() throws IOException {
66 WildcardsPdfFileSourceAdapter victim = new WildcardsPdfFileSourceAdapter(
67 setUpFiles().getAbsolutePath() + "/*.PdF");
68 assertEquals(3, victim.getPdfFileSources().size());
69 }
70
71 @Test
72 public void testPositiveFilePath() throws IOException {
73 WildcardsPdfFileSourceAdapter victim = new WildcardsPdfFileSourceAdapter(
74 setUpFiles().getAbsolutePath() + "/test_file.pdf");
75 assertEquals(1, victim.getPdfFileSources().size());
76 }
77
78 @Test
79 public void testOrder() throws IOException {
80 folder.newFile("7.pdf");
81 folder.newFile("44.pdf");
82 folder.newFile("14.pdf");
83 WildcardsPdfFileSourceAdapter victim = new WildcardsPdfFileSourceAdapter(
84 folder.getRoot().getAbsolutePath() + "/*.pdf");
85 assertEquals(3, victim.getPdfFileSources().size());
86 assertEquals("7.pdf", victim.getPdfFileSources().get(0).getName());
87 assertEquals("14.pdf", victim.getPdfFileSources().get(1).getName());
88 assertEquals("44.pdf", victim.getPdfFileSources().get(2).getName());
89 }
90 }