mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-15 21:12:15 +00:00
[JENKINS-10903] Serialize ImmutableList in the same manner as ImmutableMap.
This is a partial fix for JENKINS-10903. Any new builds will be serialized correctly. Based on ImmutableMapConverter.java
This commit is contained in:
1 parent
b27b5f4ea3
commit
ebee47bb75
3 files changed
+128
-1
No files matched your search
@@ -23,12 +23,16 @@
|
||||
*/
|
||||
package hudson.util;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import junit.framework.TestCase;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Run;
|
||||
|
||||
import org.jvnet.hudson.test.Bug;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -125,7 +129,6 @@ public class XStream2Test extends TestCase {
|
||||
Map<?,?> m;
|
||||
}
|
||||
|
||||
|
||||
public void testImmutableMap() {
|
||||
XStream2 xs = new XStream2();
|
||||
|
||||
@@ -166,6 +169,54 @@ public class XStream2Test extends TestCase {
|
||||
assertEquals(m,a.m);
|
||||
}
|
||||
|
||||
private static class ImmutableListHolder {
|
||||
ImmutableList<?> l;
|
||||
}
|
||||
|
||||
private static class ListHolder {
|
||||
List<?> l;
|
||||
}
|
||||
|
||||
public void testImmutableList() {
|
||||
XStream2 xs = new XStream2();
|
||||
|
||||
roundtripImmutableList(xs, ImmutableList.of());
|
||||
roundtripImmutableList(xs, ImmutableList.of("abc"));
|
||||
roundtripImmutableList(xs, ImmutableList.of("abc", "def"));
|
||||
|
||||
roundtripImmutableListAsPlainList(xs, ImmutableList.of());
|
||||
roundtripImmutableListAsPlainList(xs, ImmutableList.of("abc"));
|
||||
roundtripImmutableListAsPlainList(xs, ImmutableList.of("abc", "def"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the field type is {@link ImmutableList}, XML shouldn't contain a reference to the type name.
|
||||
*/
|
||||
private void roundtripImmutableList(XStream2 xs, ImmutableList<?> l) {
|
||||
ImmutableListHolder a = new ImmutableListHolder();
|
||||
a.l = l;
|
||||
String xml = xs.toXML(a);
|
||||
//System.out.println(xml);
|
||||
assertFalse("shouldn't contain the class name",xml.contains("google"));
|
||||
assertFalse("shouldn't contain the class name",xml.contains("class"));
|
||||
a = (ImmutableListHolder)xs.fromXML(xml);
|
||||
|
||||
assertSame(l.getClass(),a.l.getClass()); // should get back the exact same type, not just a random list
|
||||
assertEquals(l,a.l);
|
||||
}
|
||||
|
||||
private void roundtripImmutableListAsPlainList(XStream2 xs, ImmutableList<?> l) {
|
||||
ListHolder a = new ListHolder();
|
||||
a.l = l;
|
||||
String xml = xs.toXML(a);
|
||||
//System.out.println(xml);
|
||||
assertTrue("XML should mention the class name",xml.contains('\"'+ImmutableList.class.getName()+'\"'));
|
||||
a = (ListHolder)xs.fromXML(xml);
|
||||
|
||||
assertSame(l.getClass(),a.l.getClass()); // should get back the exact same type, not just a random list
|
||||
assertEquals(l,a.l);
|
||||
}
|
||||
|
||||
@Bug(8006) // Previously a null entry in an array caused NPE
|
||||
public void testEmptyStack() {
|
||||
assertEquals("<object-array><null/><null/></object-array>",
|
||||
|
||||
Reference in new issue
Block a user