diff options
author | Victor Chang <vichang@google.com> | 2024-04-19 22:34:32 +0100 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2024-04-19 22:43:52 +0100 |
commit | 8cbce3901152cf83a7dd0054a9778dccf2fbdb79 (patch) | |
tree | d9a1838717bafaef00fa1b1301eae69d5a286ab5 | |
parent | c6b25a05cd75f53ade908da0bc0761b7a8fa4410 (diff) | |
download | icu-8cbce3901152cf83a7dd0054a9778dccf2fbdb79.tar.gz |
Android patch: Fix message2 test setup issue on Android
1. "}" is a special character in regex, and needs to be escaped
on Android.
2. cls.getClassLoader().getResource(packageName) returns null on
Android.
This patch can be upstreamed.
Test: atest CtsIcuTestCases:android.icu.dev.test.message2
Change-Id: I0c3b33bfc9d8dfa192a73a268ca068e1c3a3cf1e
4 files changed, 16 insertions, 24 deletions
diff --git a/android_icu4j/src/main/tests/android/icu/dev/test/message2/SerializationTest.java b/android_icu4j/src/main/tests/android/icu/dev/test/message2/SerializationTest.java index 021b6ffd5..8e1e1b05e 100644 --- a/android_icu4j/src/main/tests/android/icu/dev/test/message2/SerializationTest.java +++ b/android_icu4j/src/main/tests/android/icu/dev/test/message2/SerializationTest.java @@ -102,7 +102,7 @@ public class SerializationTest extends CoreTestFmwk { .replaceAll("\\|([\\d\\.]+)\\|", "$1") // Naive normalization for `|asBaC12|` to `asBaC12` .replaceAll("\\|([a-zA-Z\\d]+)\\|", "$1") - .replaceAll(" }", "}") + .replaceAll(" \\}", "}") .trim(); assertEquals("Serialization different from to the initial source", pattern, parsed); } diff --git a/android_icu4j/src/main/tests/android/icu/dev/test/message2/TestUtils.java b/android_icu4j/src/main/tests/android/icu/dev/test/message2/TestUtils.java index 530579067..c8e024b2c 100644 --- a/android_icu4j/src/main/tests/android/icu/dev/test/message2/TestUtils.java +++ b/android_icu4j/src/main/tests/android/icu/dev/test/message2/TestUtils.java @@ -7,7 +7,10 @@ package android.icu.dev.test.message2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; import java.net.URI; import java.net.URISyntaxException; @@ -130,15 +133,8 @@ public class TestUtils { return unit.toString(); } - static Reader jsonReader(String jsonFileName) throws URISyntaxException, IOException { - Path json = getTestFile(TestUtils.class, jsonFileName); - return Files.newBufferedReader(json, StandardCharsets.UTF_8); + static Reader jsonReader(String jsonFileName) { + InputStream json = TestUtils.class.getResourceAsStream(jsonFileName); + return new BufferedReader(new InputStreamReader(json, StandardCharsets.UTF_8)); } - - private static Path getTestFile(Class<?> cls, String fileName) throws URISyntaxException { - String packageName = cls.getPackage().getName().replace('.', '/'); - URI getPath = cls.getClassLoader().getResource(packageName).toURI(); - Path filePath = Paths.get(getPath); - Path json = Paths.get(fileName); - return filePath.resolve(json); - }} +} diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/SerializationTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/SerializationTest.java index 01e18c586..8c55c195d 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/SerializationTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/SerializationTest.java @@ -99,7 +99,7 @@ public class SerializationTest extends CoreTestFmwk { .replaceAll("\\|([\\d\\.]+)\\|", "$1") // Naive normalization for `|asBaC12|` to `asBaC12` .replaceAll("\\|([a-zA-Z\\d]+)\\|", "$1") - .replaceAll(" }", "}") + .replaceAll(" \\}", "}") .trim(); assertEquals("Serialization different from to the initial source", pattern, parsed); } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/TestUtils.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/TestUtils.java index ae8868d03..e0e4c67ea 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/TestUtils.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/message2/TestUtils.java @@ -6,7 +6,10 @@ package com.ibm.icu.dev.test.message2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; import java.net.URI; import java.net.URISyntaxException; @@ -129,15 +132,8 @@ public class TestUtils { return unit.toString(); } - static Reader jsonReader(String jsonFileName) throws URISyntaxException, IOException { - Path json = getTestFile(TestUtils.class, jsonFileName); - return Files.newBufferedReader(json, StandardCharsets.UTF_8); + static Reader jsonReader(String jsonFileName) { + InputStream json = TestUtils.class.getResourceAsStream(jsonFileName); + return new BufferedReader(new InputStreamReader(json, StandardCharsets.UTF_8)); } - - private static Path getTestFile(Class<?> cls, String fileName) throws URISyntaxException { - String packageName = cls.getPackage().getName().replace('.', '/'); - URI getPath = cls.getClassLoader().getResource(packageName).toURI(); - Path filePath = Paths.get(getPath); - Path json = Paths.get(fileName); - return filePath.resolve(json); - }} +} |