Skip to content

Commit

Permalink
Update junit 4.12 to 4.13.1 to remove security warning.
Browse files Browse the repository at this point in the history
This also involved replacing the deprecated org.junit.Assert.assertThat with org.hamcrest.MatcherAssert.assertThat.

NOTE: The security issue in junit 4.12 (which relates to information disclosure using TemporaryFolder rule) does not affect this project so this update is mostly to appease security scanners.
  • Loading branch information
danfickle committed Oct 14, 2020
1 parent 4f94cc8 commit 801780b
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 49 deletions.
2 changes: 1 addition & 1 deletion openhtmltopdf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import static com.openhtmltopdf.layout.BreakerTestSupport.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.openhtmltopdf.layout;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

import java.util.Locale;

import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

import com.openhtmltopdf.extend.FSTextTransformer;

public class TextTransformersTest {
@Test
public void testSimpleToUpperTransform() {
FSTextTransformer tr = new TextUtil.DefaultToUpperTransformer(Locale.US);
Assert.assertThat(tr.transform("this is a Test"), equalTo("THIS IS A TEST"));
assertThat(tr.transform("this is a Test"), equalTo("THIS IS A TEST"));
}

@Test
public void testSimpleToLowerTransform() {
FSTextTransformer tr = new TextUtil.DefaultToLowerTransformer(Locale.US);
Assert.assertThat(tr.transform("THIS IS a TEST"), equalTo("this is a test"));
assertThat(tr.transform("THIS IS a TEST"), equalTo("this is a test"));
}

@Test
public void testSimpleToTitleTransform() {
FSTextTransformer tr = new TextUtil.DefaultToTitleTransformer();
Assert.assertThat(tr.transform("this iS a teST"), equalTo("This IS A TeST"));
assertThat(tr.transform("this iS a teST"), equalTo("This IS A TeST"));
}

@Test
Expand All @@ -35,7 +35,7 @@ public void testPunctuationUnchanged() {
new TextUtil.DefaultToTitleTransformer() };

for (FSTextTransformer tr : trs) {
Assert.assertThat(tr.transform("!@#$%^&&*()_-+=?/><,.~`"), equalTo("!@#$%^&&*()_-+=?/><,.~`"));
assertThat(tr.transform("!@#$%^&&*()_-+=?/><,.~`"), equalTo("!@#$%^&&*()_-+=?/><,.~`"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.openhtmltopdf.layout.BreakerTestSupport.*;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.InputStream;
import java.util.Map;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Assert;
import org.junit.Test;
import org.xml.sax.InputSource;
Expand All @@ -15,7 +16,7 @@ public void testResolveEntity() throws Exception {
String publicId = "-//OPENHTMLTOPDF//DOC XHTML Character Entities Only 1.0//EN";
InputSource resolvedEntity = instance.resolveEntity(publicId, null);
try (InputStream in = resolvedEntity.getByteStream()) {
Assert.assertThat(in, notNullValue());
assertThat(in, notNullValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import static org.hamcrest.core.IsEqual.equalTo;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;

import com.openhtmltopdf.extend.FSUriResolver;

Expand All @@ -14,44 +14,44 @@ public class DefaultUriResolverTest {

@Test
public void testJarHttpUrlResolve() {
Assert.assertThat(resolver.resolveURI("jar:http://www.foo.com/bar/baz.jar!/", "logo.png"), equalTo("jar:http://www.foo.com/bar/baz.jar!/logo.png"));
assertThat(resolver.resolveURI("jar:http://www.foo.com/bar/baz.jar!/", "logo.png"), equalTo("jar:http://www.foo.com/bar/baz.jar!/logo.png"));
}

@Test
public void testJarFileUrlResolve() {
Assert.assertThat(resolver.resolveURI("jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/", "logo.jpg"), equalTo("jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/logo.jpg"));
assertThat(resolver.resolveURI("jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/", "logo.jpg"), equalTo("jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/logo.jpg"));
}

@Test
public void testAbsoluteJarFileAsRelativePart() {
Assert.assertThat(resolver.resolveURI("http://example.com/", "jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/logo.jpg"), equalTo("jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/logo.jpg"));
assertThat(resolver.resolveURI("http://example.com/", "jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/logo.jpg"), equalTo("jar:file:/E:/example/target/server-1.0.0.war!/WEB-INF/classes!/export/logo.jpg"));
}

@Test
@Ignore("Base URIs not working with out a trailing slash")
public void testNonJarUrlResolveWithoutTrailingSlash() {
Assert.assertThat(resolver.resolveURI("http://example.com", "logo.png"), equalTo("http://example.com/logo.png"));
assertThat(resolver.resolveURI("http://example.com", "logo.png"), equalTo("http://example.com/logo.png"));
}

@Test
public void testNonJarUrlResolveWithTrailingSlash() {
Assert.assertThat(resolver.resolveURI("http://example.com/", "logo.png"), equalTo("http://example.com/logo.png"));
assertThat(resolver.resolveURI("http://example.com/", "logo.png"), equalTo("http://example.com/logo.png"));
}

@Test
public void testNonJarWithPath() {
Assert.assertThat(resolver.resolveURI("http://example.com/path/", "logo.png"), equalTo("http://example.com/path/logo.png"));
assertThat(resolver.resolveURI("http://example.com/path/", "logo.png"), equalTo("http://example.com/path/logo.png"));
}

@Test
public void testAbsoluteAsPartialUrl() {
Assert.assertThat(resolver.resolveURI("http://example.com/", "http://sample.com/logo.png"), equalTo("http://sample.com/logo.png"));
assertThat(resolver.resolveURI("http://example.com/", "http://sample.com/logo.png"), equalTo("http://sample.com/logo.png"));
}

@Test
@Ignore("Should empty urls should resolve to the base rather than null?")
public void testEmptyUrl() {
Assert.assertThat(resolver.resolveURI("http://example.com/", ""), equalTo("http://example.com/"));
assertThat(resolver.resolveURI("http://example.com/", ""), equalTo("http://example.com/"));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
package com.openhtmltopdf.util;

import static org.hamcrest.CoreMatchers.is;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;

import org.hamcrest.CoreMatchers;

public class ConfigurationTest {

@Test
public void testValueFor() {
String key = "xr.test-config-byte";
String value = Configuration.valueFor(key);
assertThat(value, is("8"));
assertThat(value, CoreMatchers.is("8"));
}

@Test
public void testValueAsByte() {
String key = "xr.test-config-byte";
int value = Configuration.valueAsByte(key, (byte) 0);
assertThat(value, is(8));
assertThat(value, CoreMatchers.is(8));
}

@Test
public void testValueAsShort() {
String key = "xr.test-config-short";
int value = Configuration.valueAsShort(key, (short) 0);
assertThat(value, is(16));
assertThat(value, CoreMatchers.is(16));
}

@Test
public void testValueAsInt() {
String key = "xr.test-config-int";
int value = Configuration.valueAsInt(key, (int) 0);
assertThat(value, is(100));
int value = Configuration.valueAsInt(key, 0);
assertThat(value, CoreMatchers.is(100));
}

@Test
public void testValueAsLong() {
String key = "xr.test-config-long";
long value = Configuration.valueAsLong(key, (long) 0);
assertThat(value, is(2000L));
long value = Configuration.valueAsLong(key, 0l);
assertThat(value, CoreMatchers.is(2000L));
}

@Test
public void testValueAsFloat() {
String key = "xr.test-config-float";
float value = Configuration.valueAsFloat(key, (float) 0);
assertThat(value, is(3000.25F));
float value = Configuration.valueAsFloat(key, 0f);
assertThat(value, CoreMatchers.is(3000.25F));
}

@Test
public void testValueAsDouble() {
String key = "xr.test-config-double";
double value = Configuration.valueAsDouble(key, (double) 0);
assertThat(value, is(4000.50D));
double value = Configuration.valueAsDouble(key, 0d);
assertThat(value, CoreMatchers.is(4000.50D));
}

@Test
public void testIsTrue() {
String key = "xr.test-config-boolean";
boolean value = Configuration.isTrue(key, false);
assertThat(value, is(true));
assertThat(value, CoreMatchers.is(true));
}

@Test
public void testIsFalse() {
String key = "xr.test-config-boolean";
boolean value = Configuration.isFalse(key, true);
assertThat(value, is(false));
assertThat(value, CoreMatchers.is(false));
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package com.openhtmltopdf.util;

import java.awt.image.BufferedImage;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;

import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.junit.Assert;
import static org.hamcrest.MatcherAssert.assertThat;

public class ImageUtilTest {

@Test
public void testGetEmbeddedBase64Image() {
String onePixel = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC";
byte[] result = ImageUtil.getEmbeddedBase64Image(onePixel);
Assert.assertThat(result, notNullValue());
assertThat(result, notNullValue());
}

@Test
public void testLoadEmbeddedBase64Image() {
String onePixel = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC";
BufferedImage result = ImageUtil.loadEmbeddedBase64Image(onePixel);
Assert.assertThat(result.getHeight(), is(1));
Assert.assertThat(result.getWidth(), is(1));
assertThat(result.getHeight(), CoreMatchers.is(1));
assertThat(result.getWidth(), CoreMatchers.is(1));
}

}
2 changes: 1 addition & 1 deletion openhtmltopdf-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.openhtmltopdf.nonvisualregressiontests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;

Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-objects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-pdfa-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-pdfbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import java.io.IOException;
import java.io.PrintStream;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import com.openhtmltopdf.util.XRLog;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;

public class Slf4JLoggerTest {

Expand Down Expand Up @@ -43,8 +43,8 @@ public void testLogger() throws IOException {
old.println(log);
System.setErr(old);

Assert.assertThat(log, containsString("] [INFO]"));
Assert.assertThat(log, containsString("] [WARN]"));
assertThat(log, containsString("] [INFO]"));
assertThat(log, containsString("] [WARN]"));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion openhtmltopdf-templates/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${open.junit4.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<open.jar.plugin.version>3.2.0</open.jar.plugin.version>

<open.batik.version>1.12</open.batik.version>
<open.junit4.version>4.13.1</open.junit4.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down

0 comments on commit 801780b

Please sign in to comment.