File tree Expand file tree Collapse file tree
core-java-12/src/test/java/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import static org .hamcrest .CoreMatchers .equalTo ;
4+ import static org .hamcrest .MatcherAssert .assertThat ;
5+
6+ import org .junit .Test ;
7+
8+ public class StringAPITest {
9+
10+ @ Test
11+ public void whenPositiveArgument_thenReturnIndentedString () {
12+ String multilineStr = "This is\n a multiline\n string." ;
13+ String outputStr = " This is\n a multiline\n string.\n " ;
14+
15+ String postIndent = multilineStr .indent (3 );
16+
17+ assertThat (outputStr , equalTo (postIndent ));
18+ }
19+
20+ @ Test
21+ public void whenNegativeArgument_thenReturnReducedIndentedString () {
22+ String multilineStr = " This is\n a multiline\n string." ;
23+ String outputStr = " This is\n a multiline\n string.\n " ;
24+
25+ String postIndent = multilineStr .indent (-2 );
26+
27+ assertThat (outputStr , equalTo (postIndent ));
28+ }
29+
30+ @ Test
31+ public void whenTransformUsingLamda_thenReturnTransformedString () {
32+ String result = "hello" .transform (input -> input + " world!" );
33+
34+ assertThat ("hello world!" , equalTo (result ));
35+ }
36+
37+ @ Test
38+ public void whenTransformUsingParseInt_thenReturnInt () {
39+ int result = "42" .transform (Integer ::parseInt );
40+
41+ assertThat (42 , equalTo (result ));
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments