@@ -21,13 +21,15 @@ public class PdfOperationTest {
2121 public void givenADocumentAndPageToKeep_whenSplit_thenReturnsOnlyKeptPage ()
2222 throws IOException {
2323
24- List <Integer > pageNumberToKeep = new ArrayList <>();
25- pageNumberToKeep .add (2 );
24+ PageOptions pageOptions = new PageOptions .Builder ()
25+ .pageIndexes (new Integer []{2 })
26+ .operation (PageOptionsOperation .KEEP_ONLY )
27+ .build ();
2628
27- SplitQuery splitQuery = new SplitQuery (
28- Files .readAllBytes (new File ("src/test/resources/file_types/pdf/multipage.pdf" ).toPath ()),
29- new PageOptions (pageNumberToKeep , PageOptionsOperation .KEEP_ONLY , 0 ));
29+ byte [] fileBytes = Files .readAllBytes (
30+ new File ("src/test/resources/file_types/pdf/multipage.pdf" ).toPath ());
3031
32+ SplitQuery splitQuery = new SplitQuery (fileBytes , pageOptions );
3133 SplitPdf splitPdf = pdfOperation .split (splitQuery );
3234
3335 Assertions .assertNotNull (splitPdf );
@@ -39,13 +41,18 @@ public void givenADocumentAndPageToKeep_whenSplit_thenReturnsOnlyKeptPage()
3941 public void givenADocumentAndListOfPagesToKeep_whenSplit_thenReturnsOnlyKeptPages ()
4042 throws IOException {
4143
42- List <Integer > pageNumberToKeep = new ArrayList <>();
43- pageNumberToKeep .add (1 );
44- pageNumberToKeep .add (2 );
44+ List <Integer > pageNumbersToKeep = new ArrayList <>();
45+ pageNumbersToKeep .add (1 );
46+ pageNumbersToKeep .add (2 );
47+
48+ PageOptions pageOptions = new PageOptions .Builder ()
49+ .pageIndexes (pageNumbersToKeep )
50+ .operation (PageOptionsOperation .KEEP_ONLY )
51+ .build ();
4552
4653 SplitQuery splitQuery = new SplitQuery (
4754 Files .readAllBytes (new File ("src/test/resources/file_types/pdf/multipage.pdf" ).toPath ()),
48- new PageOptions ( pageNumberToKeep , PageOptionsOperation . KEEP_ONLY , 0 )
55+ pageOptions
4956 );
5057 SplitPdf splitPdf = pdfOperation .split (splitQuery );
5158
@@ -58,14 +65,14 @@ public void givenADocumentAndListOfPagesToKeep_whenSplit_thenReturnsOnlyKeptPage
5865 public void givenADocumentAndListOfPagesToRemove_whenSplit_thenReturnsOnlyNotRemovedPages ()
5966 throws IOException {
6067
61- List < Integer > pageNumberToKeep = new ArrayList <>();
62- pageNumberToKeep . add ( 1 );
63- pageNumberToKeep . add ( 2 );
64- pageNumberToKeep . add ( 3 );
68+ PageOptions pageOptions = new PageOptions . Builder ()
69+ . pageIndexes ( new Integer []{ 1 , 2 , 3 })
70+ . operation ( PageOptionsOperation . REMOVE )
71+ . build ( );
6572
6673 SplitQuery splitQuery = new SplitQuery (
6774 Files .readAllBytes (new File ("src/test/resources/file_types/pdf/multipage.pdf" ).toPath ()),
68- new PageOptions ( pageNumberToKeep , PageOptionsOperation . REMOVE , 0 )
75+ pageOptions
6976 );
7077 SplitPdf splitPdf = pdfOperation .split (splitQuery );
7178
@@ -78,14 +85,14 @@ public void givenADocumentAndListOfPagesToRemove_whenSplit_thenReturnsOnlyNotRem
7885 public void givenADocumentOtherThantAPdf_whenSplit_mustFail ()
7986 throws IOException {
8087
81- List < Integer > pageNumberToKeep = new ArrayList <>();
82- pageNumberToKeep . add ( 1 );
83- pageNumberToKeep . add ( 2 );
84- pageNumberToKeep . add ( 3 );
88+ PageOptions pageOptions = new PageOptions . Builder ()
89+ . pageIndexes ( new Integer []{ 1 , 2 , 3 })
90+ . operation ( PageOptionsOperation . REMOVE )
91+ . build ( );
8592
8693 SplitQuery splitQuery = new SplitQuery (
8794 Files .readAllBytes (new File ("src/test/resources/file_types/receipt.jpg" ).toPath ()),
88- new PageOptions ( pageNumberToKeep , PageOptionsOperation . REMOVE , 0 )
95+ pageOptions
8996 );
9097
9198 Assertions .assertThrows (
@@ -97,12 +104,15 @@ public void givenADocumentOtherThantAPdf_whenSplit_mustFail()
97104 public void givenADocumentAndListPagesToRemoveAndMinPagesCondition_whenSplit_mustNotRemovePages ()
98105 throws IOException {
99106
100- List <Integer > pageNumberToKeep = new ArrayList <>();
101- pageNumberToKeep .add (1 );
107+ PageOptions pageOptions = new PageOptions .Builder ()
108+ .pageIndexes (new Integer []{1 })
109+ .operation (PageOptionsOperation .REMOVE )
110+ .onMinPages (5 )
111+ .build ();
102112
103113 SplitQuery splitQuery = new SplitQuery (
104114 Files .readAllBytes (new File ("src/test/resources/file_types/pdf/multipage_cut-2.pdf" ).toPath ()),
105- new PageOptions ( pageNumberToKeep , PageOptionsOperation . REMOVE , 5 )
115+ pageOptions
106116 );
107117 SplitPdf splitPdf = pdfOperation .split (splitQuery );
108118
@@ -115,14 +125,14 @@ public void givenADocumentAndListPagesToRemoveAndMinPagesCondition_whenSplit_mus
115125 public void givenADocumentAndNegativeListPagesToKeep_whenSplit_thenReturnsOnlyKeptPages ()
116126 throws IOException {
117127
118- List < Integer > pageNumberToKeep = new ArrayList <>();
119- pageNumberToKeep . add ( 1 );
120- pageNumberToKeep . add (- 2 );
121- pageNumberToKeep . add (- 1 );
128+ PageOptions pageOptions = new PageOptions . Builder ()
129+ . pageIndexes ( new Integer []{ 1 ,- 2 ,- 1 })
130+ . operation ( PageOptionsOperation . KEEP_ONLY )
131+ . build ( );
122132
123133 SplitQuery splitQuery = new SplitQuery (
124134 Files .readAllBytes (new File ("src/test/resources/file_types/pdf/multipage.pdf" ).toPath ()),
125- new PageOptions ( pageNumberToKeep , PageOptionsOperation . KEEP_ONLY , 0 )
135+ pageOptions
126136 );
127137 SplitPdf splitPdf = pdfOperation .split (splitQuery );
128138
0 commit comments