Skip to content

Commit 3324565

Browse files
committed
PDFBOX-6026: fix timezone, use fields and make them private
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1926762 13f79535-47bb-0310-9956-ffa450edef68
1 parent d1a34be commit 3324565

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.security.MessageDigest;
3434
import java.security.NoSuchAlgorithmException;
3535
import java.util.List;
36+
import java.util.TimeZone;
3637
import javax.xml.transform.TransformerException;
3738

3839
import org.apache.xmpbox.DateConverter;
@@ -46,27 +47,45 @@
4647
import org.apache.xmpbox.xml.DomXmpParser;
4748
import org.apache.xmpbox.xml.XmpParsingException;
4849
import org.apache.xmpbox.xml.XmpParsingException.ErrorType;
50+
import org.junit.jupiter.api.AfterAll;
51+
import org.junit.jupiter.api.BeforeAll;
4952
import org.junit.jupiter.api.BeforeEach;
5053
import org.junit.jupiter.api.Test;
5154
import org.apache.xmpbox.xml.XmpSerializer;
5255

5356
class DeserializationTest
5457
{
5558

56-
protected ByteArrayOutputStream bos;
59+
private ByteArrayOutputStream baos;
5760

58-
protected XmpSerializer serializer;
61+
private XmpSerializer serializer;
5962

6063
private DomXmpParser xdb;
6164

65+
private static TimeZone defaultTZ;
66+
67+
@BeforeAll
68+
static void initAll()
69+
{
70+
defaultTZ = TimeZone.getDefault();
71+
// Need to set a timezone or date values will be different depending on test location
72+
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
73+
}
74+
6275
@BeforeEach
6376
void init() throws XmpParsingException
6477
{
65-
bos = new ByteArrayOutputStream();
78+
baos = new ByteArrayOutputStream();
6679
serializer = new XmpSerializer();
6780
xdb = new DomXmpParser();
6881
}
6982

83+
@AfterAll
84+
static void finishAll()
85+
{
86+
TimeZone.setDefault(defaultTZ);
87+
}
88+
7089
@Test
7190
void testStructuredRecursive() throws XmpParsingException
7291
{
@@ -107,7 +126,7 @@ void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlg
107126
{
108127
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml");
109128
XMPMetadata metadata=xdb.parse(fis);
110-
checkTransform(metadata, "96393121650279079517435472505216876362174786845882116375023427217573081361024");
129+
checkTransform(metadata, "16805992283807186369849610414335227396239089071611806706387795179375897398118");
111130
}
112131

113132
@Test
@@ -330,7 +349,6 @@ void testSpaceTextValues() throws XmpParsingException
330349
private void checkTransform(XMPMetadata metadata, String expected)
331350
throws TransformerException, NoSuchAlgorithmException, IOException
332351
{
333-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
334352
serializer.serialize(metadata, baos, true);
335353
String replaced = baos.toString(StandardCharsets.UTF_8).replace("\r\n", "\n");
336354
byte[] ba = replaced.getBytes(StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)