|
|
@ -490,19 +490,13 @@ public class MapTest extends TestCase { |
|
|
|
public void testPutForUnknownEnumValues() throws Exception { |
|
|
|
public void testPutForUnknownEnumValues() throws Exception { |
|
|
|
TestMap.Builder builder = TestMap.newBuilder() |
|
|
|
TestMap.Builder builder = TestMap.newBuilder() |
|
|
|
.putInt32ToEnumFieldValue(0, 0) |
|
|
|
.putInt32ToEnumFieldValue(0, 0) |
|
|
|
.putInt32ToEnumFieldValue(1, 1); |
|
|
|
.putInt32ToEnumFieldValue(1, 1) |
|
|
|
|
|
|
|
.putInt32ToEnumFieldValue(2, 1000); // unknown value.
|
|
|
|
try { |
|
|
|
|
|
|
|
builder.putInt32ToEnumFieldValue(2, 1000); // unknown value.
|
|
|
|
|
|
|
|
fail(); |
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
|
|
|
|
// expected
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestMap message = builder.build(); |
|
|
|
TestMap message = builder.build(); |
|
|
|
assertEquals(0, message.getInt32ToEnumFieldValueOrThrow(0)); |
|
|
|
assertEquals(0, message.getInt32ToEnumFieldValueOrThrow(0)); |
|
|
|
assertEquals(1, message.getInt32ToEnumFieldValueOrThrow(1)); |
|
|
|
assertEquals(1, message.getInt32ToEnumFieldValueOrThrow(1)); |
|
|
|
assertEquals(2, message.getInt32ToEnumFieldCount()); |
|
|
|
assertEquals(1000, message.getInt32ToEnumFieldValueOrThrow(2)); |
|
|
|
|
|
|
|
assertEquals(3, message.getInt32ToEnumFieldCount()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testPutChecksNullKeysAndValues() throws Exception { |
|
|
|
public void testPutChecksNullKeysAndValues() throws Exception { |
|
|
@ -1250,12 +1244,9 @@ public class MapTest extends TestCase { |
|
|
|
builder.putInt32ToEnumFieldValue(1, TestMap.EnumValue.BAR.getNumber()); |
|
|
|
builder.putInt32ToEnumFieldValue(1, TestMap.EnumValue.BAR.getNumber()); |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
TestMap.EnumValue.BAR.getNumber(), builder.getInt32ToEnumFieldValueOrThrow(1)); |
|
|
|
TestMap.EnumValue.BAR.getNumber(), builder.getInt32ToEnumFieldValueOrThrow(1)); |
|
|
|
try { |
|
|
|
|
|
|
|
builder.putInt32ToEnumFieldValue(1, -1); |
|
|
|
builder.putInt32ToEnumFieldValue(1, -1); |
|
|
|
fail(); |
|
|
|
assertEquals(-1, builder.getInt32ToEnumFieldValueOrThrow(1)); |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertEquals(TestMap.EnumValue.UNRECOGNIZED, builder.getInt32ToEnumFieldOrThrow(1)); |
|
|
|
// expected
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.putStringToInt32Field("a", 1); |
|
|
|
builder.putStringToInt32Field("a", 1); |
|
|
|
assertEquals(1, builder.getStringToInt32FieldOrThrow("a")); |
|
|
|
assertEquals(1, builder.getStringToInt32FieldOrThrow("a")); |
|
|
|