forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
core-java-12/src/test/java/com/baeldung/StringAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.baeldung; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class StringAPITest { | ||
|
||
@Test | ||
public void whenPositiveArgument_thenReturnIndentedString() { | ||
String multilineStr = "This is\na multiline\nstring."; | ||
String outputStr = " This is\n a multiline\n string.\n"; | ||
|
||
String postIndent = multilineStr.indent(3); | ||
|
||
assertThat(outputStr, equalTo(postIndent)); | ||
} | ||
|
||
@Test | ||
public void whenNegativeArgument_thenReturnReducedIndentedString() { | ||
String multilineStr = " This is\n a multiline\n string."; | ||
String outputStr = " This is\n a multiline\n string.\n"; | ||
|
||
String postIndent = multilineStr.indent(-2); | ||
|
||
assertThat(outputStr, equalTo(postIndent)); | ||
} | ||
|
||
@Test | ||
public void whenTransformUsingLamda_thenReturnTransformedString() { | ||
String result = "hello".transform(input -> input + " world!"); | ||
|
||
assertThat("hello world!", equalTo(result)); | ||
} | ||
|
||
@Test | ||
public void whenTransformUsingParseInt_thenReturnInt() { | ||
int result = "42".transform(Integer::parseInt); | ||
|
||
assertThat(42, equalTo(result)); | ||
} | ||
} |