Skip to content

Commit

Permalink
Update to junit 5 and add tests for NaN support in NSNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
3breadt committed Nov 6, 2019
1 parent cfa6c85 commit 55a3ad8
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 160 deletions.
17 changes: 12 additions & 5 deletions dd-plist.iml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test-files" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.5.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.5.2" level="project" />
</component>
</module>
36 changes: 24 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<distributionManagement>
<snapshotRepository>
Expand All @@ -69,17 +71,28 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>3.8.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>process-test-sources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<version>3.1.1</version>
<configuration>
<reportOutputDirectory>target</reportOutputDirectory>
<destDir>javadoc</destDir>
Expand All @@ -97,14 +110,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<version>3.2.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin.xml</descriptor>
<descriptor>src/main/assembly/javadoc.xml</descriptor>
<descriptor>src/main/assembly/sources.xml</descriptor>
</descriptors>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
<executions>
Expand All @@ -120,7 +132,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -134,7 +146,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>${project.build.directory}/osgi/MANIFEST.MF</manifestFile>
Expand Down Expand Up @@ -173,7 +185,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -185,9 +197,9 @@
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/com/dd/plist/test/CloneTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.dd.plist.test;

import com.dd.plist.*;

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;

/**
* @author Daniel Dreibrodt
*/
public class CloneTest extends TestCase {
public class CloneTest {
@Test
public void testCloneEquals() throws Exception {
NSDictionary root = (NSDictionary)PropertyListParser.parse(new File("test-files/test1.plist"));
NSDictionary clonedDictionary = root.clone();

assertEquals(clonedDictionary, root);
}

@Test
public void testCloneIsDeep() throws Exception {
NSDictionary root = (NSDictionary)PropertyListParser.parse(new File("test-files/test1.plist"));
NSDictionary clonedDictionary = root.clone();
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/com/dd/plist/test/DeSerializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import com.dd.plist.*;
import com.dd.plist.test.model.*;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

import java.nio.charset.Charset;
import java.util.*;

public class DeSerializationTest extends TestCase {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DeSerializationTest {
private static final Date date = new Date();

@Test
public void testSimpleMap() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
Expand All @@ -19,6 +23,7 @@ public void testSimpleMap() throws Exception {
assertEquals(map, result);
}

@Test
public void testSimpleMapNS() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
Expand All @@ -30,6 +35,7 @@ public void testSimpleMapNS() throws Exception {
assertEquals(test, result);
}

@Test
public void testPojoMap() throws Exception {
TestClassMap test = new TestClassMap();
test.setStringMap(mapFromArr("key", "value"));
Expand Down Expand Up @@ -61,10 +67,12 @@ public void testPojoMap() throws Exception {
assertEquals(test, dict.toJavaObject(TestClassMap.class));
}

@Test
public void testDictSet() throws Exception {
assertEquals(NSObject.fromJavaObject(genTestSetObject()), genTestSetDict());
}

@Test
public void testPojoSet() throws Exception {
TestClassSet test = genTestSetObject();
NSDictionary dict = genTestSetDict();
Expand All @@ -73,10 +81,6 @@ public void testPojoSet() throws Exception {
assertEquals(test, dict.toJavaObject(TestClassSet.class));
}

public void testUid() throws Exception {

}

private NSDictionary genTestSetDict() {
NSDictionary dict = new NSDictionary();
dict.put("stringSet", new NSSet(new NSString("value")));
Expand Down
40 changes: 27 additions & 13 deletions src/test/java/com/dd/plist/test/GoogleCodeIssueTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.dd.plist.test;

import com.dd.plist.*;
import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

/**
* This class contains tests for issues that were managed with the Google Code issue tracking system
*/
public class GoogleCodeIssueTest extends TestCase {
public static void testIssue4() throws Exception {
public class GoogleCodeIssueTest {
@Test
public void testIssue4() throws Exception {
NSDictionary d = (NSDictionary)PropertyListParser.parse(new File("test-files/issue4.plist"));
assertTrue(((NSString)d.objectForKey("Device Name")).toString().equals("Kid\u2019s iPhone"));
}

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

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

public static void testIssue18() throws Exception {
@Test
public void testIssue18() throws Exception {
NSNumber x = new NSNumber(-999);
PropertyListParser.saveAsBinary(x, new File("test-files/out-testIssue18.plist"));
NSObject y = PropertyListParser.parse(new File("test-files/out-testIssue18.plist"));
assertTrue(x.equals(y));
}

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

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

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

public static void testIssue33() throws Exception {
@Test
public void testIssue33() throws Exception {
NSDictionary dict = (NSDictionary)PropertyListParser.parse(new File("test-files/issue33.pbxproj"));
}
public static void testIssue38() throws Exception {

@Test
public void testIssue38() throws Exception {
NSDictionary dict = (NSDictionary)PropertyListParser.parse(new File("test-files/issue33.pbxproj"));
NSObject fileRef = ((NSDictionary) ((NSDictionary)dict.get("objects")).get("65541A9C16D13B8C00A968D5")).get("fileRef");
assertTrue(fileRef.equals(new NSString("65541A9B16D13B8C00A968D5")));
Expand All @@ -80,7 +92,8 @@ public static void testIssue38() throws Exception {
/**
* Test storing null values
*/
public static void testIssue41() {
@Test
public void testIssue41() {
//Dictionary
Map<String, Object> nullMap = new HashMap<String, Object>();
nullMap.put("key", null);
Expand Down Expand Up @@ -140,7 +153,8 @@ public static void testIssue41() {
}
}

public static void testIssue49() throws Exception {
@Test
public void testIssue49() throws Exception {
NSDictionary dict = (NSDictionary)PropertyListParser.parse(new File("test-files/issue49.plist"));
assertEquals(0, dict.count());
}
Expand Down
19 changes: 6 additions & 13 deletions src/test/java/com/dd/plist/test/IssueTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.dd.plist.test;

import com.dd.plist.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXParseException;

import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

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

@Test(expected = PropertyListFormatException.class)
@Test
public void testIssue42_OutOfMemoryErrorWhenBinaryPropertyListTrailerIsCorrupt() throws Exception {
File plistFile = new File("test-files/github-issue42.plist");
PropertyListParser.parse(plistFile);
assertThrows(PropertyListFormatException.class, () -> PropertyListParser.parse(plistFile));
}

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

try {
XMLPropertyListParser.parse(is);
Assert.fail();
}
catch (SAXParseException ex) {
// This is the expectation
}
assertThrows(SAXParseException.class, () -> XMLPropertyListParser.parse(is));
}
}
Loading

0 comments on commit 55a3ad8

Please sign in to comment.