Skip to content

Commit

Permalink
Add test from EsotericSoftware#385
Browse files Browse the repository at this point in the history
  • Loading branch information
magro committed Jun 17, 2016
1 parent 2de0896 commit 50f7f36
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions test/com/esotericsoftware/kryo/MapSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

package com.esotericsoftware.kryo;

import java.io.ByteArrayInputStream;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
Expand Down Expand Up @@ -167,6 +169,31 @@ public void testTreeMapWithReferences () {
map.put("4", 44);
roundTrip(29, 43, map);
}

public void testSerializingMapAfterDeserializingMultipleReferencesToSameMap() throws Exception {
Kryo kryo = new Kryo();
kryo.getFieldSerializerConfig().setOptimizedGenerics(false);
Output output = new Output(4096);

kryo.writeClassAndObject(output, new HasMultipleReferenceToSameMap());
kryo.readClassAndObject(new Input(new ByteArrayInputStream(output.getBuffer())));
output.clear();

Map<Integer, List<String>> mapOfLists = new HashMap<Integer, List<String>>();
mapOfLists.put(1, new java.util.ArrayList<String>());
kryo.writeClassAndObject(output, mapOfLists);

@SuppressWarnings("unchecked")
Map<Integer, List<String>> deserializedMap =
(Map<Integer, List<String>>) kryo.readClassAndObject(new Input(new ByteArrayInputStream(output.getBuffer())));
assertEquals(1, deserializedMap.size());
}

@SuppressWarnings("unused")
static class HasMultipleReferenceToSameMap {
private Map<Integer, String> mapOne = new HashMap<Integer, String>();
private Map<Integer, String> mapTwo = this.mapOne;
}

static public class HasGenerics {
public HashMap<String, Integer[]> map = new HashMap();
Expand Down Expand Up @@ -195,4 +222,4 @@ public TreeMapSubclass(Comparator<? super K> comparator) {
super(comparator);
}
}
}
}

0 comments on commit 50f7f36

Please sign in to comment.