@@ -42,11 +42,11 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .barcodes ;
44
44
45
+ import com .itextpdf .barcodes .exceptions .BarcodeExceptionMessageConstant ;
45
46
import com .itextpdf .io .image .ImageData ;
46
47
import com .itextpdf .io .image .ImageDataFactory ;
47
- import com .itextpdf .barcodes .exceptions .BarcodeExceptionMessageConstant ;
48
- import com .itextpdf .kernel .exceptions .PdfException ;
49
48
import com .itextpdf .kernel .colors .ColorConstants ;
49
+ import com .itextpdf .kernel .exceptions .PdfException ;
50
50
import com .itextpdf .kernel .pdf .PdfDocument ;
51
51
import com .itextpdf .kernel .pdf .PdfPage ;
52
52
import com .itextpdf .kernel .pdf .PdfReader ;
@@ -63,28 +63,24 @@ This file is part of the iText (R) project.
63
63
import java .io .IOException ;
64
64
import org .junit .Assert ;
65
65
import org .junit .BeforeClass ;
66
- import org .junit .Rule ;
67
66
import org .junit .Test ;
68
67
import org .junit .experimental .categories .Category ;
69
- import org .junit .rules .ExpectedException ;
70
68
71
69
@ Category (IntegrationTest .class )
72
70
public class BarcodePDF417Test extends ExtendedITextTest {
73
- public static final String sourceFolder = "./src/test/resources/com/itextpdf/barcodes/" ;
74
- public static final String destinationFolder = "./target/test/com/itextpdf/barcodes/BarcodePDF417/" ;
75
71
76
- @ Rule
77
- public ExpectedException junitExpectedException = ExpectedException . none () ;
72
+ private static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/barcodes/" ;
73
+ private static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/barcodes/BarcodePDF417/" ;
78
74
79
75
@ BeforeClass
80
76
public static void beforeClass () {
81
- createDestinationFolder ( destinationFolder );
77
+ createOrClearDestinationFolder ( DESTINATION_FOLDER );
82
78
}
83
79
84
80
@ Test
85
81
public void barcode01Test () throws IOException , PdfException , InterruptedException {
86
82
String filename = "barcode417_01.pdf" ;
87
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
83
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
88
84
PdfDocument document = new PdfDocument (writer );
89
85
90
86
PdfPage page = document .addNewPage ();
@@ -101,14 +97,15 @@ public void barcode01Test() throws IOException, PdfException, InterruptedExcepti
101
97
102
98
document .close ();
103
99
104
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
100
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename , SOURCE_FOLDER + "cmp_" + filename ,
101
+ DESTINATION_FOLDER , "diff_" ));
105
102
}
106
103
107
104
@ Test
108
105
public void barcode02Test () throws IOException , PdfException , InterruptedException {
109
106
String filename = "barcode417_02.pdf" ;
110
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
111
- PdfReader reader = new PdfReader (sourceFolder + "DocumentWithTrueTypeFont1.pdf" );
107
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
108
+ PdfReader reader = new PdfReader (SOURCE_FOLDER + "DocumentWithTrueTypeFont1.pdf" );
112
109
PdfDocument document = new PdfDocument (reader , writer );
113
110
114
111
PdfCanvas canvas = new PdfCanvas (document .getLastPage ());
@@ -124,13 +121,14 @@ public void barcode02Test() throws IOException, PdfException, InterruptedExcepti
124
121
125
122
document .close ();
126
123
127
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
124
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename , SOURCE_FOLDER + "cmp_" + filename ,
125
+ DESTINATION_FOLDER , "diff_" ));
128
126
}
129
127
130
128
@ Test
131
129
public void macroPDF417Test01 () throws IOException , InterruptedException {
132
130
String filename = "barcode417Macro_01.pdf" ;
133
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
131
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
134
132
PdfDocument pdfDocument = new PdfDocument (writer );
135
133
136
134
PdfCanvas pdfCanvas = new PdfCanvas (pdfDocument .addNewPage ());
@@ -140,7 +138,8 @@ public void macroPDF417Test01() throws IOException, InterruptedException {
140
138
141
139
pdfDocument .close ();
142
140
143
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
141
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename , SOURCE_FOLDER + "cmp_" + filename ,
142
+ DESTINATION_FOLDER , "diff_" ));
144
143
}
145
144
146
145
@ Test
@@ -195,7 +194,7 @@ public void barcode417DefaultParamsTest() {
195
194
@ Test
196
195
public void barcode417CreateAWTImageTest () throws IOException , InterruptedException {
197
196
String filename = "barcode417CreateAWTImageTest.pdf" ;
198
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
197
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
199
198
PdfDocument document = new PdfDocument (writer );
200
199
201
200
PdfPage page = document .addNewPage ();
@@ -216,14 +215,14 @@ public void barcode417CreateAWTImageTest() throws IOException, InterruptedExcept
216
215
217
216
document .close ();
218
217
219
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename ,
220
- sourceFolder + "cmp_" + filename , destinationFolder ));
218
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename ,
219
+ SOURCE_FOLDER + "cmp_" + filename , DESTINATION_FOLDER ));
221
220
}
222
221
223
222
@ Test
224
223
public void barcode417XObjectTest () throws IOException , InterruptedException {
225
224
String filename = "barcode417XObjectTest.pdf" ;
226
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
225
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
227
226
PdfDocument document = new PdfDocument (writer );
228
227
229
228
PdfPage page = document .addNewPage ();
@@ -242,8 +241,8 @@ public void barcode417XObjectTest() throws IOException, InterruptedException {
242
241
243
242
document .close ();
244
243
245
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename ,
246
- sourceFolder + "cmp_" + filename , destinationFolder ));
244
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename ,
245
+ SOURCE_FOLDER + "cmp_" + filename , DESTINATION_FOLDER ));
247
246
}
248
247
249
248
@ Test
@@ -273,7 +272,7 @@ public void barcode417YHeightTest() {
273
272
@ Test
274
273
public void barcode417CodeReuseTest () throws IOException , InterruptedException {
275
274
String filename = "barcode417CodeReuseTest.pdf" ;
276
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
275
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
277
276
PdfDocument document = new PdfDocument (writer );
278
277
279
278
PdfCanvas canvas = new PdfCanvas (document .addNewPage ());
@@ -295,14 +294,14 @@ public void barcode417CodeReuseTest() throws IOException, InterruptedException {
295
294
296
295
document .close ();
297
296
298
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename ,
299
- sourceFolder + "cmp_" + filename , destinationFolder ));
297
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename ,
298
+ SOURCE_FOLDER + "cmp_" + filename , DESTINATION_FOLDER ));
300
299
}
301
300
302
301
@ Test
303
302
public void barcode417NumbersTest () throws IOException , InterruptedException {
304
303
String filename = "barcode417NumbersTest.pdf" ;
305
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
304
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
306
305
PdfDocument document = new PdfDocument (writer );
307
306
308
307
PdfCanvas canvas = new PdfCanvas (document .addNewPage ());
@@ -315,14 +314,14 @@ public void barcode417NumbersTest() throws IOException, InterruptedException {
315
314
316
315
document .close ();
317
316
318
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename ,
319
- sourceFolder + "cmp_" + filename , destinationFolder ));
317
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename ,
318
+ SOURCE_FOLDER + "cmp_" + filename , DESTINATION_FOLDER ));
320
319
}
321
320
322
321
@ Test
323
322
public void barcode417ByteLessThanSixSizeNumbersTest () throws IOException , InterruptedException {
324
323
String filename = "barcode417ByteLessThanSixSizeNumbersTest.pdf" ;
325
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
324
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
326
325
PdfDocument document = new PdfDocument (writer );
327
326
328
327
PdfCanvas canvas = new PdfCanvas (document .addNewPage ());
@@ -335,14 +334,14 @@ public void barcode417ByteLessThanSixSizeNumbersTest() throws IOException, Inter
335
334
336
335
document .close ();
337
336
338
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename ,
339
- sourceFolder + "cmp_" + filename , destinationFolder ));
337
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename ,
338
+ SOURCE_FOLDER + "cmp_" + filename , DESTINATION_FOLDER ));
340
339
}
341
340
342
341
@ Test
343
342
public void barcode417ByteMoreThanSixSizeNumbersTest () throws IOException , InterruptedException {
344
343
String filename = "barcode417ByteMoreThanSixSizeNumbersTest.pdf" ;
345
- PdfWriter writer = new PdfWriter (destinationFolder + filename );
344
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + filename );
346
345
PdfDocument document = new PdfDocument (writer );
347
346
348
347
PdfCanvas canvas = new PdfCanvas (document .addNewPage ());
@@ -355,8 +354,8 @@ public void barcode417ByteMoreThanSixSizeNumbersTest() throws IOException, Inter
355
354
356
355
document .close ();
357
356
358
- Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename ,
359
- sourceFolder + "cmp_" + filename , destinationFolder ));
357
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + filename ,
358
+ SOURCE_FOLDER + "cmp_" + filename , DESTINATION_FOLDER ));
360
359
}
361
360
362
361
@ Test
@@ -460,36 +459,33 @@ public void barcode417OptionsWithBarcodeGenerationInvalidSizeTest() {
460
459
461
460
@ Test
462
461
public void lenCodewordsIsNotEnoughTest () {
463
- junitExpectedException .expect (PdfException .class );
464
- junitExpectedException .expectMessage (BarcodeExceptionMessageConstant .INVALID_CODEWORD_SIZE );
465
-
466
462
BarcodePDF417 barcodePDF417 = new BarcodePDF417 ();
467
463
barcodePDF417 .setOptions (BarcodePDF417 .PDF417_USE_RAW_CODEWORDS );
468
- barcodePDF417 .paintCode ();
464
+ Exception exception = Assert .assertThrows (PdfException .class ,
465
+ () -> barcodePDF417 .paintCode ());
466
+ Assert .assertEquals (BarcodeExceptionMessageConstant .INVALID_CODEWORD_SIZE , exception .getMessage ());
469
467
}
470
468
471
469
@ Test
472
470
public void lenCodewordsIsTooSmallTest () {
473
- junitExpectedException .expect (PdfException .class );
474
- junitExpectedException .expectMessage (BarcodeExceptionMessageConstant .INVALID_CODEWORD_SIZE );
475
-
476
471
BarcodePDF417 barcodePDF417 = new BarcodePDF417 ();
477
472
barcodePDF417 .setOptions (BarcodePDF417 .PDF417_USE_RAW_CODEWORDS );
478
473
// lenCodeWords should be bigger than 1
479
474
barcodePDF417 .setLenCodewords (0 );
480
- barcodePDF417 .paintCode ();
475
+ Exception exception = Assert .assertThrows (PdfException .class ,
476
+ () -> barcodePDF417 .paintCode ());
477
+ Assert .assertEquals (BarcodeExceptionMessageConstant .INVALID_CODEWORD_SIZE , exception .getMessage ());
481
478
}
482
479
483
480
@ Test
484
481
public void lenCodewordsMoreThanMaxDataCodewordsTest () {
485
- junitExpectedException .expect (PdfException .class );
486
- junitExpectedException .expectMessage (BarcodeExceptionMessageConstant .INVALID_CODEWORD_SIZE );
487
-
488
482
BarcodePDF417 barcodePDF417 = new BarcodePDF417 ();
489
483
barcodePDF417 .setOptions (BarcodePDF417 .PDF417_USE_RAW_CODEWORDS );
490
484
// lenCodeWords should be smaller than MAX_DATA_CODEWORDS
491
485
barcodePDF417 .setLenCodewords (927 );
492
- barcodePDF417 .paintCode ();
486
+ Exception exception = Assert .assertThrows (PdfException .class ,
487
+ () -> barcodePDF417 .paintCode ());
488
+ Assert .assertEquals (BarcodeExceptionMessageConstant .INVALID_CODEWORD_SIZE , exception .getMessage ());
493
489
}
494
490
495
491
private PdfFormXObject createMacroBarcodePart (PdfDocument document , String text , float mh , float mw , int segmentId ) {
0 commit comments