66
77import com .jcabi .xml .XML ;
88import java .util .AbstractMap ;
9+ import java .util .ArrayList ;
910import java .util .Collection ;
10- import java .util .LinkedList ;
1111import java .util .Map ;
1212import org .hamcrest .BaseMatcher ;
1313import org .hamcrest .Description ;
1616
1717/**
1818 * Hamcrest matcher for a YAML story.
19- *
2019 * @since 0.1.0
2120 */
22- @ SuppressWarnings ("PMD.ConstructorShouldDoInitialization" )
2321public final class XtoryMatcher extends BaseMatcher <Xtory > {
2422
2523 /**
@@ -79,7 +77,7 @@ public boolean matches(final Object object) {
7977 Assumptions .assumeTrue (xtory .map ().get ("skip" ) == null );
8078 final XML after = xtory .xsline ().pass (xtory .before ());
8179 final Collection <Map .Entry <String , Boolean >> xpaths =
82- new LinkedList <>();
80+ new ArrayList <>(0 );
8381 int failures = 0 ;
8482 for (final String xpath : xtory .asserts ()) {
8583 final boolean success = !after .nodes (xpath ).isEmpty ();
@@ -92,28 +90,35 @@ public boolean matches(final Object object) {
9290 "All %d XPath expressions matched" ,
9391 xpaths .size ()
9492 );
95- final StringBuilder sum = new StringBuilder (1024 )
96- .append (String .format ("%d XPath expression(s) failed:\n " , failures ));
93+ final StringBuilder sum = new StringBuilder (1024 ).append (
94+ String .format ("%d XPath expression(s) failed:%n" , failures )
95+ );
9796 for (final Map .Entry <String , Boolean > ent : xpaths ) {
9897 sum .append (" " );
9998 if (ent .getValue ()) {
10099 sum .append ("OK" );
101100 } else {
102101 sum .append ("FAIL" );
103102 }
104- sum .append (": " ).append (ent .getKey ()).append ('\n' );
103+ sum .append (": " ).append (ent .getKey ()).append (System . lineSeparator () );
105104 }
106- sum
107- .append ("\n XML before XSL transformation:\n " )
108- .append (xtory .before ().toString ().replace ("\n " , "\n " ))
109- .append (
110- String .format (
111- "\n XML after XSL transformation (%d->%d chars):\n " ,
112- xtory .before ().toString ().length (),
113- after .toString ().length ()
114- )
105+ sum .append (
106+ String .format ("%nXML before XSL transformation:%n " )
107+ ).append (
108+ xtory .before ().toString ().replace (
109+ System .lineSeparator (), String .format ("%n " )
110+ )
111+ ).append (
112+ String .format (
113+ "%nXML after XSL transformation (%d->%d chars):%n " ,
114+ xtory .before ().toString ().length (),
115+ after .toString ().length ()
116+ )
117+ ).append (
118+ after .toString ().replace (
119+ System .lineSeparator (), String .format ("%n " )
115120 )
116- . append ( after . toString (). replace ( " \n " , " \n " ) );
121+ );
117122 this .summary = sum .toString ();
118123 this .match = true ;
119124 for (final Map .Entry <String , Boolean > ent : xpaths ) {
@@ -139,8 +144,7 @@ public void describeMismatch(final Object story, final Description desc) {
139144 if (this .match ) {
140145 this .extra .describeMismatch (story , desc );
141146 } else {
142- desc .appendText (" \n " ).appendText (this .summary );
147+ desc .appendText (System . lineSeparator () ).appendText (this .summary );
143148 }
144149 }
145-
146150}
0 commit comments