Skip to content

Commit

Permalink
fix unit test failed. (sofastack#681)
Browse files Browse the repository at this point in the history
* fix unit test failed.

* Avoid null key transfer to headers
  • Loading branch information
zonghaishang authored Jun 21, 2019
1 parent e277116 commit 9e5c4eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ public byte[] encode(Map<String, String> map) throws SerializationException {
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
writeSupportEmpty(key, out);
writeSupportEmpty(value, out);
/**
* 排除不写null作为key
*/
if(key != null){
writeSupportEmpty(key, out);
writeSupportEmpty(value, out);
}
}
return out.toByteArray();
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public void encode() throws Exception {
map.put("a", "");
map.put("b", null);
bs = simpleMapSerializer.encode(map);
Assert.assertEquals(10, bs.length);
Assert.assertEquals(37, bs.length);

Map<String, String> map1 = simpleMapSerializer.decode(bs);
Assert.assertNotNull(map1);
Assert.assertEquals(1, map1.size());
Assert.assertEquals(4, map1.size());
Assert.assertEquals("2", map1.get("1"));
Assert.assertEquals(null, map1.get(""));
Assert.assertEquals(null, map1.get("a"));
Assert.assertEquals(null, map1.get("b"));
Assert.assertEquals("x", map1.get(""));
Assert.assertEquals("", map1.get("a"));
Assert.assertEquals("", map1.get("b"));

map1 = simpleMapSerializer.decode(null);
Assert.assertNotNull(map1);
Expand Down

0 comments on commit 9e5c4eb

Please sign in to comment.