aboutsummaryrefslogtreecommitdiffhomepage
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/core/src/test/java/com/google/protobuf/MapTest.java23
-rw-r--r--java/util/src/main/java/com/google/protobuf/util/JsonFormat.java2
-rw-r--r--java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java24
3 files changed, 24 insertions, 25 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 9ce5ebc9..45019537 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 {
@@ -1251,12 +1245,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"));
diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
index 37fa194a..e1c2d73d 100644
--- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
+++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
@@ -1558,7 +1558,7 @@ public class JsonFormat {
BigDecimal value = new BigDecimal(json.getAsString());
return value.longValueExact();
} catch (Exception e) {
- throw new InvalidProtocolBufferException("Not an int32 value: " + json);
+ throw new InvalidProtocolBufferException("Not an int64 value: " + json);
}
}
diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
index 695176ed..460b81f6 100644
--- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
+++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
@@ -233,9 +233,7 @@ public class JsonFormatTest extends TestCase {
TestMap.Builder mapBuilder = TestMap.newBuilder();
mapBuilder.putInt32ToEnumMapValue(1, 0);
- Map<Integer, Integer> mapWithInvalidValues = new HashMap<Integer, Integer>();
- mapWithInvalidValues.put(2, 12345);
- mapBuilder.putAllInt32ToEnumMapValue(mapWithInvalidValues);
+ mapBuilder.putInt32ToEnumMapValue(2, 12345);
TestMap mapMessage = mapBuilder.build();
assertEquals(
"{\n"
@@ -268,7 +266,7 @@ public class JsonFormatTest extends TestCase {
assertRoundTripEquals(message);
}
- public void testParserAcceptStringForNumbericField() throws Exception {
+ public void testParserAcceptStringForNumericField() throws Exception {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
mergeFromJson(
"{\n"
@@ -483,8 +481,8 @@ public class JsonFormatTest extends TestCase {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
mergeFromJson(
"{\n"
- + " \"repeatedNestedMessage\": [null, null],\n"
- + " \"repeated_nested_message\": [null, null]\n"
+ + " \"repeatedInt32\": [1, 2],\n"
+ + " \"repeated_int32\": [5, 6]\n"
+ "}",
builder);
fail();
@@ -492,7 +490,7 @@ public class JsonFormatTest extends TestCase {
// Exception expected.
}
- // Duplicated oneof fields.
+ // Duplicated oneof fields, same name.
try {
TestOneof.Builder builder = TestOneof.newBuilder();
mergeFromJson("{\n" + " \"oneofInt32\": 1,\n" + " \"oneof_int32\": 2\n" + "}", builder);
@@ -500,6 +498,16 @@ public class JsonFormatTest extends TestCase {
} catch (InvalidProtocolBufferException e) {
// Exception expected.
}
+
+ // Duplicated oneof fields, different name.
+ try {
+ TestOneof.Builder builder = TestOneof.newBuilder();
+ mergeFromJson(
+ "{\n" + " \"oneofInt32\": 1,\n" + " \"oneofNullValue\": null\n" + "}", builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
}
public void testMapFields() throws Exception {
@@ -1093,7 +1101,7 @@ public class JsonFormatTest extends TestCase {
public void testParserUnexpectedTypeUrl() throws Exception {
try {
- TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ Any.Builder builder = Any.newBuilder();
mergeFromJson(
"{\n"
+ " \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"