From fc227bc128e4d931ae74e07d06f82cfcdb8b59a3 Mon Sep 17 00:00:00 2001 From: Ganesh Pagade Date: Tue, 7 May 2019 10:58:11 +0530 Subject: [PATCH 1/3] Java 12 String API Test --- .../test/java/com/baeldung/StringAPITest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 core-java-12/src/test/java/com/baeldung/StringAPITest.java diff --git a/core-java-12/src/test/java/com/baeldung/StringAPITest.java b/core-java-12/src/test/java/com/baeldung/StringAPITest.java new file mode 100755 index 0000000000..7b68fbb52c --- /dev/null +++ b/core-java-12/src/test/java/com/baeldung/StringAPITest.java @@ -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)); + } +} From ef4fe8c87023091eeb2c1dfd67461799ede9fb9d Mon Sep 17 00:00:00 2001 From: Ganesh Pagade Date: Tue, 7 May 2019 11:12:48 +0530 Subject: [PATCH 2/3] new location for the code --- .../src/test/java/com/baeldung/string}/StringAPITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {core-java-12/src/test/java/com/baeldung => core-java-modules/core-java-12/src/test/java/com/baeldung/string}/StringAPITest.java (97%) mode change 100755 => 100644 diff --git a/core-java-12/src/test/java/com/baeldung/StringAPITest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java old mode 100755 new mode 100644 similarity index 97% rename from core-java-12/src/test/java/com/baeldung/StringAPITest.java rename to core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java index 7b68fbb52c..f26a25ed79 --- a/core-java-12/src/test/java/com/baeldung/StringAPITest.java +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.string; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; From cc4a2639d935e346a2a17a31062d24eeb4250925 Mon Sep 17 00:00:00 2001 From: Ganesh Pagade Date: Sun, 12 May 2019 11:10:07 +0530 Subject: [PATCH 3/3] fix test arg order --- .../src/test/java/com/baeldung/string/StringAPITest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java index f26a25ed79..3d80a36bf6 100644 --- a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java +++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java @@ -14,7 +14,7 @@ public class StringAPITest { String postIndent = multilineStr.indent(3); - assertThat(outputStr, equalTo(postIndent)); + assertThat(postIndent, equalTo(outputStr)); } @Test @@ -24,20 +24,20 @@ public class StringAPITest { String postIndent = multilineStr.indent(-2); - assertThat(outputStr, equalTo(postIndent)); + assertThat(postIndent, equalTo(outputStr)); } @Test public void whenTransformUsingLamda_thenReturnTransformedString() { String result = "hello".transform(input -> input + " world!"); - assertThat("hello world!", equalTo(result)); + assertThat(result, equalTo("hello world!")); } @Test public void whenTransformUsingParseInt_thenReturnInt() { int result = "42".transform(Integer::parseInt); - assertThat(42, equalTo(result)); + assertThat(result, equalTo(42)); } }