Skip to content

Commit 14e07e6

Browse files
authored
Add ICU4J Maven build profile for ICU4J v78 (#542)
1 parent fb73d75 commit 14e07e6

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed

executors/icu4j/74/executor-icu4j/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,36 @@
171171
</plugins>
172172
</build>
173173
</profile>
174+
<profile>
175+
<id>icu78</id>
176+
<dependencies>
177+
<dependency>
178+
<groupId>com.ibm.icu</groupId>
179+
<artifactId>icu4j</artifactId>
180+
<version>78.1</version>
181+
</dependency>
182+
</dependencies>
183+
<build>
184+
<plugins>
185+
<plugin>
186+
<artifactId>maven-surefire-plugin</artifactId>
187+
<configuration>
188+
<includes>
189+
<!-- see: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html -->
190+
<include>**/collator/icu74/*Test.java</include>
191+
<include>**/langnames/icu74/*Test.java</include>
192+
<include>**/likelysubtags/icu74/*Test.java</include>
193+
<include>**/listformatter/icu74/*Test.java</include>
194+
<include>**/messageformat2/icu78/*Test.java</include> <!-- latest MF2 version: ICU 78 -->
195+
<include>**/numberformatter/icu74/*Test.java</include>
196+
<include>**/pluralrules/icu74/*Test.java</include>
197+
<include>**/relativedatetimeformat/icu74/*Test.java</include>
198+
</includes>
199+
</configuration>
200+
</plugin>
201+
</plugins>
202+
</build>
203+
</profile>
174204
</profiles>
175205

176206
<dependencies>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package org.unicode.conformance.messageformat2.icu78;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import com.ibm.icu.util.ULocale;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.Locale;
9+
import java.util.TimeZone;
10+
import org.junit.After;
11+
import org.junit.Before;
12+
import org.junit.Rule;
13+
import org.junit.Test;
14+
import org.junit.rules.TestName;
15+
import org.unicode.conformance.testtype.messageformat2.IMFInputParam;
16+
import org.unicode.conformance.testtype.messageformat2.MFInputParamDatetime;
17+
import org.unicode.conformance.testtype.messageformat2.MFInputParamObject;
18+
import org.unicode.conformance.testtype.messageformat2.MessageFormatInputJson;
19+
import org.unicode.conformance.testtype.messageformat2.MessageFormatTester;
20+
21+
public class MessageFormatterTest {
22+
23+
/**
24+
* The default locale used for all of our tests. Used in @Before
25+
*/
26+
protected final static Locale defaultLocale = Locale.US;
27+
28+
/**
29+
* The default time zone for all of our tests. Used in @Before
30+
*/
31+
protected final static TimeZone defaultTimeZone = TimeZone.getTimeZone("America/Los_Angeles");
32+
33+
private com.ibm.icu.util.TimeZone testStartDefaultIcuTz;
34+
35+
private TimeZone testStartDefaultJdkTz;
36+
37+
private ULocale testStartDefaultULocale;
38+
39+
private Locale testStartDefaultLocale;
40+
41+
@Rule
42+
public TestName name = new TestName();
43+
44+
// Copying test setup behavior from ICU4J CoreTestFmwk / TestFmwk, which
45+
// ensures we pin the default locale and TZ during the test. ICU Formatters
46+
// implicitly use the system's default locale and TZ.
47+
@Before
48+
public final void setup() {
49+
// Just like TestFmwk initializes JDK TimeZone and Locale before every test,
50+
// do the same for ICU TimeZone and ULocale.
51+
ULocale.setDefault(ULocale.forLocale(defaultLocale));
52+
com.ibm.icu.util.TimeZone.setDefault(
53+
com.ibm.icu.util.TimeZone.getTimeZone(defaultTimeZone.getID()));
54+
55+
// Save starting timezones
56+
testStartDefaultIcuTz = com.ibm.icu.util.TimeZone.getDefault();
57+
testStartDefaultJdkTz = TimeZone.getDefault();
58+
59+
// Save starting locales
60+
testStartDefaultULocale = ULocale.getDefault();
61+
testStartDefaultLocale = Locale.getDefault();
62+
}
63+
64+
// Copying test teardown beahvior from ICU4J CoreTestFmwk, corresponding to
65+
// the setup work.
66+
@After
67+
public final void teardown() {
68+
String testMethodName = name.getMethodName();
69+
70+
// Assert that timezones are in a good state
71+
72+
com.ibm.icu.util.TimeZone testEndDefaultIcuTz = com.ibm.icu.util.TimeZone.getDefault();
73+
TimeZone testEndDefaultJdkTz = TimeZone.getDefault();
74+
75+
assertEquals("In [" + testMethodName + "] Test should keep in sync ICU & JDK TZs",
76+
testEndDefaultIcuTz.getID(),
77+
testEndDefaultJdkTz.getID());
78+
79+
assertEquals("In [" + testMethodName + "] Test should reset ICU default TZ",
80+
testStartDefaultIcuTz.getID(), testEndDefaultIcuTz.getID());
81+
assertEquals("In [" + testMethodName + "] Test should reset JDK default TZ",
82+
testStartDefaultJdkTz.getID(), testEndDefaultJdkTz.getID());
83+
84+
// Assert that locales are in a good state
85+
86+
ULocale testEndDefaultULocale = ULocale.getDefault();
87+
Locale testEndDefaultLocale = Locale.getDefault();
88+
89+
assertEquals("In [" + testMethodName + "] Test should reset ICU ULocale",
90+
testStartDefaultULocale.toLanguageTag(), testEndDefaultULocale.toLanguageTag());
91+
assertEquals("In [" + testMethodName + "] Test should reset JDK Locale",
92+
testStartDefaultLocale.toLanguageTag(), testEndDefaultLocale.toLanguageTag());
93+
}
94+
95+
@Test
96+
public void testGetFormattedMessage() {
97+
// Setup
98+
MessageFormatInputJson inputJson = new MessageFormatInputJson();
99+
inputJson.label = "00001";
100+
inputJson.locale = "en-GB";
101+
inputJson.src = "Hello {$name}, your card expires on {$exp :datetime skeleton=yMMMdE}!";
102+
inputJson.test_description = "Test using the ICU4J API doc example for the MessageFormatter class";
103+
List<IMFInputParam> inputs = new ArrayList<>();
104+
MFInputParamObject nameArg = new MFInputParamObject();
105+
nameArg.name = "name";
106+
nameArg.value = "John";
107+
inputs.add(nameArg);
108+
MFInputParamDatetime expArg = new MFInputParamDatetime("exp", "2023-03-27T19:42:51"); // March 27, 2023, 7:42:51 PM
109+
expArg.name = "exp";
110+
inputs.add(expArg);
111+
inputJson.params = inputs;
112+
113+
// Actual
114+
String formattedString = MessageFormatTester.INSTANCE.getFormattedMessage(inputJson);
115+
116+
// Expect & assert test
117+
String expected = "Hello John, your card expires on Mon, 27 Mar 2023, 12:42!";
118+
assertEquals(expected, formattedString);
119+
120+
}
121+
122+
// ICU 75 impl output differs from MF2 spec defined at same time point (CLDR 45)
123+
// in what to return in message for non-provided args / formatting errors
124+
@Test
125+
public void testGetFormattedMessage_usingNonProvidedArg() {
126+
// Setup
127+
MessageFormatInputJson inputJson = new MessageFormatInputJson();
128+
inputJson.label = "00020";
129+
inputJson.locale = "en-US";
130+
inputJson.src = ":date";
131+
inputJson.test_description = "Test of formatting a pattern using an input arg that isn't provided";
132+
List<IMFInputParam> inputs = new ArrayList<>();
133+
inputJson.params = inputs;
134+
135+
// Actual
136+
String formattedString = MessageFormatTester.INSTANCE.getFormattedMessage(inputJson);
137+
138+
// Expect & assert test
139+
String expected = ":date";
140+
assertEquals(expected, formattedString);
141+
}
142+
143+
@Test
144+
public void testGetFormattedMessage_numberLiteralOperand() {
145+
// Setup
146+
MessageFormatInputJson inputJson = new MessageFormatInputJson();
147+
inputJson.label = "00035";
148+
inputJson.locale = "en-US";
149+
inputJson.src = "hello {4.2 :integer}";
150+
inputJson.test_description = "Test of formatting a pattern using an input arg that isn't provided";
151+
List<IMFInputParam> inputs = new ArrayList<>();
152+
inputJson.params = inputs;
153+
154+
// Actual
155+
String formattedString = MessageFormatTester.INSTANCE.getFormattedMessage(inputJson);
156+
157+
// Expect & assert test
158+
String expected = "hello 4";
159+
assertEquals(expected, formattedString);
160+
}
161+
162+
}

run_config.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,5 +736,29 @@
736736
],
737737
"per_execution": 10000
738738
}
739+
},
740+
{
741+
"prereq": {
742+
"name": "mvn-icu4j-78-shaded",
743+
"version": "78",
744+
"command": "mvn -q -P icu78 -f ../executors/icu4j/74/executor-icu4j/pom.xml package"
745+
},
746+
"run": {
747+
"icu_version": "icu78",
748+
"exec": "icu4j",
749+
"test_type": [
750+
"collation",
751+
"datetime_fmt",
752+
"lang_names",
753+
"likely_subtags",
754+
"list_fmt",
755+
"message_fmt2",
756+
"number_fmt",
757+
"plural_rules",
758+
"rdt_fmt",
759+
"segmenter"
760+
],
761+
"per_execution": 10000
762+
}
739763
}
740764
]

0 commit comments

Comments
 (0)