Log Message
Add test for lambda expressions.
Modified Paths
Added Paths
Diff
Modified: trunk/xstream/pom.xml (2305 => 2306)
--- trunk/xstream/pom.xml 2014-12-12 20:40:31 UTC (rev 2305)
+++ trunk/xstream/pom.xml 2015-01-10 23:47:51 UTC (rev 2306)
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--
Copyright (C) 2006 Joe Walnes.
- Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream committers.
+ Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream committers.
All rights reserved.
The software in this package is published under the terms of the BSD
@@ -216,6 +216,65 @@
<profiles>
<profile>
+ <id>jdk18ge</id>
+ <activation>
+ <jdk>[1.8,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerArgs>
+ <arg>-XDignore.symbol.file</arg>
+ </compilerArgs>
+ <testExcludes>
+ <exclude>**/Lambda**</exclude>
+ </testExcludes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>compile-jdk18</id>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ <testExcludes>
+ <exclude>foo</exclude>
+ </testExcludes>
+ </configuration>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>jdk17</id>
+ <activation>
+ <jdk>1.7</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerArgs>
+ <arg>-XDignore.symbol.file</arg>
+ </compilerArgs>
+ <testExcludes>
+ <exclude>**/Lambda**</exclude>
+ </testExcludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
<id>jdk15-16</id>
<activation>
<jdk>[1.5,1.7)</jdk>
@@ -230,6 +289,7 @@
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<testExcludes>
+ <exclude>**/Lambda**</exclude>
<exclude>**/extended/*17Test*</exclude>
</testExcludes>
</configuration>
Added: trunk/xstream/src/test/com/thoughtworks/acceptance/LambdaTest.java (0 => 2306)
--- trunk/xstream/src/test/com/thoughtworks/acceptance/LambdaTest.java (rev 0)
+++ trunk/xstream/src/test/com/thoughtworks/acceptance/LambdaTest.java 2015-01-10 23:47:51 UTC (rev 2306)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2014, 2015 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 31. December 2014 by Joerg Schaible
+ */
+package com.thoughtworks.acceptance;
+
+import java.io.Serializable;
+import java.lang.invoke.SerializedLambda;
+import java.util.concurrent.Callable;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.mapper.MapperWrapper;
+
+/**
+ * @author Jörg Schaible
+ */
+public class LambdaTest extends AbstractAcceptanceTest {
+ String s = "";
+
+ public static class LambdaKeeper {
+ private Callable<String> callable;
+ @SuppressWarnings("unused")
+ private Callable<String> referenced;
+ void keep(Callable<String> c) {
+ callable = c;
+ }
+ void reference() {
+ referenced = callable;
+ }
+ }
+
+ public void testLambdaExpression() {
+ LambdaKeeper keeper = new LambdaKeeper();
+ keeper.keep((Callable<String> & Serializable)() -> "result");
+
+ String expected = ""
+ + "<keeper>\n"
+ + " <callable class=\"" + keeper.callable.getClass().getName() + "\" resolves-to=\"java.lang.invoke.SerializedLambda\">\n"
+ + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
+ + " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
+ + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
+ + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
+ + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
+ + " <implMethodName>lambda$0</implMethodName>\n" // Eclipse compiler name
+ + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
+ + " <implMethodKind>6</implMethodKind>\n"
+ + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
+ + " <capturedArgs/>\n"
+ + " </callable>\n"
+ + "</keeper>";
+ xstream.alias("keeper", LambdaKeeper.class);
+ xstream.allowTypes(SerializedLambda.class);
+
+ assertBothWaysNormalized(keeper, expected);
+
+// Object resultRoot = xstream.fromXML(expected);
+// assertNotNull(resultRoot);
+ }
+
+ public void testReferencedLambdaExpression() {
+ LambdaKeeper keeper = new LambdaKeeper();
+ keeper.keep((Callable<String> & Serializable)() -> "result");
+ keeper.reference();
+
+ String expected = ""
+ + "<keeper>\n"
+ + " <callable class=\"" + keeper.callable.getClass().getName() + "\" resolves-to=\"java.lang.invoke.SerializedLambda\">\n"
+ + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
+ + " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
+ + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
+ + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
+ + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
+ + " <implMethodName>lambda$0</implMethodName>\n" // Eclipse compiler name
+ + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
+ + " <implMethodKind>6</implMethodKind>\n"
+ + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
+ + " <capturedArgs/>\n"
+ + " </callable>\n"
+ + " <referenced class=\"" +keeper.callable.getClass().getName() + "\" reference=\"../callable\"/>\n"
+ + "</keeper>";
+ xstream = new XStream() {
+ protected MapperWrapper wrapMapper(MapperWrapper next) {
+ return new MapperWrapper(next) {
+
+ @Override
+ public Class<?> realClass(String elementName) {
+ if (elementName.matches(".*\\$\\$Lambda\\$[0-9]+/[0-9]+"))
+ return null;
+ else
+ return super.realClass(elementName);
+ }
+ };
+ }
+ };
+ setupSecurity(xstream);
+ xstream.alias("keeper", LambdaKeeper.class);
+ xstream.allowTypes(SerializedLambda.class);
+
+ assertBothWaysNormalized(keeper, expected);
+ }
+
+ private void assertBothWaysNormalized(LambdaKeeper keeper, String expected) {
+ String resultXml = toXML(keeper);
+ assertEquals(normalizeLambda(expected), normalizeLambda(resultXml));
+
+ Object resultRoot = xstream.fromXML(resultXml);
+ resultXml = toXML(resultRoot);
+ assertEquals(normalizeLambda(expected), normalizeLambda(resultXml));
+ }
+
+ private String normalizeLambda(String xml) {
+ return xml.replaceAll("\\$\\$Lambda\\$[/0-9]+\"", "\\$\\$Lambda\\$\"").replaceAll(">lambda\\$[^<]+<", ">lambda\\$0<");
+ }
+}
Property changes on: trunk/xstream/src/test/com/thoughtworks/acceptance/LambdaTest.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
To unsubscribe from this list please visit:
