package com.github.davidmoten.rtree;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.junit.Test;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;

public class KryoSerializationTest {

    @Test
    public void testRTree() {
        Kryo kryo = new Kryo();
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        Output output = new Output(bytes);
        RTree<String, Point> tree = RTree.<String, Point> create()
                .add(Entries.entry("thing", Geometries.point(10, 20)))
                .add(Entries.entry("monster", Geometries.point(23, 45)));
        kryo.writeObject(output, tree);
        output.close();
        Input input = new Input(new ByteArrayInputStream(bytes.toByteArray()));
        RTree<String, Point> tree2 = kryo.readObject(input, RTree.class);
    }

}

@@ -31,16 +31,62 @@
 rtree;%0A%0A
+import static org.junit.Assert.assertEquals;%0A%0A
 import j
@@ -1057,21 +1057,761 @@
 ree.class);%0A
+        assertEquals(2, (int) tree2.entries().count().toBlocking().single());%0A    %7D%0A%0A    @Test%0A    public void testKryo() %7B%0A        Kryo kryo = new Kryo();%0A        ByteArrayOutputStream bytes = new ByteArrayOutputStream();%0A        Output output = new Output(bytes);%0A        Boo b = new Boo(%22hello%22);%0A        kryo.writeObject(output, b);%0A        output.close();%0A        Input input = new Input(new ByteArrayInputStream(bytes.toByteArray()));%0A        Boo b2 = kryo.readObject(input, Boo.class);%0A        assertEquals(%22hello%22, b2.name);%0A    %7D%0A%0A    public static class Boo %7B%0A%0A        public final String name;%0A%0A        private Boo() %7B%0A            this(%22boo%22);%0A        %7D%0A%0A        public Boo(String name) %7B%0A            this.name = name;%0A        %7D%0A
     %7D%0A%0A%7D%0A

add kryo serialization test