1313 */
1414package com .github .jknack .handlebars ;
1515
16- import static org .junit .Assert .assertEquals ;
16+ import static com .github .jknack .handlebars .IgnoreWindowsLineMatcher .equalsToStringIgnoringWindowsNewLine ;
17+ import static org .hamcrest .MatcherAssert .assertThat ;
1718
1819import java .io .IOException ;
1920import java .util .HashMap ;
@@ -40,10 +41,8 @@ public void toJSON() throws IOException {
4041
4142 Template template = handlebars .compileInline ("{{@json this}}" );
4243
43- CharSequence result = template .apply (new Blog ("First Post" , "..." ));
44-
45- assertEquals ("{\" title\" :\" First Post\" ,\" body\" :\" ...\" ,\" comments\" :[]}" ,
46- result );
44+ assertThat (template .apply (new Blog ("First Post" , "..." )), equalsToStringIgnoringWindowsNewLine (
45+ "{\" title\" :\" First Post\" ,\" body\" :\" ...\" ,\" comments\" :[]}" ));
4746 }
4847
4948 @ Test
@@ -53,14 +52,12 @@ public void toPrettyJSON() throws IOException {
5352
5453 Template template = handlebars .compileInline ("{{@json this pretty=true}}" );
5554
56- CharSequence result = template .apply (new Blog ("First Post" , "..." ));
57-
58- assertEquals ("{\n " +
59- " \" title\" : \" First Post\" ,\n " +
60- " \" body\" : \" ...\" ,\n " +
61- " \" comments\" : [ ]\n " +
62- "}" ,
63- result );
55+ assertThat (template .apply (new Blog ("First Post" , "..." )),
56+ equalsToStringIgnoringWindowsNewLine ("{\n " +
57+ " \" title\" : \" First Post\" ,\n " +
58+ " \" body\" : \" ...\" ,\n " +
59+ " \" comments\" : [ ]\n " +
60+ "}" ));
6461 }
6562
6663 @ Test
@@ -71,12 +68,12 @@ public void toJSONViewInclusive() throws IOException {
7168
7269 Template template =
7370 handlebars
74- .compileInline ("{{@json this view=\" com.github.jknack.handlebars.Blog$Views$Public\" }}" );
75-
76- CharSequence result = template .apply (new Blog ("First Post" , "..." ));
71+ .compileInline (
72+ "{{@json this view=\" com.github.jknack.handlebars.Blog$Views$Public\" }}" );
7773
78- assertEquals ("{\" title\" :\" First Post\" ,\" body\" :\" ...\" ,\" comments\" :[]}" ,
79- result );
74+ assertThat (template .apply (new Blog ("First Post" , "..." )),
75+ equalsToStringIgnoringWindowsNewLine (
76+ "{\" title\" :\" First Post\" ,\" body\" :\" ...\" ,\" comments\" :[]}" ));
8077 }
8178
8279 @ Test
@@ -90,11 +87,11 @@ public void toJSONViewExclusive() throws IOException {
9087
9188 Template template =
9289 handlebars
93- .compileInline ("{{@json this view=\" com.github.jknack.handlebars.Blog$Views$Public\" }}" );
90+ .compileInline (
91+ "{{@json this view=\" com.github.jknack.handlebars.Blog$Views$Public\" }}" );
9492
95- CharSequence result = template .apply (new Blog ("First Post" , "..." ));
96-
97- assertEquals ("{\" title\" :\" First Post\" }" , result );
93+ assertThat (template .apply (new Blog ("First Post" , "..." )),
94+ equalsToStringIgnoringWindowsNewLine ("{\" title\" :\" First Post\" }" ));
9895 }
9996
10097 @ Test
@@ -111,9 +108,8 @@ public void toJSONAliasViewExclusive() throws IOException {
111108 handlebars
112109 .compileInline ("{{@json this view=\" myView\" }}" );
113110
114- CharSequence result = template .apply (new Blog ("First Post" , "..." ));
115-
116- assertEquals ("{\" title\" :\" First Post\" }" , result );
111+ assertThat (template .apply (new Blog ("First Post" , "..." )),
112+ equalsToStringIgnoringWindowsNewLine ("{\" title\" :\" First Post\" }" ));
117113 }
118114
119115 @ Test (expected = HandlebarsException .class )
@@ -129,9 +125,8 @@ public void jsonViewNotFound() throws IOException {
129125 handlebars
130126 .compileInline ("{{@json this view=\" missing.ViewClass\" }}" );
131127
132- CharSequence result = template .apply (new Blog ("First Post" , "..." ));
133-
134- assertEquals ("{\" title\" :\" First Post\" }" , result );
128+ assertThat (template .apply (new Blog ("First Post" , "..." )),
129+ equalsToStringIgnoringWindowsNewLine ("{\" title\" :\" First Post\" }" ));
135130 }
136131
137132 @ Test
@@ -142,11 +137,12 @@ public void escapeHtml() throws IOException {
142137 Map <String , String > model = new HashMap <String , String >();
143138 model .put ("script" , "<script text=\" text/javascript\" ></script>" );
144139
145- assertEquals ("{\" script\" :\" <script text=\\ \" text/javascript\\ \" ></script>\" }" , handlebars
146- .compileInline ("{{@json this}}" ).apply (model ));
140+ assertThat (handlebars
141+ .compileInline ("{{@json this}}" ).apply (model ), equalsToStringIgnoringWindowsNewLine (
142+ "{\" script\" :\" <script text=\\ \" text/javascript\\ \" ></script>\" }" ));
147143
148- assertEquals (
149- "{ \" script \" : \" \\ u003Cscript text= \\ \" text/javascript \\ \" \\ u003E \\ u003C/script \\ u003E \" }" ,
150- handlebars . compileInline ( "{{@json this escapeHTML=true}}" ). apply ( model ));
144+ assertThat ( handlebars . compileInline ( "{{@json this escapeHTML=true}}" ). apply ( model ),
145+ equalsToStringIgnoringWindowsNewLine (
146+ "{ \" script \" : \" \\ u003Cscript text= \\ \" text/javascript \\ \" \\ u003E \\ u003C/script \\ u003E \" }" ));
151147 }
152148}
0 commit comments