17
17
package org .apache .logging .log4j .message ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
- import static org .junit .jupiter .api .Assertions .assertEquals ;
21
20
22
21
import java .math .BigDecimal ;
23
22
import java .util .stream .Stream ;
27
26
import org .junit .jupiter .params .ParameterizedTest ;
28
27
import org .junit .jupiter .params .provider .MethodSource ;
29
28
30
- /**
31
- *
32
- */
33
29
public class ParameterizedMessageTest {
34
30
35
31
@ Test
36
32
public void testNoArgs () {
37
33
final String testMsg = "Test message {}" ;
38
34
ParameterizedMessage msg = new ParameterizedMessage (testMsg , (Object []) null );
39
35
String result = msg .getFormattedMessage ();
40
- assertEquals ( testMsg , result );
36
+ assertThat ( result ). isEqualTo ( testMsg );
41
37
final Object [] array = null ;
42
38
msg = new ParameterizedMessage (testMsg , array , null );
43
39
result = msg .getFormattedMessage ();
44
- assertEquals ( testMsg , result );
40
+ assertThat ( result ). isEqualTo ( testMsg );
45
41
}
46
42
47
43
@ Test
48
44
public void testZeroLength () {
49
45
final String testMsg = "" ;
50
46
ParameterizedMessage msg = new ParameterizedMessage (testMsg , new Object [] {"arg" });
51
47
String result = msg .getFormattedMessage ();
52
- assertEquals ( testMsg , result );
48
+ assertThat ( result ). isEqualTo ( testMsg );
53
49
final Object [] array = null ;
54
50
msg = new ParameterizedMessage (testMsg , array , null );
55
51
result = msg .getFormattedMessage ();
56
- assertEquals ( testMsg , result );
52
+ assertThat ( result ). isEqualTo ( testMsg );
57
53
}
58
54
59
55
@ Test
60
56
public void testOneCharLength () {
61
57
final String testMsg = "d" ;
62
58
ParameterizedMessage msg = new ParameterizedMessage (testMsg , new Object [] {"arg" });
63
59
String result = msg .getFormattedMessage ();
64
- assertEquals ( testMsg , result );
60
+ assertThat ( result ). isEqualTo ( testMsg );
65
61
final Object [] array = null ;
66
62
msg = new ParameterizedMessage (testMsg , array , null );
67
63
result = msg .getFormattedMessage ();
68
- assertEquals ( testMsg , result );
64
+ assertThat ( result ). isEqualTo ( testMsg );
69
65
}
70
66
71
67
@ Test
72
68
public void testFormat3StringArgs () {
73
69
final String testMsg = "Test message {}{} {}" ;
74
70
final String [] args = {"a" , "b" , "c" };
75
71
final String result = ParameterizedMessage .format (testMsg , args );
76
- assertEquals ( "Test message ab c" , result );
72
+ assertThat ( result ). isEqualTo ( "Test message ab c" );
77
73
}
78
74
79
75
@ Test
80
76
public void testFormatNullArgs () {
81
77
final String testMsg = "Test message {} {} {} {} {} {}" ;
82
78
final String [] args = {"a" , null , "c" , null , null , null };
83
79
final String result = ParameterizedMessage .format (testMsg , args );
84
- assertEquals ( "Test message a null c null null null" , result );
80
+ assertThat ( result ). isEqualTo ( "Test message a null c null null null" );
85
81
}
86
82
87
83
@ Test
88
84
public void testFormatStringArgsIgnoresSuperfluousArgs () {
89
85
final String testMsg = "Test message {}{} {}" ;
90
86
final String [] args = {"a" , "b" , "c" , "unnecessary" , "superfluous" };
91
87
final String result = ParameterizedMessage .format (testMsg , args );
92
- assertEquals ( "Test message ab c" , result );
88
+ assertThat ( result ). isEqualTo ( "Test message ab c" );
93
89
}
94
90
95
91
@ Test
96
92
public void testFormatStringArgsWithEscape () {
97
93
final String testMsg = "Test message \\ {}{} {}" ;
98
94
final String [] args = {"a" , "b" , "c" };
99
95
final String result = ParameterizedMessage .format (testMsg , args );
100
- assertEquals ( "Test message {}a b" , result );
96
+ assertThat ( result ). isEqualTo ( "Test message {}a b" );
101
97
}
102
98
103
99
@ Test
104
100
public void testFormatStringArgsWithTrailingEscape () {
105
101
final String testMsg = "Test message {}{} {}\\ " ;
106
102
final String [] args = {"a" , "b" , "c" };
107
103
final String result = ParameterizedMessage .format (testMsg , args );
108
- assertEquals ( "Test message ab c\\ " , result );
104
+ assertThat ( result ). isEqualTo ( "Test message ab c\\ " );
109
105
}
110
106
111
107
@ Test
112
108
public void testFormatStringArgsWithTrailingText () {
113
109
final String testMsg = "Test message {}{} {}Text" ;
114
110
final String [] args = {"a" , "b" , "c" };
115
111
final String result = ParameterizedMessage .format (testMsg , args );
116
- assertEquals ( "Test message ab cText" , result );
112
+ assertThat ( result ). isEqualTo ( "Test message ab cText" );
117
113
}
118
114
119
115
@ Test
120
116
public void testFormatStringArgsWithTrailingEscapedEscape () {
121
117
final String testMsg = "Test message {}{} {}\\ \\ " ;
122
118
final String [] args = {"a" , "b" , "c" };
123
119
final String result = ParameterizedMessage .format (testMsg , args );
124
- assertEquals ( "Test message ab c\\ " , result );
120
+ assertThat ( result ). isEqualTo ( "Test message ab c\\ " );
125
121
}
126
122
127
123
@ Test
128
124
public void testFormatStringArgsWithEscapedEscape () {
129
125
final String testMsg = "Test message \\ \\ {}{} {}" ;
130
126
final String [] args = {"a" , "b" , "c" };
131
127
final String result = ParameterizedMessage .format (testMsg , args );
132
- assertEquals ( "Test message \\ ab c" , result );
128
+ assertThat ( result ). isEqualTo ( "Test message \\ ab c" );
133
129
}
134
130
135
131
@ Test
@@ -141,12 +137,12 @@ public void testSafeWithMutableParams() { // LOG4J2-763
141
137
// modify parameter before calling msg.getFormattedMessage
142
138
param .set ("XYZ" );
143
139
final String actual = msg .getFormattedMessage ();
144
- assertEquals ( "Test message XYZ" , actual , " Should use current param value" );
140
+ assertThat ( " Should use current param value"). isEqualTo ( "Test message XYZ" , actual );
145
141
146
142
// modify parameter after calling msg.getFormattedMessage
147
143
param .set ("000" );
148
144
final String after = msg .getFormattedMessage ();
149
- assertEquals ( "Test message XYZ" , after , " Should not change after rendered once" );
145
+ assertThat ( " Should not change after rendered once"). isEqualTo ( "Test message XYZ" , after );
150
146
}
151
147
152
148
static Stream <Object > testSerializable () {
0 commit comments