Skip to content

Commit

Permalink
Merge pull request #3 from eugenp/master
Browse files Browse the repository at this point in the history
Merge updates from eugenp/tutorials
  • Loading branch information
initialcommit-io committed May 17, 2019
2 parents 212b151 + d43790d commit 10f7493
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.baeldung.string;

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(postIndent, equalTo(outputStr));
}

@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(postIndent, equalTo(outputStr));
}

@Test
public void whenTransformUsingLamda_thenReturnTransformedString() {
String result = "hello".transform(input -> input + " world!");

assertThat(result, equalTo("hello world!"));
}

@Test
public void whenTransformUsingParseInt_thenReturnInt() {
int result = "42".transform(Integer::parseInt);

assertThat(result, equalTo(42));
}
}

0 comments on commit 10f7493

Please sign in to comment.