Skip to content

Commit 39d3d6a

Browse files
author
Samuel Huylebroeck
committed
Deprecate duplicate methods
Mark methods that had their duplicated logic consolidated inside a super-class Add extra test for SQ coverage DEVSIX-2864
1 parent 70c08bd commit 39d3d6a

File tree

7 files changed

+106
-9
lines changed

7 files changed

+106
-9
lines changed

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfCanvasTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,4 +1952,21 @@ private void setColorTest(String pdfName, boolean pattern) throws IOException, I
19521952

19531953
Assert.assertNull(new CompareTool().compareByContent(destFile, cmpFile, destinationFolder, "diff_"));
19541954
}
1955+
1956+
@Test
1957+
public void endPathNewPathTest(){
1958+
ByteArrayOutputStream boasEndPath = new ByteArrayOutputStream();
1959+
PdfDocument pdfDocEndPath = new PdfDocument(new PdfWriter(boasEndPath));
1960+
pdfDocEndPath.addNewPage();
1961+
1962+
PdfCanvas endPathCanvas = new PdfCanvas(pdfDocEndPath.getPage(1));
1963+
endPathCanvas.endPath();
1964+
1965+
ByteArrayOutputStream boasNewPath = new ByteArrayOutputStream();
1966+
PdfDocument pdfDocNewPath = new PdfDocument(new PdfWriter(boasNewPath));
1967+
pdfDocNewPath.addNewPage();
1968+
PdfCanvas newPathCanvas = new PdfCanvas(pdfDocNewPath.getPage(1));
1969+
newPathCanvas.newPath();
1970+
Assert.assertArrayEquals(boasNewPath.toByteArray(),boasEndPath.toByteArray());
1971+
}
19551972
}

layout/src/main/java/com/itextpdf/layout/borders/DashedBorder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Side
110110
float dy = y2 - y1;
111111
double borderLength = Math.sqrt(dx * dx + dy * dy);
112112

113-
float adjustedGap = getDotsGap(borderLength, initialGap + dash);
113+
float adjustedGap = super.getDotsGap(borderLength, initialGap + dash);
114114
if (adjustedGap > dash) {
115115
adjustedGap -= dash;
116116
}
@@ -144,7 +144,7 @@ public void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float
144144
float dy = y2 - y1;
145145
double borderLength = Math.sqrt(dx * dx + dy * dy);
146146

147-
float adjustedGap = getDotsGap(borderLength, initialGap + dash);
147+
float adjustedGap = super.getDotsGap(borderLength, initialGap + dash);
148148
if (adjustedGap > dash) {
149149
adjustedGap -= dash;
150150
}
@@ -170,7 +170,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
170170
float dx = x2 - x1;
171171
float dy = y2 - y1;
172172
double borderLength = Math.sqrt(dx * dx + dy * dy);
173-
float adjustedGap = getDotsGap(borderLength, initialGap + dash);
173+
float adjustedGap = super.getDotsGap(borderLength, initialGap + dash);
174174
if (adjustedGap > dash) {
175175
adjustedGap -= dash;
176176
}
@@ -194,7 +194,9 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
194194
* @param distance the {@link Border border} length
195195
* @param initialGap the initial size of the gap
196196
* @return the adjusted size of the gap
197+
* @deprecated logic moved to super-class
197198
*/
199+
@Deprecated
198200
protected float getDotsGap(double distance, float initialGap) {
199201
return super.getDotsGap(distance, initialGap);
200202
}

layout/src/main/java/com/itextpdf/layout/borders/DottedBorder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Side
106106
float dy = y2 - y1;
107107
double borderLength = Math.sqrt(dx * dx + dy * dy);
108108

109-
float adjustedGap = getDotsGap(borderLength, initialGap + width);
109+
float adjustedGap = super.getDotsGap(borderLength, initialGap + width);
110110
if (adjustedGap > width) {
111111
adjustedGap -= width;
112112
}
@@ -139,7 +139,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
139139
float dx = x2 - x1;
140140
float dy = y2 - y1;
141141
double borderLength = Math.sqrt(dx * dx + dy * dy);
142-
float adjustedGap = getDotsGap(borderLength, initialGap);
142+
float adjustedGap = super.getDotsGap(borderLength, initialGap);
143143
if (adjustedGap > width) {
144144
adjustedGap -= width;
145145
}
@@ -168,7 +168,7 @@ public void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float
168168
float dy = y2 - y1;
169169
double borderLength = Math.sqrt(dx * dx + dy * dy);
170170

171-
float adjustedGap = getDotsGap(borderLength, initialGap + width);
171+
float adjustedGap = super.getDotsGap(borderLength, initialGap + width);
172172
if (adjustedGap > width) {
173173
adjustedGap -= width;
174174
}
@@ -192,7 +192,9 @@ public void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float
192192
* @param distance the {@link Border border} length
193193
* @param initialGap the initial size of the gap
194194
* @return the adjusted size of the gap
195+
* @deprecated logic moved to super-class
195196
*/
197+
@Deprecated
196198
protected float getDotsGap(double distance, float initialGap) {
197199
return super.getDotsGap(distance, initialGap);
198200
}

layout/src/main/java/com/itextpdf/layout/borders/RoundDotsBorder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Side
105105
float dx = x2 - x1;
106106
float dy = y2 - y1;
107107
double borderLength = Math.sqrt(dx * dx + dy * dy);
108-
float adjustedGap = getDotsGap(borderLength, initialGap);
108+
float adjustedGap = super.getDotsGap(borderLength, initialGap);
109109

110110
float[] startingPoints = getStartingPointsForBorderSide(x1, y1, x2, y2, defaultSide);
111111
x1 = startingPoints[0];
@@ -133,7 +133,7 @@ public void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float
133133
float dx = x2 - x1;
134134
float dy = y2 - y1;
135135
double borderLength = Math.sqrt(dx * dx + dy * dy);
136-
float adjustedGap = getDotsGap(borderLength, initialGap);
136+
float adjustedGap = super.getDotsGap(borderLength, initialGap);
137137
boolean isHorizontal = false;
138138
if (Math.abs(y2 - y1) < 0.0005f) {
139139
isHorizontal = true;
@@ -163,7 +163,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
163163
float dx = x2 - x1;
164164
float dy = y2 - y1;
165165
double borderLength = Math.sqrt(dx * dx + dy * dy);
166-
float adjustedGap = getDotsGap(borderLength, initialGap);
166+
float adjustedGap = super.getDotsGap(borderLength, initialGap);
167167

168168
canvas
169169
.saveState()
@@ -187,7 +187,9 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
187187
* @param distance the {@link Border border} length
188188
* @param initialGap the initial size of the gap
189189
* @return the adjusted size of the gap
190+
* @deprecated logic moved to super-class
190191
*/
192+
@Deprecated
191193
protected float getDotsGap(double distance, float initialGap) {
192194
return super.getDotsGap(distance, initialGap);
193195
}

layout/src/test/java/com/itextpdf/layout/BorderTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,52 @@ private void closeDocumentAndCompareOutputs(Document document) throws IOExceptio
325325
Assert.fail(compareResult);
326326
}
327327
}
328+
329+
330+
//When 7.2 release is in progress, remove the underlying code. It's here to pass A SQ line coverage quality gate and tests deprecated protected methods
331+
public class TestDashedBorder extends DashedBorder {
332+
public TestDashedBorder(float width) {
333+
super(width);
334+
}
335+
public float publicGetDotsGap(double distance,float initialGap){
336+
return getDotsGap(distance, initialGap);
337+
}
338+
}
339+
340+
public class TestDottedBorder extends DottedBorder {
341+
public TestDottedBorder(float width) {
342+
super(width);
343+
}
344+
public float publicGetDotsGap(double distance,float initialGap){
345+
return getDotsGap(distance, initialGap);
346+
}
347+
}
348+
349+
public class TestRoundDotsBorder extends RoundDotsBorder {
350+
public TestRoundDotsBorder(float width) {
351+
super(width);
352+
}
353+
public float publicGetDotsGap(double distance,float initialGap){
354+
return getDotsGap(distance, initialGap);
355+
}
356+
}
357+
358+
@Test
359+
public void getDotsGapTest(){
360+
float expected = 0.2f;
361+
double distance = 0.2;
362+
float initialGap = 0.2f;
363+
364+
TestDashedBorder db = new TestDashedBorder(1f);
365+
TestDottedBorder dotb = new TestDottedBorder(1f);
366+
TestRoundDotsBorder rdb = new TestRoundDotsBorder(1f);
367+
368+
float dbActual = db.publicGetDotsGap(distance,initialGap);
369+
float dotbActual = dotb.publicGetDotsGap(distance,initialGap);
370+
float rdbActual = rdb.publicGetDotsGap(distance,initialGap);
371+
372+
Assert.assertEquals(expected,dbActual,0.0001f);
373+
Assert.assertEquals(expected,dotbActual,0.0001f);
374+
Assert.assertEquals(expected,rdbActual,0.0001f);
375+
}
328376
}

layout/src/test/java/com/itextpdf/layout/TableTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ This file is part of the iText (R) project.
5252
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
5353
import com.itextpdf.kernel.utils.CompareTool;
5454
import com.itextpdf.layout.borders.Border;
55+
import com.itextpdf.layout.borders.DashedBorder;
56+
import com.itextpdf.layout.borders.DottedBorder;
57+
import com.itextpdf.layout.borders.RoundDotsBorder;
5558
import com.itextpdf.layout.borders.SolidBorder;
5659
import com.itextpdf.layout.element.AreaBreak;
5760
import com.itextpdf.layout.element.Cell;
@@ -2636,6 +2639,29 @@ public void captionedTableOfOnePageWithCollapsedBordersTest01() throws IOExcepti
26362639
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
26372640
}
26382641

2642+
@Test
2643+
public void tableWithDifferentStylesOfCollapsedBordersTest() throws IOException, InterruptedException {
2644+
String testName = "tableWithDifferentStylesOfCollapsedBordersTest.pdf";
2645+
String outFileName = destinationFolder + testName;
2646+
String cmpFileName = sourceFolder + "cmp_" + testName;
2647+
2648+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
2649+
Document doc = new Document(pdfDoc);
2650+
2651+
Table table = createTestTable(2, 10, 2, 2, (UnitValue) null, BorderCollapsePropertyValue.COLLAPSE,
2652+
new Style().setBorder(new DashedBorder(ColorConstants.RED, 10)));
2653+
table.getHeader().setBorder(new DottedBorder(ColorConstants.ORANGE, 5f));
2654+
table.getFooter().setBorder(new RoundDotsBorder(ColorConstants.ORANGE, 5f));
2655+
2656+
// no caption
2657+
addTable(table, true, true, doc);
2658+
2659+
doc.close();
2660+
2661+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
2662+
2663+
}
2664+
26392665
@Test
26402666
public void captionedTableOfOnePageWithSeparatedBordersTest01() throws IOException, InterruptedException {
26412667
String testName = "captionedTableOfOnePageWithSeparatedBordersTest01.pdf";

0 commit comments

Comments
 (0)