Skip to content

Commit 69613f8

Browse files
mansi2392pedja4
authored andcommitted
BAEL-1237 String Formatter (eugenp#3103)
* Example Code For Evaluation Article This is an example code for the evaluation article on "Different Types of Bean Injection in Spring" * Added unit tests * Minor changes to application context * Removed code committed for evaluation article * BAEL-944 Demonstrating the problems with new Url pattern matching in Spring 5 * BAEL-944 Demonstrating the problems with new Url pattern matching in Spring 5 * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Code Formatting and solving build issue * BAEL-944 Resolving build issue due to change in Spring version * BAEL-944 Resolving build issue * BAEL-944 Formatting code * BAEL-944 Moving tests to correct package * BAEL-944 Moving tests to correct package * BAEL-944 Replacing @RequestMapping by @GetMapping * BAEL-944 Remove unnecessary attribute name, "value" in annotations * BAEL-79 Intro to Activiti with Spring * BAEL-79 Intro to Activiti with Spring * BAEL-79 Adding activiti module to the parent modules * BAEL-79 Using latest version * BAEL-79 Update Spring boot version that works with Activiti * BAEL-79 Replace RequestMapping with GetMapping * BAEL-79 Use Java 8 Syntax * BAEL-79 Formatting * BAEL-79 changed module name * BAEL-378 A Guide to Activiti with Java * BAEL-79 Fixed unit tests * BAEL-79 Simplified the process * BAEL-79 Fix test cases * BAEL-1045 Lambda Behave * BAEL-1045 Lambda Behave * BAEL-1045 Lambda Behave * BAEL-1090 Difference between compact and compressed strings in Java 9 * BAEL-1237 String Formatter * BAEL-1237 String Formatter * BAEL-1237 String Formatter * BAEL-1237 String Formatter * BAEL-1237 Guide to java.util.Formatter * BAEL-1237 String Formatter * BAEL-1237 Using platform dependent line separator in new line test
1 parent 668f1f1 commit 69613f8

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎core-java/src/test/java/com/baeldung/string/formatter/StringFormatterExampleTests.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)