Skip to content

Commit

Permalink
Add a test case for issue magro#90
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr14huashao committed Sep 22, 2020
1 parent cc89b03 commit d0c74d0
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import static org.testng.Assert.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.Set;

import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import org.junit.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

Expand All @@ -25,12 +31,14 @@ private static enum Colors {

private Kryo _kryo;
private EnumMap<Vipers, Set<String>> _original;

private EnumMap<Vipers, Object> _newTempMap;

@BeforeTest
protected void beforeTest() {
_kryo = new Kryo();
_kryo.register(EnumMap.class, new EnumMapSerializer());
_original = new EnumMap<Vipers, Set<String>>(Vipers.class);
_newTempMap = new EnumMap<Vipers, Object>(Vipers.class);
}

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand All @@ -57,4 +65,35 @@ public void testDeepCopy() throws Exception {
assertNotSame(_original.get(Vipers.BLACK_MAMBA), copy.get(Vipers.BLACK_MAMBA));
assertEquals(_original, copy);
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testEnumMapNest() throws Exception {
_kryo.register(HashSet.class);
_kryo.register(Vipers.class);
_kryo.register(Colors.class);
_kryo.register(EnumMap.class, new EnumMapSerializer());

final Set<String> mambaAka = new HashSet<String>();
final Set<String> papaAka = new HashSet<>();
mambaAka.add("Beatrix Kiddo");
mambaAka.add("The Bride");
papaAka.add("Good Job");
papaAka.add("There is Great");

_original.put(Vipers.BLACK_MAMBA, mambaAka);
_original.put(Vipers.SIDEWINDER, papaAka);
_newTempMap.put(Vipers.COPPERHEAD, _original);

final File outputFile = File.createTempFile("input_file", "dat");
try (final Output output = new Output(new FileOutputStream(outputFile))) {
_kryo.writeObject(output, _newTempMap);
output.flush();
output.close();
final Input input = new Input(new FileInputStream(outputFile));
final EnumMap tEnumMap = _kryo.readObject(input, EnumMap.class);
input.close();
Assert.assertEquals(_newTempMap, tEnumMap);
}
}
}

0 comments on commit d0c74d0

Please sign in to comment.