Skip to content

Commit fc227bc

Browse files
committed
Java 12 String API Test
1 parent e4abb5a commit fc227bc

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\na multiline\nstring.";
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+
}

0 commit comments

Comments
 (0)