diff options
author | Lucas Lin <lucaslin@google.com> | 2020-04-17 08:37:41 +0000 |
---|---|---|
committer | Lucas Lin <lucaslin@google.com> | 2020-04-17 11:03:36 +0000 |
commit | 4e78cfa60dc0e9ad5c227b6920a3a05c9cb97ca5 (patch) | |
tree | a4d1005ebd33f72f19d8b5ba30d0d6bc2f6a6a11 | |
parent | 17fd4b42c696edbecb2f931ea521b37b05816c76 (diff) |
Refine NetworkMonitorTest#testReadAsString_StreamShorterThanLimit()
The characters of string may not only contain ASCII characters,
so the length of string may not the same as bytes.
Replace the string to byte[].
Bug: 154217644
Test: atest NetworkStackTests:NetworkMonitorTest
Change-Id: I3c1f826ef1be0302fdb19c294087464af8573105
Merged-In: I6552a6c8a291d54fc16bd3a1df3ab29a4481b20d
(cherry picked from commit 57096958ca18bf26ea8bbc7b2fb48619a1756097)
-rw-r--r-- | tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java index b755d61..26630f8 100644 --- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java @@ -1861,15 +1861,13 @@ public class NetworkMonitorTest { @Test public void testReadAsString_StreamShorterThanLimit() throws Exception { final WrappedNetworkMonitor wnm = makeNotMeteredNetworkMonitor(); - final String content = "The HTTP response code is 200 but it is not a captive portal."; - ByteArrayInputStream inputStream = new ByteArrayInputStream( - content.getBytes(StandardCharsets.UTF_8)); - assertEquals(content, wnm.readAsString(inputStream, content.length(), - StandardCharsets.UTF_8)); - // Reset the inputStream and test the case that the stream ends earlier than the limit. - inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); - assertEquals(content, wnm.readAsString(inputStream, content.length() + 10, - StandardCharsets.UTF_8)); + final byte[] content = "The HTTP response code is 200 but it is not a captive portal." + .getBytes(StandardCharsets.UTF_8); + assertEquals(new String(content), wnm.readAsString(new ByteArrayInputStream(content), + content.length, StandardCharsets.UTF_8)); + // Test the case that the stream ends earlier than the limit. + assertEquals(new String(content), wnm.readAsString(new ByteArrayInputStream(content), + content.length + 10, StandardCharsets.UTF_8)); } @Test |