Skip to content

Commit 1798b0b

Browse files
author
glenn.volckaert
committed
Add generic types to casting to AbstractPdfFunction
Cleanup of PdfFunctionFactoryTest DEVSIX-3538
1 parent 014fb72 commit 1798b0b

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/colorspace/PdfSpecialCs.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public Separation(String name, PdfColorSpace alternateSpace, PdfFunction tintTra
154154
* to the alternate color space
155155
*/
156156
public Separation(String name, PdfColorSpace alternateSpace, IPdfFunction tintTransform) {
157-
this(new PdfName(name), alternateSpace.getPdfObject(), ((AbstractPdfFunction)tintTransform).getPdfObject());
157+
this(new PdfName(name), alternateSpace.getPdfObject(),
158+
((AbstractPdfFunction<PdfDictionary>)tintTransform).getPdfObject());
158159
if (!tintTransform.checkCompatibilityWithColorSpace(alternateSpace)) {
159160
throw new PdfException(
160161
KernelExceptionMessageConstant.FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE, this);
@@ -237,7 +238,7 @@ public DeviceN(List<String> names, PdfColorSpace alternateSpace, PdfFunction tin
237238
*/
238239
public DeviceN(List<String> names, PdfColorSpace alternateSpace, IPdfFunction tintTransform) {
239240
this(new PdfArray(names, true), alternateSpace.getPdfObject(),
240-
((AbstractPdfFunction)tintTransform).getPdfObject());
241+
((AbstractPdfFunction<PdfDictionary>)tintTransform).getPdfObject());
241242
if (tintTransform.getInputSize() != numOfComponents ||
242243
tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
243244
throw new PdfException(
@@ -312,7 +313,7 @@ public NChannel(List<String> names, PdfColorSpace alternateSpace, PdfFunction ti
312313
public NChannel(List<String> names, PdfColorSpace alternateSpace, IPdfFunction tintTransform,
313314
PdfDictionary attributes) {
314315
this(new PdfArray(names, true), alternateSpace.getPdfObject(),
315-
((AbstractPdfFunction)tintTransform).getPdfObject(), attributes);
316+
((AbstractPdfFunction<PdfDictionary>)tintTransform).getPdfObject(), attributes);
316317
if (tintTransform.getInputSize() != 1 ||
317318
tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
318319
throw new PdfException(

kernel/src/test/java/com/itextpdf/kernel/pdf/function/BaseInputOutPutConvertorsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public void testInvalidOffsetAndLength() throws IOException {
7878

7979
@Test
8080
public void testInvalidLengthForWordSize() throws IOException {
81-
BaseInputOutPutConvertors.IInputConversionFunction inputConvertor = BaseInputOutPutConvertors.getInputConvertor(1, 1);
81+
BaseInputOutPutConvertors.IInputConversionFunction inputConvertor = BaseInputOutPutConvertors.getInputConvertor(
82+
1, 1);
8283

8384
BaseInputOutPutConvertors.IOutputConversionFunction outputConvertor = BaseInputOutPutConvertors.getOutputConvertor(1, 1);
8485

kernel/src/test/java/com/itextpdf/kernel/pdf/function/PdfFunctionFactoryTest.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import com.itextpdf.kernel.pdf.PdfName;
77
import com.itextpdf.kernel.pdf.PdfNumber;
88
import com.itextpdf.kernel.pdf.PdfStream;
9+
import com.itextpdf.test.ExtendedITextTest;
10+
import com.itextpdf.test.annotations.type.IntegrationTest;
911

10-
import junit.framework.TestCase;
1112
import org.junit.Assert;
1213
import org.junit.Test;
14+
import org.junit.experimental.categories.Category;
1315

14-
public class PdfFunctionFactoryTest extends TestCase {
16+
@Category(IntegrationTest.class)
17+
public class PdfFunctionFactoryTest extends ExtendedITextTest {
1518

1619
@Test
1720
public void testCreateFunctionType0() {
@@ -24,7 +27,7 @@ public void testCreateFunctionType0() {
2427
stream.put(PdfName.BitsPerSample, new PdfNumber(1));
2528
IPdfFunction function = PdfFunctionFactory.create(stream);
2629

27-
assertTrue(function instanceof PdfType0Function);
30+
Assert.assertTrue(function instanceof PdfType0Function);
2831
}
2932

3033
@Test
@@ -36,7 +39,7 @@ public void testCreateFunctionType2() {
3639
object.put(PdfName.N, new PdfNumber(2));
3740
IPdfFunction function = PdfFunctionFactory.create(object);
3841

39-
assertTrue(function instanceof PdfType2Function);
42+
Assert.assertTrue(function instanceof PdfType2Function);
4043
}
4144

4245
@Test
@@ -54,7 +57,7 @@ public void testCreateFunctionType3() {
5457
object.put(PdfName.Encode, new PdfArray(new double[] {0, 1, 0, 1}));
5558
IPdfFunction function = PdfFunctionFactory.create(object);
5659

57-
assertTrue(function instanceof PdfType3Function);
60+
Assert.assertTrue(function instanceof PdfType3Function);
5861
}
5962

6063

@@ -69,7 +72,7 @@ public void testCreateFunctionType4() {
6972
stream.put(PdfName.BitsPerSample, new PdfNumber(1));
7073
IPdfFunction function = PdfFunctionFactory.create(stream);
7174

72-
assertTrue(function instanceof PdfType4Function);
75+
Assert.assertTrue(function instanceof PdfType4Function);
7376
}
7477

7578

@@ -82,9 +85,9 @@ public void testInvalidFunctionTypeThrowsException() {
8285
stream.put(PdfName.Range, new PdfArray(
8386
new double[] {1,2,3,4,5,6}));
8487
stream.put(PdfName.BitsPerSample, new PdfNumber(1));
85-
PdfException ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(stream));
88+
Exception ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(stream));
8689

87-
assertEquals("Invalid function type 1", ex.getMessage());
90+
Assert.assertEquals("Invalid function type 1", ex.getMessage());
8891
}
8992

9093
@Test
@@ -96,9 +99,9 @@ public void testDictionaryForType0Throws() {
9699
dict.put(PdfName.Range, new PdfArray(
97100
new double[] {1,2,3,4,5,6}));
98101
dict.put(PdfName.BitsPerSample, new PdfNumber(1));
99-
PdfException ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(dict));
102+
Exception ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(dict));
100103

101-
assertEquals("Invalid object type, a function type 0 requires a stream object", ex.getMessage());
104+
Assert.assertEquals("Invalid object type, a function type 0 requires a stream object", ex.getMessage());
102105
}
103106

104107
@Test
@@ -110,16 +113,16 @@ public void testDictionaryForType4Throws() {
110113
dict.put(PdfName.Range, new PdfArray(
111114
new double[] {1,2,3,4,5,6}));
112115
dict.put(PdfName.BitsPerSample, new PdfNumber(1));
113-
PdfException ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(dict));
116+
Exception ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(dict));
114117

115-
assertEquals("Invalid object type, a function type 4 requires a stream object", ex.getMessage());
118+
Assert.assertEquals("Invalid object type, a function type 4 requires a stream object", ex.getMessage());
116119
}
117120

118121
@Test
119122
public void testArrayThrows() {
120123
PdfArray array = new PdfArray();
121-
PdfException ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(array));
124+
Exception ex = Assert.assertThrows(PdfException.class, () -> PdfFunctionFactory.create(array));
122125

123-
assertEquals("Invalid object type, a function must be either a Dictionary or a Stream", ex.getMessage());
126+
Assert.assertEquals("Invalid object type, a function must be either a Dictionary or a Stream", ex.getMessage());
124127
}
125128
}

0 commit comments

Comments
 (0)