diff options
Diffstat (limited to 'java/src/test/java/com/google/protobuf/AbstractMessageTest.java')
-rw-r--r-- | java/src/test/java/com/google/protobuf/AbstractMessageTest.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/java/src/test/java/com/google/protobuf/AbstractMessageTest.java b/java/src/test/java/com/google/protobuf/AbstractMessageTest.java index 3d05cb7d..fcbf019d 100644 --- a/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +++ b/java/src/test/java/com/google/protobuf/AbstractMessageTest.java @@ -506,4 +506,22 @@ public class AbstractMessageTest extends TestCase { String.format("%s should have a different hash code from %s", m1, m2), m1.hashCode() == m2.hashCode()); } + + public void testCheckByteStringIsUtf8OnUtf8() { + ByteString byteString = ByteString.copyFromUtf8("some text"); + AbstractMessageLite.checkByteStringIsUtf8(byteString); + // No exception thrown. + } + + public void testCheckByteStringIsUtf8OnNonUtf8() { + ByteString byteString = + ByteString.copyFrom(new byte[]{(byte) 0x80}); // A lone continuation byte. + try { + AbstractMessageLite.checkByteStringIsUtf8(byteString); + fail("Expected AbstractMessageLite.checkByteStringIsUtf8 to throw IllegalArgumentException"); + } catch (IllegalArgumentException exception) { + assertEquals("Byte string is not UTF-8.", exception.getMessage()); + } + } + } |