@@ -14,7 +14,8 @@ public class StringFormatterExampleTests {
1414 public void givenString_whenFormatSpecifierForCalendar_thenGotExpected () {
1515 //Syntax of Format Specifiers for Date/Time Representation
1616 Calendar c = new GregorianCalendar (2017 , 11 , 10 );
17- String s = String .format ("The date is: %1$tm %1$te,%1$tY" , c );
17+ String s = String .format ("The date is: %tm %1$te,%1$tY" , c );
18+
1819
1920 assertEquals ("The date is: 12 10,2017" , s );
2021 }
@@ -84,7 +85,7 @@ public void givenString_whenNumericFloatingConversion_thenConvertedString() {
8485 public void givenString_whenLineSeparatorConversion_thenConvertedString () {
8586 //Line Separator Conversion
8687 String s = String .format ("First Line %nSecond Line" );
87- assertEquals ("First Line \n "
88+ assertEquals ("First Line " + System . getProperty ( "line.separator" )
8889 + "Second Line" , s );
8990 }
9091
@@ -114,10 +115,10 @@ public void givenString_whenSpecifyPrecision_thenGotExpected() {
114115 public void givenString_whenSpecifyArgumentIndex_thenGotExpected () {
115116 Calendar c = new GregorianCalendar (2017 , 11 , 10 );
116117 //Argument_Index
117- String s = String .format ("The date is: %1$ tm %1$te,%1$tY" , c );
118+ String s = String .format ("The date is: %tm %1$te,%1$tY" , c );
118119 assertEquals ("The date is: 12 10,2017" , s );
119-
120- s = String .format ("The date is: %1$ tm %<te,%<tY" , c );
120+
121+ s = String .format ("The date is: %tm %<te,%<tY" , c );
121122 assertEquals ("The date is: 12 10,2017" , s );
122123 }
123124
@@ -126,8 +127,7 @@ public void givenAppendable_whenCreateFormatter_thenFormatterWorksOnAppendable()
126127 //Using String Formatter with Appendable
127128 StringBuilder sb = new StringBuilder ();
128129 Formatter formatter = new Formatter (sb );
129- formatter .format ("I am writting to a %1$s Instance." , sb .getClass ());
130-
130+ formatter .format ("I am writting to a %s Instance." , sb .getClass ());
131131 assertEquals ("I am writting to a class java.lang.StringBuilder Instance." , sb .toString ());
132132 }
133133
0 commit comments