File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
jvm/src/test/scala/scala/xml
shared/src/main/scala/scala/xml Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1+ package scala .xml
2+
3+ import java .io ._
4+
5+ import org .junit .Assert .assertEquals
6+ import org .junit .Test
7+
8+ class SerializationTest {
9+ def roundTrip [T ](obj : T ): T = {
10+ def serialize (in : T ): Array [Byte ] = {
11+ val bos = new ByteArrayOutputStream ()
12+ val oos = new ObjectOutputStream (bos)
13+ oos.writeObject(in)
14+ oos.flush()
15+ bos.toByteArray()
16+ }
17+
18+ def deserialize (in : Array [Byte ]): T = {
19+ val bis = new ByteArrayInputStream (in)
20+ val ois = new ObjectInputStream (bis)
21+ ois.readObject.asInstanceOf [T ]
22+ }
23+
24+ deserialize(serialize(obj))
25+ }
26+
27+ @ Test
28+ def xmlLiteral : Unit = {
29+ val n = <node />
30+ assertEquals(n, roundTrip(n))
31+ }
32+
33+ @ Test
34+ def empty : Unit = {
35+ assertEquals(NodeSeq .Empty , roundTrip(NodeSeq .Empty ))
36+ }
37+
38+ @ Test
39+ def implicitConversion : Unit = {
40+ val parent = <parent ><child ></child ><child /></parent >
41+ val children : Seq [Node ] = parent.child
42+ val asNodeSeq : NodeSeq = children
43+ assertEquals(asNodeSeq, roundTrip(asNodeSeq))
44+ }
45+ }
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ object NodeSeq {
4242 * @author Burak Emir
4343 * @version 1.0
4444 */
45- abstract class NodeSeq extends AbstractSeq [Node ] with immutable.Seq [Node ] with SeqLike [Node , NodeSeq ] with Equality {
45+ abstract class NodeSeq extends AbstractSeq [Node ] with immutable.Seq [Node ] with SeqLike [Node , NodeSeq ] with Equality with Serializable {
4646
4747 /** Creates a list buffer as builder for this class */
4848 override protected [this ] def newBuilder = NodeSeq .newBuilder
You can’t perform that action at this time.
0 commit comments