Skip to content

Commit 8d7518b

Browse files
committed
Fix MessageFormatMessageTest on JDK 17
The whitespace used to print numbers changed between JDK 11 and JDK 17.
1 parent 92b8810 commit 8d7518b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

log4j-api-test/src/test/java/org/apache/logging/log4j/message/MessageFormatMessageTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@
2020

2121
import org.apache.logging.log4j.test.junit.Mutable;
2222
import org.apache.logging.log4j.util.Constants;
23+
import org.assertj.core.presentation.UnicodeRepresentation;
2324
import org.junit.jupiter.api.Test;
2425
import org.junit.jupiter.api.parallel.ResourceAccessMode;
2526
import org.junit.jupiter.api.parallel.ResourceLock;
2627
import org.junit.jupiter.api.parallel.Resources;
2728

28-
import static org.junit.jupiter.api.Assertions.*;
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
31+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2932

3033
@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
3134
public class MessageFormatMessageTest {
3235

33-
private static final String SPACE = Constants.JAVA_MAJOR_VERSION < 9 ? " " : "\u00a0";
36+
private static final char SPACE = ' ';
37+
private static final char NB_SPACE = '\u00a0';
38+
private static final char NARROW_NB_SPACE = '\u202f';
3439

3540
private static final int LOOP_CNT = 500;
3641
String[] array = new String[LOOP_CNT];
@@ -72,8 +77,10 @@ public void testOneIntArgLocaleFrance() {
7277
final String testMsg = "Test message {0,number,currency}";
7378
final MessageFormatMessage msg = new MessageFormatMessage(Locale.FRANCE, testMsg, 1234567890);
7479
final String result = msg.getFormattedMessage();
75-
final String expected = "Test message 1 234 567 890,00" + SPACE + "€";
76-
assertEquals(expected, result);
80+
final char separator = Constants.JAVA_MAJOR_VERSION < 9 ? SPACE : NB_SPACE;
81+
final char groupingSeparator = Constants.JAVA_MAJOR_VERSION < 17 ? NB_SPACE : NARROW_NB_SPACE;
82+
assertThat(result).withRepresentation(UnicodeRepresentation.UNICODE_REPRESENTATION)
83+
.isEqualTo("Test message 1%1$c234%1$c567%1$c890,00%2$c€", groupingSeparator, separator);
7784
}
7885

7986
@Test

0 commit comments

Comments
 (0)