aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJisi Liu <jisi.liu@gmail.com>2015-02-05 14:26:52 -0800
committerJisi Liu <jisi.liu@gmail.com>2015-02-05 14:26:52 -0800
commitca35a8030339d85cb4efb928b1aae8e38584d214 (patch)
tree99eb45f6fb01a7a8a1d953b7f0c9704e79dc8394
parent0d52964597d0552f5ab4442f9908fd39d8650b23 (diff)
downloadprotobuf-ca35a8030339d85cb4efb928b1aae8e38584d214.tar.gz
protobuf-ca35a8030339d85cb4efb928b1aae8e38584d214.tar.bz2
protobuf-ca35a8030339d85cb4efb928b1aae8e38584d214.zip
Test keys and values cannot be null.
-rw-r--r--javanano/src/test/java/com/google/protobuf/nano/NanoTest.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
index 0edf6d6d..a7383cb4 100644
--- a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
+++ b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
@@ -3742,11 +3742,33 @@ public class NanoTest extends TestCase {
byte[] output = MessageNano.toByteArray(origin);
TestMap parsed = new TestMap();
MessageNano.mergeFrom(parsed, output);
- // TODO(liujisi): Test null values in serialization.
// TODO(liujisi): Test merging message type values.
// TODO(liujisi): Test missing key/value in parsing.
}
+ public void testMapSerializeRejectNull() throws Exception {
+ TestMap primitiveMap = new TestMap();
+ primitiveMap.int32ToInt32Field = new HashMap<Integer, Integer>();
+ primitiveMap.int32ToInt32Field.put(null, 1);
+ try {
+ MessageNano.toByteArray(primitiveMap);
+ fail("should reject null keys");
+ } catch (IllegalStateException e) {
+ // pass.
+ }
+
+ TestMap messageMap = new TestMap();
+ messageMap.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ messageMap.int32ToMessageField.put(0, null);
+ try {
+ MessageNano.toByteArray(messageMap);
+ fail("should reject null values");
+ } catch (IllegalStateException e) {
+ // pass.
+ }
+ }
+
private static final Integer[] int32Values = new Integer[] {
0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE,
};