37
37
import org .springframework .util .StringUtils ;
38
38
import org .springframework .web .reactive .result .view .DummyMacroRequestContext ;
39
39
40
- import static org .junit .Assert .assertEquals ;
41
- import static org .junit .Assert .assertNotNull ;
42
- import static org .junit .Assert .assertTrue ;
40
+ import static org .assertj .core .api .Assertions .assertThat ;
43
41
44
42
/**
45
43
* @author Darren Davison
@@ -62,127 +60,122 @@ public void setUp() throws Exception {
62
60
63
61
@ Test
64
62
public void testName () throws Exception {
65
- assertEquals ( "Darren" , getMacroOutput ("NAME" ));
63
+ assertThat ( getMacroOutput ("NAME" )). isEqualTo ( "Darren" );
66
64
}
67
65
68
66
@ Test
69
67
public void testAge () throws Exception {
70
- assertEquals ( "99" , getMacroOutput ("AGE" ));
68
+ assertThat ( getMacroOutput ("AGE" )). isEqualTo ( "99" );
71
69
}
72
70
73
71
@ Test
74
72
public void testMessage () throws Exception {
75
- assertEquals ( "Howdy Mundo" , getMacroOutput ("MESSAGE" ));
73
+ assertThat ( getMacroOutput ("MESSAGE" )). isEqualTo ( "Howdy Mundo" );
76
74
}
77
75
78
76
@ Test
79
77
public void testDefaultMessage () throws Exception {
80
- assertEquals ( "hi planet" , getMacroOutput ("DEFAULTMESSAGE" ));
78
+ assertThat ( getMacroOutput ("DEFAULTMESSAGE" )). isEqualTo ( "hi planet" );
81
79
}
82
80
83
81
@ Test
84
82
public void testMessageArgs () throws Exception {
85
- assertEquals ( "Howdy[World]" , getMacroOutput ("MESSAGEARGS" ));
83
+ assertThat ( getMacroOutput ("MESSAGEARGS" )). isEqualTo ( "Howdy[World]" );
86
84
}
87
85
88
86
@ Test
89
87
public void testMessageArgsWithDefaultMessage () throws Exception {
90
- assertEquals ( "Hi" , getMacroOutput ("MESSAGEARGSWITHDEFAULTMESSAGE" ));
88
+ assertThat ( getMacroOutput ("MESSAGEARGSWITHDEFAULTMESSAGE" )). isEqualTo ( "Hi" );
91
89
}
92
90
93
91
@ Test
94
92
public void testUrl () throws Exception {
95
- assertEquals ( " /springtest/aftercontext.html", getMacroOutput ( "URL" ) );
93
+ assertThat ( getMacroOutput ( "URL" )). isEqualTo ( " /springtest/aftercontext.html" );
96
94
}
97
95
98
96
@ Test
99
97
public void testUrlParams () throws Exception {
100
- assertEquals ( " /springtest/aftercontext/bar?spam=bucket", getMacroOutput ( "URLPARAMS" ) );
98
+ assertThat ( getMacroOutput ( "URLPARAMS" )). isEqualTo ( " /springtest/aftercontext/bar?spam=bucket" );
101
99
}
102
100
103
101
@ Test
104
102
public void testForm1 () throws Exception {
105
- assertEquals ( " <input type=\" text\" id=\" name\" name=\" name\" value=\" Darren\" >", getMacroOutput ( "FORM1" ) );
103
+ assertThat ( getMacroOutput ( "FORM1" )). isEqualTo ( " <input type=\" text\" id=\" name\" name=\" name\" value=\" Darren\" >" );
106
104
}
107
105
108
106
@ Test
109
107
public void testForm2 () throws Exception {
110
- assertEquals ("<input type=\" text\" id=\" name\" name=\" name\" value=\" Darren\" class=\" myCssClass\" >" ,
111
- getMacroOutput ("FORM2" ));
108
+ assertThat (getMacroOutput ("FORM2" )).isEqualTo ("<input type=\" text\" id=\" name\" name=\" name\" value=\" Darren\" class=\" myCssClass\" >" );
112
109
}
113
110
114
111
@ Test
115
112
public void testForm3 () throws Exception {
116
- assertEquals ( " <textarea id=\" name\" name=\" name\" >\n Darren</textarea>", getMacroOutput ( "FORM3" ) );
113
+ assertThat ( getMacroOutput ( "FORM3" )). isEqualTo ( " <textarea id=\" name\" name=\" name\" >\n Darren</textarea>" );
117
114
}
118
115
119
116
@ Test
120
117
public void testForm4 () throws Exception {
121
- assertEquals ( " <textarea id=\" name\" name=\" name\" rows=10 cols=30>\n Darren</textarea>", getMacroOutput ( "FORM4" ) );
118
+ assertThat ( getMacroOutput ( "FORM4" )). isEqualTo ( " <textarea id=\" name\" name=\" name\" rows=10 cols=30>\n Darren</textarea>" );
122
119
}
123
120
124
121
@ Test
125
122
public void testForm9 () throws Exception {
126
- assertEquals ( " <input type=\" password\" id=\" name\" name=\" name\" value=\" \" >", getMacroOutput ( "FORM9" ) );
123
+ assertThat ( getMacroOutput ( "FORM9" )). isEqualTo ( " <input type=\" password\" id=\" name\" name=\" name\" value=\" \" >" );
127
124
}
128
125
129
126
@ Test
130
127
public void testForm10 () throws Exception {
131
- assertEquals ("<input type=\" hidden\" id=\" name\" name=\" name\" value=\" Darren\" >" ,
132
- getMacroOutput ("FORM10" ));
128
+ assertThat (getMacroOutput ("FORM10" )).isEqualTo ("<input type=\" hidden\" id=\" name\" name=\" name\" value=\" Darren\" >" );
133
129
}
134
130
135
131
@ Test
136
132
public void testForm11 () throws Exception {
137
- assertEquals ( " <input type=\" text\" id=\" name\" name=\" name\" value=\" Darren\" >", getMacroOutput ( "FORM11" ) );
133
+ assertThat ( getMacroOutput ( "FORM11" )). isEqualTo ( " <input type=\" text\" id=\" name\" name=\" name\" value=\" Darren\" >" );
138
134
}
139
135
140
136
@ Test
141
137
public void testForm12 () throws Exception {
142
- assertEquals ("<input type=\" hidden\" id=\" name\" name=\" name\" value=\" Darren\" >" ,
143
- getMacroOutput ("FORM12" ));
138
+ assertThat (getMacroOutput ("FORM12" )).isEqualTo ("<input type=\" hidden\" id=\" name\" name=\" name\" value=\" Darren\" >" );
144
139
}
145
140
146
141
@ Test
147
142
public void testForm13 () throws Exception {
148
- assertEquals ( " <input type=\" password\" id=\" name\" name=\" name\" value=\" \" >", getMacroOutput ( "FORM13" ) );
143
+ assertThat ( getMacroOutput ( "FORM13" )). isEqualTo ( " <input type=\" password\" id=\" name\" name=\" name\" value=\" \" >" );
149
144
}
150
145
151
146
@ Test
152
147
public void testForm15 () throws Exception {
153
148
String output = getMacroOutput ("FORM15" );
154
- assertTrue ( "Wrong output: " + output , output .startsWith ("<input type=\" hidden\" name=\" _name\" value=\" on\" />" ));
155
- assertTrue ( "Wrong output: " + output , output .contains ("<input type=\" checkbox\" id=\" name\" name=\" name\" />" ));
149
+ assertThat ( output .startsWith ("<input type=\" hidden\" name=\" _name\" value=\" on\" />" )). as ( "Wrong output: " + output ). isTrue ( );
150
+ assertThat ( output .contains ("<input type=\" checkbox\" id=\" name\" name=\" name\" />" )). as ( "Wrong output: " + output ). isTrue ( );
156
151
}
157
152
158
153
@ Test
159
154
public void testForm16 () throws Exception {
160
155
String output = getMacroOutput ("FORM16" );
161
- assertTrue ( "Wrong output: " + output , output .startsWith (
162
- "<input type=\" hidden\" name=\" _jedi\" value=\" on\" />" ));
163
- assertTrue ( "Wrong output: " + output , output .contains (
164
- "<input type=\" checkbox\" id=\" jedi\" name=\" jedi\" checked=\" checked\" />" ));
156
+ assertThat ( output .startsWith (
157
+ "<input type=\" hidden\" name=\" _jedi\" value=\" on\" />" )). as ( "Wrong output: " + output ). isTrue () ;
158
+ assertThat ( output .contains (
159
+ "<input type=\" checkbox\" id=\" jedi\" name=\" jedi\" checked=\" checked\" />" )). as ( "Wrong output: " + output ). isTrue () ;
165
160
}
166
161
167
162
@ Test
168
163
public void testForm17 () throws Exception {
169
- assertEquals (
170
- "<input type=\" text\" id=\" spouses0.name\" name=\" spouses[0].name\" value=\" Fred\" >" ,
171
- getMacroOutput ("FORM17" ));
164
+ assertThat (getMacroOutput ("FORM17" )).isEqualTo ("<input type=\" text\" id=\" spouses0.name\" name=\" spouses[0].name\" value=\" Fred\" >" );
172
165
}
173
166
174
167
@ Test
175
168
public void testForm18 () throws Exception {
176
169
String output = getMacroOutput ("FORM18" );
177
- assertTrue ( "Wrong output: " + output , output .startsWith (
178
- "<input type=\" hidden\" name=\" _spouses[0].jedi\" value=\" on\" />" ));
179
- assertTrue ( "Wrong output: " + output , output .contains (
180
- "<input type=\" checkbox\" id=\" spouses0.jedi\" name=\" spouses[0].jedi\" checked=\" checked\" />" ));
170
+ assertThat ( output .startsWith (
171
+ "<input type=\" hidden\" name=\" _spouses[0].jedi\" value=\" on\" />" )). as ( "Wrong output: " + output ). isTrue () ;
172
+ assertThat ( output .contains (
173
+ "<input type=\" checkbox\" id=\" spouses0.jedi\" name=\" spouses[0].jedi\" checked=\" checked\" />" )). as ( "Wrong output: " + output ). isTrue () ;
181
174
}
182
175
183
176
private String getMacroOutput (String name ) throws Exception {
184
177
String macro = fetchMacro (name );
185
- assertNotNull (macro );
178
+ assertThat (macro ). isNotNull ( );
186
179
187
180
FileSystemResource resource = new FileSystemResource (System .getProperty ("java.io.tmpdir" ) + "/tmp.ftl" );
188
181
FileCopyUtils .copy ("<#import \" spring.ftl\" as spring />\n " + macro , new FileWriter (resource .getPath ()));
@@ -230,7 +223,7 @@ private String getMacroOutput(String name) throws Exception {
230
223
231
224
private String fetchMacro (String name ) throws Exception {
232
225
ClassPathResource resource = new ClassPathResource ("test-macro.ftl" , getClass ());
233
- assertTrue (resource .exists ());
226
+ assertThat (resource .exists ()). isTrue ( );
234
227
String all = FileCopyUtils .copyToString (new InputStreamReader (resource .getInputStream ()));
235
228
all = all .replace ("\r \n " , "\n " );
236
229
String [] macros = StringUtils .delimitedListToStringArray (all , "\n \n " );
0 commit comments