aboutsummaryrefslogtreecommitdiffhomepage
path: root/java/core/src
diff options
context:
space:
mode:
authorGravatar Anuraag Agrawal <anuraaga@gmail.com>2017-04-07 14:50:52 +0900
committerGravatar Anuraag Agrawal <anuraaga@gmail.com>2017-04-07 14:50:52 +0900
commitbf483dfb99a5b7c57ee0a222bd041275cda9cf98 (patch)
tree9f1c55151e63924378d5dc0a4a6a4853ff77b76a /java/core/src
parentefec7571047c680e11354bd30bf8bd3dfda15ff0 (diff)
Allow unknown values for Map put*Value methods just like every other enum mutation method.
Diffstat (limited to 'java/core/src')
-rw-r--r--java/core/src/test/java/com/google/protobuf/MapTest.java23
1 files changed, 7 insertions, 16 deletions
diff --git a/java/core/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java
index 81e951cc..e0d3f0cd 100644
--- a/java/core/src/test/java/com/google/protobuf/MapTest.java
+++ b/java/core/src/test/java/com/google/protobuf/MapTest.java
@@ -490,19 +490,13 @@ public class MapTest extends TestCase {
public void testPutForUnknownEnumValues() throws Exception {
TestMap.Builder builder = TestMap.newBuilder()
.putInt32ToEnumFieldValue(0, 0)
- .putInt32ToEnumFieldValue(1, 1);
-
- try {
- builder.putInt32ToEnumFieldValue(2, 1000); // unknown value.
- fail();
- } catch (IllegalArgumentException e) {
- // expected
- }
-
+ .putInt32ToEnumFieldValue(1, 1)
+ .putInt32ToEnumFieldValue(2, 1000); // unknown value.
TestMap message = builder.build();
assertEquals(0, message.getInt32ToEnumFieldValueOrThrow(0));
assertEquals(1, message.getInt32ToEnumFieldValueOrThrow(1));
- assertEquals(2, message.getInt32ToEnumFieldCount());
+ assertEquals(1000, message.getInt32ToEnumFieldValueOrThrow(2));
+ assertEquals(3, message.getInt32ToEnumFieldCount());
}
public void testPutChecksNullKeysAndValues() throws Exception {
@@ -1250,12 +1244,9 @@ public class MapTest extends TestCase {
builder.putInt32ToEnumFieldValue(1, TestMap.EnumValue.BAR.getNumber());
assertEquals(
TestMap.EnumValue.BAR.getNumber(), builder.getInt32ToEnumFieldValueOrThrow(1));
- try {
- builder.putInt32ToEnumFieldValue(1, -1);
- fail();
- } catch (IllegalArgumentException e) {
- // expected
- }
+ builder.putInt32ToEnumFieldValue(1, -1);
+ assertEquals(-1, builder.getInt32ToEnumFieldValueOrThrow(1));
+ assertEquals(TestMap.EnumValue.UNRECOGNIZED, builder.getInt32ToEnumFieldOrThrow(1));
builder.putStringToInt32Field("a", 1);
assertEquals(1, builder.getStringToInt32FieldOrThrow("a"));