Skip to content

Commit 55a3ad8

Browse files
committed
Update to junit 5 and add tests for NaN support in NSNumber
1 parent cfa6c85 commit 55a3ad8

9 files changed

+268
-160
lines changed

dd-plist.iml

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
66
<content url="file://$MODULE_DIR$">
77
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
88
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
10+
<sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
11+
<sourceFolder url="file://$MODULE_DIR$/test-files" type="java-test-resource" />
912
<excludeFolder url="file://$MODULE_DIR$/target" />
1013
</content>
1114
<orderEntry type="inheritedJdk" />
1215
<orderEntry type="sourceFolder" forTests="false" />
13-
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14-
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15-
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
16-
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
16+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.5.2" level="project" />
17+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.5.2" level="project" />
18+
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
19+
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
20+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.5.2" level="project" />
21+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.5.2" level="project" />
22+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.5.2" level="project" />
23+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.5.2" level="project" />
1724
</component>
1825
</module>

pom.xml

+24-12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
</scm>
5757
<properties>
5858
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
59+
<maven.compiler.source>1.6</maven.compiler.source>
60+
<maven.compiler.target>1.6</maven.compiler.target>
5961
</properties>
6062
<distributionManagement>
6163
<snapshotRepository>
@@ -69,17 +71,28 @@
6971
<plugin>
7072
<groupId>org.apache.maven.plugins</groupId>
7173
<artifactId>maven-compiler-plugin</artifactId>
72-
<version>3.0</version>
74+
<version>3.8.1</version>
7375
<configuration>
74-
<source>1.6</source>
75-
<target>1.6</target>
7676
<compilerArgument>-Xlint:unchecked</compilerArgument>
7777
</configuration>
78+
<executions>
79+
<execution>
80+
<id>default-testCompile</id>
81+
<phase>process-test-sources</phase>
82+
<goals>
83+
<goal>testCompile</goal>
84+
</goals>
85+
<configuration>
86+
<source>1.8</source>
87+
<target>1.8</target>
88+
</configuration>
89+
</execution>
90+
</executions>
7891
</plugin>
7992
<plugin>
8093
<groupId>org.apache.maven.plugins</groupId>
8194
<artifactId>maven-javadoc-plugin</artifactId>
82-
<version>2.8.1</version>
95+
<version>3.1.1</version>
8396
<configuration>
8497
<reportOutputDirectory>target</reportOutputDirectory>
8598
<destDir>javadoc</destDir>
@@ -97,14 +110,13 @@
97110
<plugin>
98111
<groupId>org.apache.maven.plugins</groupId>
99112
<artifactId>maven-assembly-plugin</artifactId>
100-
<version>2.3</version>
113+
<version>3.2.0</version>
101114
<configuration>
102115
<descriptors>
103116
<descriptor>src/main/assembly/bin.xml</descriptor>
104117
<descriptor>src/main/assembly/javadoc.xml</descriptor>
105118
<descriptor>src/main/assembly/sources.xml</descriptor>
106119
</descriptors>
107-
<finalName>${project.artifactId}</finalName>
108120
<appendAssemblyId>true</appendAssemblyId>
109121
</configuration>
110122
<executions>
@@ -120,7 +132,7 @@
120132
<plugin>
121133
<groupId>org.apache.maven.plugins</groupId>
122134
<artifactId>maven-gpg-plugin</artifactId>
123-
<version>1.4</version>
135+
<version>1.6</version>
124136
<executions>
125137
<execution>
126138
<id>sign-artifacts</id>
@@ -134,7 +146,7 @@
134146
<plugin>
135147
<groupId>org.apache.maven.plugins</groupId>
136148
<artifactId>maven-jar-plugin</artifactId>
137-
<version>2.4</version>
149+
<version>3.2.0</version>
138150
<configuration>
139151
<archive>
140152
<manifestFile>${project.build.directory}/osgi/MANIFEST.MF</manifestFile>
@@ -173,7 +185,7 @@
173185
<plugin>
174186
<groupId>org.sonatype.plugins</groupId>
175187
<artifactId>nexus-staging-maven-plugin</artifactId>
176-
<version>1.6.7</version>
188+
<version>1.6.8</version>
177189
<extensions>true</extensions>
178190
<configuration>
179191
<serverId>ossrh</serverId>
@@ -185,9 +197,9 @@
185197
</build>
186198
<dependencies>
187199
<dependency>
188-
<groupId>junit</groupId>
189-
<artifactId>junit</artifactId>
190-
<version>4.12</version>
200+
<groupId>org.junit.jupiter</groupId>
201+
<artifactId>junit-jupiter</artifactId>
202+
<version>5.5.2</version>
191203
<scope>test</scope>
192204
</dependency>
193205
</dependencies>

src/test/java/com/dd/plist/test/CloneTest.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package com.dd.plist.test;
22

33
import com.dd.plist.*;
4-
5-
import junit.framework.TestCase;
4+
import org.junit.jupiter.api.Test;
65

76
import java.io.File;
87

8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertNotSame;
10+
911
/**
1012
* @author Daniel Dreibrodt
1113
*/
12-
public class CloneTest extends TestCase {
14+
public class CloneTest {
15+
@Test
1316
public void testCloneEquals() throws Exception {
1417
NSDictionary root = (NSDictionary)PropertyListParser.parse(new File("test-files/test1.plist"));
1518
NSDictionary clonedDictionary = root.clone();
1619

1720
assertEquals(clonedDictionary, root);
1821
}
1922

23+
@Test
2024
public void testCloneIsDeep() throws Exception {
2125
NSDictionary root = (NSDictionary)PropertyListParser.parse(new File("test-files/test1.plist"));
2226
NSDictionary clonedDictionary = root.clone();

src/test/java/com/dd/plist/test/DeSerializationTest.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import com.dd.plist.*;
44
import com.dd.plist.test.model.*;
5-
import junit.framework.TestCase;
5+
import org.junit.jupiter.api.Test;
66

77
import java.nio.charset.Charset;
88
import java.util.*;
99

10-
public class DeSerializationTest extends TestCase {
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertTrue;
12+
13+
public class DeSerializationTest {
1114
private static final Date date = new Date();
1215

16+
@Test
1317
public void testSimpleMap() throws Exception {
1418
Map<String, String> map = new HashMap<String, String>();
1519
map.put("key", "value");
@@ -19,6 +23,7 @@ public void testSimpleMap() throws Exception {
1923
assertEquals(map, result);
2024
}
2125

26+
@Test
2227
public void testSimpleMapNS() throws Exception {
2328
Map<String, String> map = new HashMap<String, String>();
2429
map.put("key", "value");
@@ -30,6 +35,7 @@ public void testSimpleMapNS() throws Exception {
3035
assertEquals(test, result);
3136
}
3237

38+
@Test
3339
public void testPojoMap() throws Exception {
3440
TestClassMap test = new TestClassMap();
3541
test.setStringMap(mapFromArr("key", "value"));
@@ -61,10 +67,12 @@ public void testPojoMap() throws Exception {
6167
assertEquals(test, dict.toJavaObject(TestClassMap.class));
6268
}
6369

70+
@Test
6471
public void testDictSet() throws Exception {
6572
assertEquals(NSObject.fromJavaObject(genTestSetObject()), genTestSetDict());
6673
}
6774

75+
@Test
6876
public void testPojoSet() throws Exception {
6977
TestClassSet test = genTestSetObject();
7078
NSDictionary dict = genTestSetDict();
@@ -73,10 +81,6 @@ public void testPojoSet() throws Exception {
7381
assertEquals(test, dict.toJavaObject(TestClassSet.class));
7482
}
7583

76-
public void testUid() throws Exception {
77-
78-
}
79-
8084
private NSDictionary genTestSetDict() {
8185
NSDictionary dict = new NSDictionary();
8286
dict.put("stringSet", new NSSet(new NSString("value")));

src/test/java/com/dd/plist/test/GoogleCodeIssueTest.java

+27-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package com.dd.plist.test;
22

33
import com.dd.plist.*;
4-
import junit.framework.TestCase;
4+
import org.junit.jupiter.api.Test;
55

66
import java.io.File;
77
import java.io.IOException;
88
import java.util.HashMap;
99
import java.util.Map;
1010

11+
import static org.junit.jupiter.api.Assertions.*;
12+
1113
/**
1214
* This class contains tests for issues that were managed with the Google Code issue tracking system
1315
*/
14-
public class GoogleCodeIssueTest extends TestCase {
15-
public static void testIssue4() throws Exception {
16+
public class GoogleCodeIssueTest {
17+
@Test
18+
public void testIssue4() throws Exception {
1619
NSDictionary d = (NSDictionary)PropertyListParser.parse(new File("test-files/issue4.plist"));
1720
assertTrue(((NSString)d.objectForKey("Device Name")).toString().equals("Kid\u2019s iPhone"));
1821
}
1922

20-
public static void testIssue7() throws Exception {
23+
@Test
24+
public void testIssue7() throws Exception {
2125
// also a test for issue 12
2226
// the issue4 test has a UTF-16-BE string in its binary representation
2327
NSObject x = PropertyListParser.parse(new File("test-files/issue4.plist"));
@@ -26,24 +30,28 @@ public static void testIssue7() throws Exception {
2630
assertTrue(x.equals(y));
2731
}
2832

29-
public static void testIssue16() throws Exception {
33+
@Test
34+
public void testIssue16() throws Exception {
3035
float x = ((NSNumber)PropertyListParser.parse(new File("test-files/issue16.plist"))).floatValue();
3136
assertTrue(x == (float)2.71828);
3237
}
3338

34-
public static void testIssue18() throws Exception {
39+
@Test
40+
public void testIssue18() throws Exception {
3541
NSNumber x = new NSNumber(-999);
3642
PropertyListParser.saveAsBinary(x, new File("test-files/out-testIssue18.plist"));
3743
NSObject y = PropertyListParser.parse(new File("test-files/out-testIssue18.plist"));
3844
assertTrue(x.equals(y));
3945
}
4046

41-
public static void testIssue21() throws Exception {
47+
@Test
48+
public void testIssue21() throws Exception {
4249
String x = ((NSString)PropertyListParser.parse(new File("test-files/issue21.plist"))).toString();
4350
assertTrue(x.equals("Lot&s of &persand&s and other escapable \"\'<>€ characters"));
4451
}
4552

46-
public static void testIssue22() throws Exception {
53+
@Test
54+
public void testIssue22() throws Exception {
4755
NSDictionary x1 = ((NSDictionary)PropertyListParser.parse(new File("test-files/issue22-emoji.plist")));
4856
NSDictionary x2 = ((NSDictionary)PropertyListParser.parse(new File("test-files/issue22-emoji-xml.plist")));
4957
PropertyListParser.saveAsBinary(x1, new File("test-files/out-testIssue22.plist"));
@@ -64,14 +72,18 @@ public static void testIssue22() throws Exception {
6472
assertTrue(emojiString.equals(y2.objectForKey("emojiString").toString()));
6573
}
6674

67-
public static void testIssue30() throws Exception {
75+
@Test
76+
public void testIssue30() throws Exception {
6877
NSArray arr = (NSArray)PropertyListParser.parse(new File("test-files/issue30.plist"));
6978
}
7079

71-
public static void testIssue33() throws Exception {
80+
@Test
81+
public void testIssue33() throws Exception {
7282
NSDictionary dict = (NSDictionary)PropertyListParser.parse(new File("test-files/issue33.pbxproj"));
7383
}
74-
public static void testIssue38() throws Exception {
84+
85+
@Test
86+
public void testIssue38() throws Exception {
7587
NSDictionary dict = (NSDictionary)PropertyListParser.parse(new File("test-files/issue33.pbxproj"));
7688
NSObject fileRef = ((NSDictionary) ((NSDictionary)dict.get("objects")).get("65541A9C16D13B8C00A968D5")).get("fileRef");
7789
assertTrue(fileRef.equals(new NSString("65541A9B16D13B8C00A968D5")));
@@ -80,7 +92,8 @@ public static void testIssue38() throws Exception {
8092
/**
8193
* Test storing null values
8294
*/
83-
public static void testIssue41() {
95+
@Test
96+
public void testIssue41() {
8497
//Dictionary
8598
Map<String, Object> nullMap = new HashMap<String, Object>();
8699
nullMap.put("key", null);
@@ -140,7 +153,8 @@ public static void testIssue41() {
140153
}
141154
}
142155

143-
public static void testIssue49() throws Exception {
156+
@Test
157+
public void testIssue49() throws Exception {
144158
NSDictionary dict = (NSDictionary)PropertyListParser.parse(new File("test-files/issue49.plist"));
145159
assertEquals(0, dict.count());
146160
}

src/test/java/com/dd/plist/test/IssueTest.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.dd.plist.test;
22

33
import com.dd.plist.*;
4-
import org.junit.Assert;
5-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
65
import org.xml.sax.SAXParseException;
76

87
import java.io.*;
98
import java.util.zip.GZIPInputStream;
109
import java.util.zip.GZIPOutputStream;
1110

12-
import static org.junit.Assert.assertEquals;
13-
import static org.junit.Assert.fail;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertThrows;
1413

1514
/**
1615
* Regression tests for various issues and bugs that have been encountered
@@ -55,10 +54,10 @@ public void testIssue31_FalsePositiveForGZipInsideDataElement() throws Exception
5554
assertEquals("1f8b2ef69414fa70ff578a697cfc0919235c8eff", HexConverter.toHex(hash.bytes()));
5655
}
5756

58-
@Test(expected = PropertyListFormatException.class)
57+
@Test
5958
public void testIssue42_OutOfMemoryErrorWhenBinaryPropertyListTrailerIsCorrupt() throws Exception {
6059
File plistFile = new File("test-files/github-issue42.plist");
61-
PropertyListParser.parse(plistFile);
60+
assertThrows(PropertyListFormatException.class, () -> PropertyListParser.parse(plistFile));
6261
}
6362

6463
@Test
@@ -86,12 +85,6 @@ public void testIssue51_BillionLaughsAttack() throws Exception {
8685
"<lolz>&lol9;</lolz>";
8786
InputStream is = new ByteArrayInputStream(plist.getBytes());
8887

89-
try {
90-
XMLPropertyListParser.parse(is);
91-
Assert.fail();
92-
}
93-
catch (SAXParseException ex) {
94-
// This is the expectation
95-
}
88+
assertThrows(SAXParseException.class, () -> XMLPropertyListParser.parse(is));
9689
}
9790
}

0 commit comments

Comments
 (0)