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/05 11:08:25 UTC
svn commit: r1881494 - in
/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos:
COSDictionaryTest.java TestCOSFloat.java TestCOSInteger.java
TestCOSString.java
Author: tilman
Date: Sat Sep 5 11:08:25 2020
New Revision: 1881494
URL: http://svn.apache.org/viewvc?rev=1881494&view=rev
Log:
PDFBOX-4892: SonarQube fix
Modified:
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/COSDictionaryTest.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSString.java
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/COSDictionaryTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/COSDictionaryTest.java?rev=1881494&r1=1881493&r2=1881494&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/COSDictionaryTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/COSDictionaryTest.java Sat Sep 5 11:08:25 2020
@@ -16,7 +16,7 @@
*/
package org.apache.pdfbox.cos;
-import static org.junit.Assert.assertFalse;
+import org.junit.Assert;
import org.junit.Test;
public class COSDictionaryTest
@@ -29,7 +29,7 @@ public class COSDictionaryTest
cosDictionary.setItem(COSName.BE, COSName.BE);
cosDictionary.setInt(COSName.LENGTH, 0);
cosStream.setItem(COSName.BE, COSName.BE);
- assertFalse("a COSDictionary shall not be equal to a COSStream with the same dictionary entries", cosDictionary.equals(cosStream));
- assertFalse("a COSStream shall not be equal to a COSDictionary with the same dictionary entries", cosStream.equals(cosDictionary));
+ Assert.assertNotEquals("a COSDictionary shall not be equal to a COSStream with the same dictionary entries", cosDictionary, cosStream);
+ Assert.assertNotEquals("a COSStream shall not be equal to a COSDictionary with the same dictionary entries", cosStream, cosDictionary);
}
}
\ No newline at end of file
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java?rev=1881494&r1=1881493&r2=1881494&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSFloat.java Sat Sep 5 11:08:25 2020
@@ -115,18 +115,18 @@ public class TestCOSFloat extends TestCO
COSFloat test2 = new COSFloat(num);
COSFloat test3 = new COSFloat(num);
// Reflexive (x == x)
- assertTrue(test1.equals(test1));
+ Assert.assertEquals(test1, test1);
// Symmetric is preserved ( x==y then y==x)
- assertTrue(test2.equals(test3));
- assertTrue(test3.equals(test2));
+ Assert.assertEquals(test2, test3);
+ Assert.assertEquals(test3, test2);
// Transitive (if x==y && y==z then x==z)
- assertTrue(test1.equals(test2));
- assertTrue(test2.equals(test3));
- assertTrue(test1.equals(test3));
+ Assert.assertEquals(test1, test2);
+ Assert.assertEquals(test2, test3);
+ Assert.assertEquals(test1, test3);
float nf = Float.intBitsToFloat(Float.floatToIntBits(num) + 1);
COSFloat test4 = new COSFloat(nf);
- assertFalse(test4.equals(test1));
+ Assert.assertNotEquals(test4, test1);
}
}.runTests();
}
@@ -139,11 +139,11 @@ public class TestCOSFloat extends TestCO
{
COSFloat test1 = new COSFloat(num);
COSFloat test2 = new COSFloat(num);
- assertEquals(test1.hashCode(), test2.hashCode());
+ Assert.assertEquals(test1.hashCode(), test2.hashCode());
float nf = Float.intBitsToFloat(Float.floatToIntBits(num) + 1);
COSFloat test3 = new COSFloat(nf);
- assertFalse(test3.hashCode() == test1.hashCode());
+ assertNotSame(test3.hashCode(), test1.hashCode());
}
}
@@ -181,7 +181,7 @@ public class TestCOSFloat extends TestCO
void runTest(float num)
{
COSFloat testFloat = new COSFloat(num);
- assertEquals((int) num, testFloat.intValue());
+ Assert.assertEquals((int) num, testFloat.intValue());
}
}
@@ -199,7 +199,7 @@ public class TestCOSFloat extends TestCO
void runTest(float num)
{
COSFloat testFloat = new COSFloat(num);
- assertEquals((long) num, testFloat.longValue());
+ Assert.assertEquals((long) num, testFloat.longValue());
}
}
@@ -222,7 +222,7 @@ public class TestCOSFloat extends TestCO
{
COSFloat cosFloat = new COSFloat(num);
cosFloat.accept(visitor);
- assertEquals(floatToString(cosFloat.floatValue()), outStream.toString("ISO-8859-1"));
+ Assert.assertEquals(floatToString(cosFloat.floatValue()), outStream.toString("ISO-8859-1"));
testByteArrays(floatToString(num).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
outStream.reset();
}
@@ -258,12 +258,12 @@ public class TestCOSFloat extends TestCO
cosFloat.writePDF(outStream);
String expected = floatToString(cosFloat.floatValue());
- assertEquals(expected, outStream.toString("ISO-8859-1"));
- assertEquals("COSFloat{" + expected + "}", cosFloat.toString());
+ Assert.assertEquals(expected, outStream.toString("ISO-8859-1"));
+ Assert.assertEquals("COSFloat{" + expected + "}", cosFloat.toString());
expected = floatToString(num);
- assertEquals(expected, outStream.toString("ISO-8859-1"));
- assertEquals("COSFloat{" + expected + "}", cosFloat.toString());
+ Assert.assertEquals(expected, outStream.toString("ISO-8859-1"));
+ Assert.assertEquals("COSFloat{" + expected + "}", cosFloat.toString());
testByteArrays(expected.getBytes(StandardCharsets.ISO_8859_1),
outStream.toByteArray());
@@ -301,7 +301,7 @@ public class TestCOSFloat extends TestCO
{
double smallValue = Float.MIN_VALUE / 10d;
- assertEquals("Test must be performed with a value smaller than Float.MIN_VALUE.", -1,
+ Assert.assertEquals("Test must be performed with a value smaller than Float.MIN_VALUE.", -1,
Double.compare(smallValue, Float.MIN_VALUE));
// 1.4012984643248171E-46
@@ -331,7 +331,7 @@ public class TestCOSFloat extends TestCO
{
double largeValue = Float.MAX_VALUE * 10d;
- assertEquals("Test must be performed with a value larger than Float.MAX_VALUE.", 1,
+ Assert.assertEquals("Test must be performed with a value larger than Float.MAX_VALUE.", 1,
Double.compare(largeValue, Float.MIN_VALUE));
// 1.4012984643248171E-46
@@ -363,10 +363,10 @@ public class TestCOSFloat extends TestCO
// PDFBOX-3500 has 0.-262
COSFloat cosFloat = new COSFloat("0.00000-33917698");
- assertEquals(new COSFloat("-0.0000033917698"), cosFloat);
+ Assert.assertEquals(new COSFloat("-0.0000033917698"), cosFloat);
cosFloat = new COSFloat("0.-262");
- assertEquals(new COSFloat("-0.262"), cosFloat);
+ Assert.assertEquals(new COSFloat("-0.262"), cosFloat);
}
public void testDuplicateMisplacedNegative()
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java?rev=1881494&r1=1881493&r2=1881494&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java Sat Sep 5 11:08:25 2020
@@ -24,6 +24,7 @@ import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.pdfbox.pdfwriter.COSWriter;
+import org.junit.Assert;
/**
* A test case for COSInteger
@@ -59,17 +60,17 @@ public class TestCOSInteger extends Test
COSInteger test2 = COSInteger.get(i);
COSInteger test3 = COSInteger.get(i);
// Reflexive (x == x)
- assertTrue(test1.equals(test1));
+ Assert.assertEquals(test1, test1);
// Symmetric is preserved ( x==y then y===x)
- assertTrue(test2.equals(test1));
- assertTrue(test1.equals(test2));
+ Assert.assertEquals(test2, test1);
+ Assert.assertEquals(test1, test2);
// Transitive (if x==y && y==z then x===z)
- assertTrue(test1.equals(test2));
- assertTrue(test2.equals(test3));
- assertTrue(test1.equals(test3));
-
+ Assert.assertEquals(test1, test2);
+ Assert.assertEquals(test2, test3);
+ Assert.assertEquals(test1, test3);
+
COSInteger test4 = COSInteger.get(i + 1);
- assertFalse(test4.equals(test1));
+ Assert.assertNotEquals(test4, test1);
}
}
@@ -83,10 +84,10 @@ public class TestCOSInteger extends Test
{
COSInteger test1 = COSInteger.get(i);
COSInteger test2 = COSInteger.get(i);
- assertEquals(test1.hashCode(), test2.hashCode());
+ Assert.assertEquals(test1.hashCode(), test2.hashCode());
COSInteger test3 = COSInteger.get(i + 1);
- assertFalse(test3.hashCode() == test1.hashCode());
+ assertNotSame(test3.hashCode(), test1.hashCode());
}
}
@@ -104,7 +105,7 @@ public class TestCOSInteger extends Test
{
for (int i = -1000; i < 3000; i += 200)
{
- assertEquals(i, COSInteger.get(i).intValue());
+ Assert.assertEquals(i, COSInteger.get(i).intValue());
}
}
@@ -113,7 +114,7 @@ public class TestCOSInteger extends Test
{
for (int i = -1000; i < 3000; i += 200)
{
- assertEquals((long) i, COSInteger.get(i).longValue());
+ Assert.assertEquals((long) i, COSInteger.get(i).longValue());
}
}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSString.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSString.java?rev=1881494&r1=1881493&r2=1881494&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSString.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSString.java Sat Sep 5 11:08:25 2020
@@ -25,6 +25,7 @@ import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.pdfbox.pdfwriter.COSWriter;
+import org.junit.Assert;
/**
* This will test all of the filters in the PDFBox system.
@@ -101,7 +102,7 @@ public class TestCOSString extends TestC
{
fail("IOException: " + e.getMessage());
}
- assertEquals(expected, outStream.toString());
+ Assert.assertEquals(expected, outStream.toString());
}
/**
@@ -122,15 +123,8 @@ public class TestCOSString extends TestC
{
fail("IOException thrown: " + e.getMessage());
}
- try
- {
- COSString.parseHex(hexForm + "xx");
- fail("Should have thrown an IOException here");
- }
- catch (IOException e)
- {
- // PASS
- }
+ Assert.assertThrows("Should have thrown an IOException here",
+ IOException.class, () -> COSString.parseHex(hexForm + "xx"));
}
private String createHex(String str)
@@ -151,11 +145,11 @@ public class TestCOSString extends TestC
String expected = "Test subject for testing getHex";
COSString test1 = new COSString(expected);
String hexForm = createHex(expected);
- assertEquals(hexForm, test1.toHexString());
+ Assert.assertEquals(hexForm, test1.toHexString());
COSString escCS = new COSString(ESC_CHAR_STRING);
// Not sure whether the escaped characters should be escaped or not, presumably since
// writePDF() gives you the proper formatted text, getHex() should ONLY convert to hex.
- assertEquals(createHex(ESC_CHAR_STRING), escCS.toHexString());
+ Assert.assertEquals(createHex(ESC_CHAR_STRING), escCS.toHexString());
}
/**
@@ -167,17 +161,17 @@ public class TestCOSString extends TestC
{
String testStr = "Test subject for getString()";
COSString test1 = new COSString(testStr);
- assertEquals(testStr, test1.getString());
+ Assert.assertEquals(testStr, test1.getString());
COSString hexStr = COSString.parseHex(createHex(testStr));
- assertEquals(testStr, hexStr.getString());
+ Assert.assertEquals(testStr, hexStr.getString());
COSString escapedString = new COSString(ESC_CHAR_STRING);
- assertEquals(ESC_CHAR_STRING, escapedString.getString());
+ Assert.assertEquals(ESC_CHAR_STRING, escapedString.getString());
testStr = "Line1\nLine2\nLine3\n";
COSString lineFeedString = new COSString(testStr);
- assertEquals(testStr, lineFeedString.getString());
+ Assert.assertEquals(testStr, lineFeedString.getString());
}
catch (IOException e)
{
@@ -226,29 +220,29 @@ public class TestCOSString extends TestC
// Testing the getString method
COSString stringAscii = new COSString( textAscii );
- assertEquals( stringAscii.getString(), textAscii );
+ Assert.assertEquals( stringAscii.getString(), textAscii );
COSString string8Bit = new COSString( text8Bit );
- assertEquals( string8Bit.getString(), text8Bit );
+ Assert.assertEquals( string8Bit.getString(), text8Bit );
COSString stringHighBits = new COSString( textHighBits );
- assertEquals( stringHighBits.getString(), textHighBits );
+ Assert.assertEquals( stringHighBits.getString(), textHighBits );
// Testing the getBytes method
// The first two strings should be stored as ISO-8859-1 because they only contain chars in the range 0..255
- assertEquals(textAscii, new String(stringAscii.getBytes(), StandardCharsets.ISO_8859_1));
+ Assert.assertEquals(textAscii, new String(stringAscii.getBytes(), StandardCharsets.ISO_8859_1));
// likewise for the 8bit characters.
- assertEquals(text8Bit, new String(string8Bit.getBytes(), StandardCharsets.ISO_8859_1));
+ Assert.assertEquals(text8Bit, new String(string8Bit.getBytes(), StandardCharsets.ISO_8859_1));
// The japanese text contains high bits so must be stored as big endian UTF-16
- assertEquals(textHighBits, new String(stringHighBits.getBytes(), "UnicodeBig"));
+ Assert.assertEquals(textHighBits, new String(stringHighBits.getBytes(), "UnicodeBig"));
// Test the writePDF method to ensure that the Strings are correct when written into PDF.
ByteArrayOutputStream out = new ByteArrayOutputStream();
COSWriter.writeString(stringAscii, out);
- assertEquals("(" + textAscii + ")", new String(out.toByteArray(), "ASCII"));
+ Assert.assertEquals("(" + textAscii + ")", new String(out.toByteArray(), "ASCII"));
out.reset();
COSWriter.writeString(string8Bit, out);
@@ -257,7 +251,7 @@ public class TestCOSString extends TestC
{
hex.append( Integer.toHexString(c).toUpperCase() );
}
- assertEquals("<"+hex.toString()+">", new String(out.toByteArray(), "ASCII"));
+ Assert.assertEquals("<"+hex.toString()+">", new String(out.toByteArray(), "ASCII"));
out.reset();
COSWriter.writeString(stringHighBits, out);
@@ -267,7 +261,7 @@ public class TestCOSString extends TestC
{
hex.append( Integer.toHexString(c).toUpperCase() );
}
- assertEquals("<"+hex.toString()+">", new String(out.toByteArray(), "ASCII"));
+ Assert.assertEquals("<"+hex.toString()+">", new String(out.toByteArray(), "ASCII"));
}
@Override
@@ -277,11 +271,11 @@ public class TestCOSString extends TestC
ICOSVisitor visitor = new COSWriter(outStream);
COSString testSubj = new COSString(ESC_CHAR_STRING);
testSubj.accept(visitor);
- assertEquals("(" + ESC_CHAR_STRING_PDF_FORMAT + ")", outStream.toString());
+ Assert.assertEquals("(" + ESC_CHAR_STRING_PDF_FORMAT + ")", outStream.toString());
outStream.reset();
testSubj.setForceHexForm(true);
testSubj.accept(visitor);
- assertEquals("<" + createHex(ESC_CHAR_STRING) + ">", outStream.toString());
+ Assert.assertEquals("<" + createHex(ESC_CHAR_STRING) + ">", outStream.toString());
}
/**
@@ -294,27 +288,27 @@ public class TestCOSString extends TestC
{
// Reflexive
COSString x1 = new COSString("Test");
- assertTrue(x1.equals(x1));
+ Assert.assertEquals(x1, x1);
// Symmetry i.e. if x == y then y == x
COSString y1 = new COSString("Test");
- assertTrue(x1.equals(y1));
- assertTrue(y1.equals(x1));
+ Assert.assertEquals(x1, y1);
+ Assert.assertEquals(y1, x1);
COSString x2 = new COSString("Test");
x2.setForceHexForm(true);
// also if x != y then y != x
- assertFalse(x1.equals(x2));
- assertFalse(x2.equals(x1));
+ Assert.assertNotEquals(x1, x2);
+ Assert.assertNotEquals(x2, x1);
// Transitive if x == y && y == z then x == z
COSString z1 = new COSString("Test");
- assertTrue(x1.equals(y1));
- assertTrue(y1.equals(z1));
- assertTrue(x1.equals(z1));
+ Assert.assertEquals(x1, y1);
+ Assert.assertEquals(y1, z1);
+ Assert.assertEquals(x1, z1);
// Test the negative as well if x1 == y1 && y1 != x2 then x1 != x2
- assertTrue(x1.equals(y1));
- assertFalse(y1.equals(x2));
- assertFalse(x1.equals(x2));
+ Assert.assertEquals(x1, y1);
+ Assert.assertNotEquals(y1, x2);
+ Assert.assertNotEquals(x1, x2);
}
}
@@ -325,11 +319,11 @@ public class TestCOSString extends TestC
{
COSString str1 = new COSString("Test1");
COSString str2 = new COSString("Test2");
- assertFalse(str1.hashCode() == str2.hashCode());
+ Assert.assertNotEquals(str1.hashCode(), str2.hashCode());
COSString str3 = new COSString("Test1");
- assertTrue(str1.hashCode() == str3.hashCode());
+ Assert.assertEquals(str1.hashCode(), str3.hashCode());
str3.setForceHexForm(true);
- assertFalse(str1.hashCode() == str3.hashCode());
+ Assert.assertNotEquals(str1.hashCode(), str3.hashCode());
}
/**
@@ -340,13 +334,13 @@ public class TestCOSString extends TestC
{
COSString test1 = COSString.parseHex("000000FF000000");
COSString test2 = COSString.parseHex("000000FF00FFFF");
- assertEquals(test1, test1);
- assertEquals(test2, test2);
- assertFalse(test1.toHexString().equals(test2.toHexString()));
+ Assert.assertEquals(test1, test1);
+ Assert.assertEquals(test2, test2);
+ Assert.assertNotEquals(test1.toHexString(), test2.toHexString());
assertFalse(Arrays.equals(test1.getBytes(), test2.getBytes()));
- assertFalse(test1.equals(test2));
- assertFalse(test2.equals(test1));
- assertFalse(test1.getString().equals(test2.getString()));
+ Assert.assertNotEquals(test1, test2);
+ Assert.assertNotEquals(test2, test1);
+ Assert.assertNotEquals(test1.getString(), test2.getString());
}
/**