You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/09/04 17:22:58 UTC
svn commit: r1881467 -
/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
Author: tilman
Date: Fri Sep 4 17:22:58 2020
New Revision: 1881467
URL: http://svn.apache.org/viewvc?rev=1881467&view=rev
Log:
PDFBOX-4892: SonarQube fix
Modified:
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java?rev=1881467&r1=1881466&r2=1881467&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java Fri Sep 4 17:22:58 2020
@@ -75,28 +75,28 @@ public class COSArrayListTest {
annotationsList.add(txtLink);
annotationsList.add(aCircle);
annotationsList.add(txtLink);
- assertTrue(annotationsList.size() == 4);
+ assertEquals(4, annotationsList.size());
tbcAnnotationsList = new ArrayList<>();
tbcAnnotationsList.add(txtMark);
tbcAnnotationsList.add(txtLink);
tbcAnnotationsList.add(aCircle);
tbcAnnotationsList.add(txtLink);
- assertTrue(tbcAnnotationsList.size() == 4);
+ assertEquals(4, tbcAnnotationsList.size());
annotationsArray = new COSArray();
annotationsArray.add(txtMark);
annotationsArray.add(txtLink);
annotationsArray.add(aCircle);
annotationsArray.add(txtLink);
- assertTrue(annotationsArray.size() == 4);
+ assertEquals(4, annotationsArray.size());
tbcAnnotationsArray = new COSBase[4];
tbcAnnotationsArray[0] = txtMark.getCOSObject();
tbcAnnotationsArray[1] = txtLink.getCOSObject();
tbcAnnotationsArray[2] = aCircle.getCOSObject();
tbcAnnotationsArray[3] = txtLink.getCOSObject();
- assertTrue(tbcAnnotationsArray.length == 4);
+ assertEquals(4, tbcAnnotationsArray.length);
// add the annotations to the page
pdPage = new PDPage();
@@ -114,15 +114,15 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> cosArrayList = new COSArrayList<>(annotationsList, annotationsArray);
for (int i = 0; i < cosArrayList.size(); i++) {
- PDAnnotation annot = (PDAnnotation) cosArrayList.get(i);
+ PDAnnotation annot = cosArrayList.get(i);
assertTrue("PDAnnotations cosObject at " + i + " shall be equal to index " + i + " of COSArray",
- annotationsArray.get(i).equals(annot.getCOSObject()));
+ annotationsArray.get(i).equals(annot.getCOSObject()));
// compare with Java List/Array
assertTrue("PDAnnotations at " + i + " shall be at index " + i + " of List",
- tbcAnnotationsList.get(i).equals((annot)));
+ tbcAnnotationsList.get(i).equals((annot)));
assertEquals("PDAnnotations cosObject at " + i + " shall be at position " + i + " of Array",
- tbcAnnotationsArray[i], annot.getCOSObject());
+ tbcAnnotationsArray[i], annot.getCOSObject());
}
}
@@ -137,12 +137,12 @@ public class COSArrayListTest {
PDAnnotationSquare aSquare = new PDAnnotationSquare();
cosArrayList.add(aSquare);
- assertTrue("List size shall be 5", annotationsList.size() == 5);
- assertTrue("COSArray size shall be 5", annotationsArray.size() == 5);
+ assertEquals("List size shall be 5", 5, annotationsList.size());
+ assertEquals("COSArray size shall be 5", 5, annotationsArray.size());
- PDAnnotation annot = (PDAnnotation) annotationsList.get(4);
- assertTrue("Added annotation shall be 4th entry in COSArray",
- annotationsArray.indexOf(annot.getCOSObject()) == 4);
+ PDAnnotation annot = annotationsList.get(4);
+ assertEquals("Added annotation shall be 4th entry in COSArray",
+ 4, annotationsArray.indexOf(annot.getCOSObject()));
assertEquals("Provided COSArray and underlying COSArray shall be equal", annotationsArray,
cosArrayList.toList());
}
@@ -159,13 +159,13 @@ public class COSArrayListTest {
assertEquals("Remove operation shall return the removed object", toBeRemoved,
cosArrayList.remove(positionToRemove));
- assertTrue("List size shall be 3", cosArrayList.size() == 3);
- assertTrue("COSArray size shall be 3", annotationsArray.size() == 3);
+ assertEquals("List size shall be 3", 3, cosArrayList.size());
+ assertEquals("COSArray size shall be 3", 3, annotationsArray.size());
- assertTrue("PDAnnotation shall no longer exist in List",
- cosArrayList.indexOf(tbcAnnotationsList.get(positionToRemove)) == -1);
- assertTrue("COSObject shall no longer exist in COSArray",
- annotationsArray.indexOf(tbcAnnotationsArray[positionToRemove]) == -1);
+ assertEquals("PDAnnotation shall no longer exist in List",
+ -1, cosArrayList.indexOf(tbcAnnotationsList.get(positionToRemove)));
+ assertEquals("COSObject shall no longer exist in COSArray",
+ -1, annotationsArray.indexOf(tbcAnnotationsArray[positionToRemove]));
}
/**
@@ -180,21 +180,21 @@ public class COSArrayListTest {
PDAnnotation toBeRemoved = annotationsList.get(positionToRemove);
assertTrue("Remove operation shall return true", cosArrayList.remove(toBeRemoved));
- assertTrue("List size shall be 3", cosArrayList.size() == 3);
- assertTrue("COSArray size shall be 3", annotationsArray.size() == 3);
+ assertEquals("List size shall be 3", 3, cosArrayList.size());
+ assertEquals("COSArray size shall be 3", 3, annotationsArray.size());
// compare with Java List/Array to ensure correct object at position
- assertTrue("List object at 3 is at position 2 in COSArrayList now",
- cosArrayList.get(2).equals(tbcAnnotationsList.get(3)));
- assertTrue("COSObject of List object at 3 is at position 2 in COSArray now",
- annotationsArray.get(2).equals(tbcAnnotationsList.get(3).getCOSObject()));
- assertTrue("Array object at 3 is at position 2 in underlying COSArray now",
- annotationsArray.get(2).equals(tbcAnnotationsArray[3]));
-
- assertTrue("PDAnnotation shall no longer exist in List",
- cosArrayList.indexOf(tbcAnnotationsList.get(positionToRemove)) == -1);
- assertTrue("COSObject shall no longer exist in COSArray",
- annotationsArray.indexOf(tbcAnnotationsArray[positionToRemove]) == -1);
+ assertEquals("List object at 3 is at position 2 in COSArrayList now",
+ cosArrayList.get(2), tbcAnnotationsList.get(3));
+ assertEquals("COSObject of List object at 3 is at position 2 in COSArray now",
+ annotationsArray.get(2), tbcAnnotationsList.get(3).getCOSObject());
+ assertEquals("Array object at 3 is at position 2 in underlying COSArray now",
+ annotationsArray.get(2), tbcAnnotationsArray[3]);
+
+ assertEquals("PDAnnotation shall no longer exist in List",
+ -1, cosArrayList.indexOf(tbcAnnotationsList.get(positionToRemove)));
+ assertEquals("COSObject shall no longer exist in COSArray",
+ -1, annotationsArray.indexOf(tbcAnnotationsArray[positionToRemove]));
assertFalse("Remove shall not remove any object", cosArrayList.remove(toBeRemoved));
@@ -214,8 +214,8 @@ public class COSArrayListTest {
List<PDAnnotation> toBeRemovedInstances = Collections.singletonList(toBeRemoved);
assertTrue("Remove operation shall return true", cosArrayList.removeAll(toBeRemovedInstances));
- assertTrue("List size shall be 3", cosArrayList.size() == 3);
- assertTrue("COSArray size shall be 3", annotationsArray.size() == 3);
+ assertEquals("List size shall be 3", 3, cosArrayList.size());
+ assertEquals("COSArray size shall be 3", 3, annotationsArray.size());
assertFalse("Remove shall not remove any object", cosArrayList.removeAll(toBeRemovedInstances));
}
@@ -232,13 +232,12 @@ public class COSArrayListTest {
PDAnnotation toBeRemoved = tbcAnnotationsList.get(positionToRemove);
assertTrue("Remove operation shall return true", cosArrayList.remove(toBeRemoved));
- assertTrue("List size shall be 3", cosArrayList.size() == 3);
- assertTrue("COSArray size shall be 3", annotationsArray.size() == 3);
+ assertEquals("List size shall be 3", 3, cosArrayList.size());
+ assertEquals("COSArray size shall be 3", 3, annotationsArray.size());
assertTrue("Remove operation shall return true", cosArrayList.remove(toBeRemoved));
- assertTrue("List size shall be 2", cosArrayList.size() == 2);
- assertTrue("COSArray size shall be 2", annotationsArray.size() == 2);
-
+ assertEquals("List size shall be 2", 2, cosArrayList.size());
+ assertEquals("COSArray size shall be 2", 2, annotationsArray.size());
}
/**
@@ -255,8 +254,8 @@ public class COSArrayListTest {
List<PDAnnotation> toBeRemovedInstances = Collections.singletonList(toBeRemoved);
assertTrue("Remove operation shall return true", cosArrayList.removeAll(toBeRemovedInstances));
- assertTrue("List size shall be 2", cosArrayList.size() == 2);
- assertTrue("COSArray size shall be 2", annotationsArray.size() == 2);
+ assertEquals("List size shall be 2", 2, cosArrayList.size());
+ assertEquals("COSArray size shall be 2", 2, annotationsArray.size());
assertFalse("Remove shall not remove any object", cosArrayList.removeAll(toBeRemovedInstances));
}
@@ -309,12 +308,11 @@ public class COSArrayListTest {
pageAnnots.add(txtMark);
pageAnnots.add(txtMark);
pageAnnots.add(txtLink);
- assertTrue("There shall be 4 annotations generated", pageAnnots.size() == 4);
+ assertEquals("There shall be 4 annotations generated", 4, pageAnnots.size());
page.setAnnotations(pageAnnots);
pdf.save(OUT_DIR + "/removeSingleDirectObjectTest.pdf");
- pdf.close();
}
try (PDDocument pdf = Loader.loadPDF(new File(OUT_DIR + "/removeSingleDirectObjectTest.pdf"))) {
@@ -322,14 +320,14 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> annotations = (COSArrayList) page.getAnnotations();
- assertTrue("There shall be 4 annotations retrieved", annotations.size() == 4);
- assertTrue("The size of the internal COSArray shall be 4", annotations.toList().size() == 4);
+ assertEquals("There shall be 4 annotations retrieved", 4, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 4", 4, annotations.toList().size());
PDAnnotation toBeRemoved = annotations.get(0);
annotations.remove(toBeRemoved);
- assertTrue("There shall be 3 annotations left", annotations.size() == 3);
- assertTrue("The size of the internal COSArray shall be 3", annotations.toList().size() == 3);
+ assertEquals("There shall be 3 annotations left", 3, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 3", 3, annotations.toList().size());
}
}
@@ -349,12 +347,11 @@ public class COSArrayListTest {
pageAnnots.add(txtMark);
pageAnnots.add(txtMark);
pageAnnots.add(txtLink);
- assertTrue("There shall be 4 annotations generated", pageAnnots.size() == 4);
+ assertEquals("There shall be 4 annotations generated", 4, pageAnnots.size());
page.setAnnotations(pageAnnots);
pdf.save(OUT_DIR + "/removeSingleIndirectObjectTest.pdf");
- pdf.close();
}
try (PDDocument pdf = Loader.loadPDF(new File(OUT_DIR + "/removeSingleIndirectObjectTest.pdf"))) {
@@ -362,15 +359,15 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> annotations = (COSArrayList) page.getAnnotations();
- assertTrue("There shall be 4 annotations retrieved", annotations.size() == 4);
- assertTrue("The size of the internal COSArray shall be 4", annotations.toList().size() == 4);
+ assertEquals("There shall be 4 annotations retrieved", 4, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 4", 4, annotations.toList().size());
PDAnnotation toBeRemoved = annotations.get(0);
annotations.remove(toBeRemoved);
- assertTrue("There shall be 3 annotations left", annotations.size() == 3);
- assertTrue("The size of the internal COSArray shall be 2", annotations.toList().size() == 3);
+ assertEquals("There shall be 3 annotations left", 3, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 2", 3, annotations.toList().size());
}
}
@@ -394,12 +391,11 @@ public class COSArrayListTest {
pageAnnots.add(txtMark);
pageAnnots.add(txtMark);
pageAnnots.add(txtLink);
- assertTrue("There shall be 4 annotations generated", pageAnnots.size() == 4);
+ assertEquals("There shall be 4 annotations generated", 4, pageAnnots.size());
page.setAnnotations(pageAnnots);
pdf.save(OUT_DIR + "/removeDirectObjectTest.pdf");
- pdf.close();
}
try (PDDocument pdf = Loader.loadPDF(new File(OUT_DIR + "/removeDirectObjectTest.pdf"))) {
@@ -407,16 +403,16 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> annotations = (COSArrayList) page.getAnnotations();
- assertTrue("There shall be 4 annotations retrieved", annotations.size() == 4);
- assertTrue("The size of the internal COSArray shall be 4", annotations.toList().size() == 4);
+ assertEquals("There shall be 4 annotations retrieved", 4, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 4", 4, annotations.toList().size());
ArrayList<PDAnnotation> toBeRemoved = new ArrayList<>();
toBeRemoved.add(annotations.get(0));
annotations.removeAll(toBeRemoved);
- assertTrue("There shall be 1 annotations left", annotations.size() == 1);
- assertTrue("The size of the internal COSArray shall be 1", annotations.toList().size() == 1);
+ assertEquals("There shall be 1 annotations left", 1, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 1", 1, annotations.toList().size());
}
}
@@ -436,12 +432,11 @@ public class COSArrayListTest {
pageAnnots.add(txtMark);
pageAnnots.add(txtMark);
pageAnnots.add(txtLink);
- assertTrue("There shall be 4 annotations generated", pageAnnots.size() == 4);
+ assertEquals("There shall be 4 annotations generated", 4, pageAnnots.size());
page.setAnnotations(pageAnnots);
pdf.save(OUT_DIR + "/removeIndirectObjectTest.pdf");
- pdf.close();
}
try (PDDocument pdf = Loader.loadPDF(new File(OUT_DIR + "/removeIndirectObjectTest.pdf"))) {
@@ -449,16 +444,16 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> annotations = (COSArrayList) page.getAnnotations();
- assertTrue("There shall be 4 annotations retrieved", annotations.size() == 4);
- assertTrue("The size of the internal COSArray shall be 4", annotations.toList().size() == 4);
+ assertEquals("There shall be 4 annotations retrieved", 4, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 4", 4, annotations.toList().size());
ArrayList<PDAnnotation> toBeRemoved = new ArrayList<>();
toBeRemoved.add(annotations.get(0));
annotations.removeAll(toBeRemoved);
- assertTrue("There shall be 1 annotations left", annotations.size() == 1);
- assertTrue("The size of the internal COSArray shall be 1", annotations.toList().size() == 1);
+ assertEquals("There shall be 1 annotations left", 1, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 1", 1, annotations.toList().size());
}
}
@@ -482,12 +477,11 @@ public class COSArrayListTest {
pageAnnots.add(txtMark);
pageAnnots.add(txtMark);
pageAnnots.add(txtLink);
- assertTrue("There shall be 4 annotations generated", pageAnnots.size() == 4);
+ assertEquals("There shall be 4 annotations generated", 4, pageAnnots.size());
page.setAnnotations(pageAnnots);
pdf.save(OUT_DIR + "/retainDirectObjectTest.pdf");
- pdf.close();
}
try (PDDocument pdf = Loader.loadPDF(new File(OUT_DIR + "/retainDirectObjectTest.pdf"))) {
@@ -495,16 +489,16 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> annotations = (COSArrayList) page.getAnnotations();
- assertTrue("There shall be 4 annotations retrieved", annotations.size() == 4);
- assertTrue("The size of the internal COSArray shall be 4", annotations.toList().size() == 4);
+ assertEquals("There shall be 4 annotations retrieved", 4, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 4", 4, annotations.toList().size());
ArrayList<PDAnnotation> toBeRetained = new ArrayList<>();
toBeRetained.add(annotations.get(0));
annotations.retainAll(toBeRetained);
- assertTrue("There shall be 3 annotations left", annotations.size() == 3);
- assertTrue("The size of the internal COSArray shall be 3", annotations.toList().size() == 3);
+ assertEquals("There shall be 3 annotations left", 3, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 3", 3, annotations.toList().size());
}
}
@@ -524,12 +518,11 @@ public class COSArrayListTest {
pageAnnots.add(txtMark);
pageAnnots.add(txtMark);
pageAnnots.add(txtLink);
- assertTrue("There shall be 4 annotations generated", pageAnnots.size() == 4);
+ assertEquals("There shall be 4 annotations generated", 4, pageAnnots.size());
page.setAnnotations(pageAnnots);
pdf.save(OUT_DIR + "/removeIndirectObjectTest.pdf");
- pdf.close();
}
try (PDDocument pdf = Loader.loadPDF(new File(OUT_DIR + "/removeIndirectObjectTest.pdf"))) {
@@ -537,16 +530,16 @@ public class COSArrayListTest {
COSArrayList<PDAnnotation> annotations = (COSArrayList) page.getAnnotations();
- assertTrue("There shall be 4 annotations retrieved", annotations.size() == 4);
- assertTrue("The size of the internal COSArray shall be 4", annotations.toList().size() == 4);
+ assertEquals("There shall be 4 annotations retrieved", 4, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 4", 4, annotations.toList().size());
ArrayList<PDAnnotation> toBeRetained = new ArrayList<>();
toBeRetained.add(annotations.get(0));
annotations.retainAll(toBeRetained);
- assertTrue("There shall be 3 annotations left", annotations.size() == 3);
- assertTrue("The size of the internal COSArray shall be 3", annotations.toList().size() == 3);
+ assertEquals("There shall be 3 annotations left", 3, annotations.size());
+ assertEquals("The size of the internal COSArray shall be 3", 3, annotations.toList().size());
}
}
}