Skip to content

Commit

Permalink
Add a test for #21
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 20, 2015
1 parent e564cb4 commit df0be55
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
public class ReadSimpleTest extends TestBase
{
enum ABC { A, B, C; }

static class WithEnumMap {
private Map<ABC, String> values;

WithEnumMap() { }
public WithEnumMap(ABC key, String value) {
values = new LinkedHashMap<ABC,String>();
values.put(key, value);
}

public Map<ABC, String> getValues() { return values; }
public void setValues(Map<ABC, String> v) { values = v; }
}

public void testSimpleList() throws Exception
{
Expand Down Expand Up @@ -75,4 +88,26 @@ public void testSimpleEnums() throws Exception
abc = JSON.std.beanFrom(ABC.class, quote("C"));
assertEquals(ABC.C, abc);
}

// [issue#21]
public void testMapWithEnumKey() throws Exception
{
WithEnumMap input = new WithEnumMap(ABC.B, "bar");
// verify serialization, should be ok:
String json = JSON.std.asString(input);
assertEquals(aposToQuotes("{'values':{'B':'bar'}}"), json);

// and then get it back too
WithEnumMap result = JSON.std.beanFrom(WithEnumMap.class, json);
assertNotNull(result);
Map<ABC, String> map = result.getValues();
assertNotNull(map);
assertEquals(1, map.size());
Map.Entry<?,?> entry = map.entrySet().iterator().next();
assertEquals("bar", entry.getValue());
if (!(entry.getKey() instanceof ABC)) {
fail("Expected key to be of type ABC, is: "+entry.getKey().getClass().getName());
}
assertEquals(ABC.B, entry.getKey());
}
}

0 comments on commit df0be55

Please sign in to comment.