1+ package com .baeldung .java14 .textblocks ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import org .junit .jupiter .api .Test ;
6+
7+ class TextBlocks13UnitTest {
8+ private TextBlocks13 subject = new TextBlocks13 ();
9+
10+ @ Test
11+ void givenAnOldStyleMultilineString_whenComparing_thenEqualsTextBlock () {
12+ String expected = "<html>\n " + "\n " + " <body>\n " + " <p>example text</p>\n " + " </body>\n " + "</html>" ;
13+ assertThat (subject .getBlockOfHtml ()).isEqualTo (expected );
14+ }
15+
16+ @ Test
17+ void givenAnOldStyleString_whenComparing_thenEqualsTextBlock () {
18+ String expected = "<html>\n \n <body>\n <p>example text</p>\n </body>\n </html>" ;
19+ assertThat (subject .getBlockOfHtml ()).isEqualTo (expected );
20+ }
21+
22+ @ Test
23+ void givenAnIndentedString_thenMatchesIndentedOldStyle () {
24+ assertThat (subject .getNonStandardIndent ()).isEqualTo (" Indent\n " );
25+ }
26+
27+ @ Test
28+ void givenAMultilineQuery_thenItCanContainUnescapedQuotes () {
29+ assertThat (subject .getQuery ()).contains ("select \" id\" , \" user\" " );
30+ }
31+
32+ @ Test
33+ void givenAMultilineQuery_thenItEndWithANewline () {
34+ assertThat (subject .getQuery ()).endsWith ("\n " );
35+ }
36+
37+ @ Test
38+ void givenATextWithCarriageReturns_thenItContainsBoth () {
39+ assertThat (subject .getTextWithCarriageReturns ()).isEqualTo ("separated with\r \n carriage returns" );
40+ }
41+
42+ @ Test
43+ void givenAStringWithEscapedWhitespace_thenItAppearsInTheResultingString () {
44+ assertThat (subject .getTextWithEscapes ()).contains ("fun with\n \n " )
45+ .contains ("whitespace\t \r \n " )
46+ .contains ("and other escapes \" \" \" " );
47+ }
48+
49+ @ Test
50+ void givenAFormattedString_thenTheParameterIsReplaced () {
51+ assertThat (subject .getFormattedText ("parameter" )).contains ("Some parameter: parameter" );
52+ }
53+ }
0 commit comments