From e113541042a758878e99ca56e3b97896bc1a2795 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 15 Oct 2017 10:30:35 +0200 Subject: [PATCH 1/5] Update README.md (#2739) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25398d1d39..d94a786bc2 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,4 @@ Any IDE can be used to work with the projects, but if you're using Eclipse, cons CI - Jenkins ================================ -This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/github%20projects%20Jobs/job/tutorials/)** +This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials-unit/)** From 7fd52a69a4b89d48de4a39923f31ce15a4f1c4b6 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 15 Oct 2017 10:30:48 +0200 Subject: [PATCH 2/5] Update README.md (#2738) --- ethereumj/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereumj/README.md b/ethereumj/README.md index 54da91b4f7..d2e2753438 100644 --- a/ethereumj/README.md +++ b/ethereumj/README.md @@ -1,4 +1,4 @@ ## EthereumJ ### Relevant Articles: -- [Introduction to EthereumJ](http://www.baeldung.com/intro-to-ethereumj) \ No newline at end of file +- [Introduction to EthereumJ](http://www.baeldung.com/ethereumj) From b6451199e7788da9100f74c71446c1edcd1466a8 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 15 Oct 2017 10:31:00 +0200 Subject: [PATCH 3/5] Update README.md (#2737) --- libraries/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/README.md b/libraries/README.md index 7214cd278c..b400b1a772 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -39,7 +39,6 @@ - [Introduction to Apache Commons CSV](http://www.baeldung.com/apache-commons-csv) - [Difference Between Two Dates in Java](http://www.baeldung.com/java-date-difference) - [Introduction to NoException](http://www.baeldung.com/no-exception) -- [Introduction to FunctionalJava](http://www.baeldung.com/functional-java) - [Apache Commons IO](http://www.baeldung.com/apache-commons-io) - [Introduction to Conflict-Free Replicated Data Types](http://www.baeldung.com/java-conflict-free-replicated-data-types) From cccd72d451163bb31fd1047f52802d318234ad52 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 15 Oct 2017 10:31:13 +0200 Subject: [PATCH 4/5] Update README.md (#2736) --- algorithms/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms/README.md b/algorithms/README.md index 8cf4c35b68..011e4b51f2 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -3,7 +3,7 @@ - [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra) - [Introduction to Cobertura](http://www.baeldung.com/cobertura) - [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization) -- [Validating Input With Finite Automata in Java](http://www.baeldung.com/finite-automata-java) +- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata) - [Introduction to Jenetics Library](http://www.baeldung.com/jenetics) - [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers) - [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm) From b85bb1ae1ef8463444aa1e571520203ff4fba4c7 Mon Sep 17 00:00:00 2001 From: Ahmed Tawila Date: Sun, 15 Oct 2017 10:31:46 +0200 Subject: [PATCH 5/5] BAEL-1171 java.lang.String API (#2732) * Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup * BAEL-1109 Introduction to JCache * BAEL-1109 Introduction to JCache * remove unneeded property in pom.xml * fix formatting * close cache instances properly * remove latest commit * BAEL-1057 Introduction to rxjava-jdbc * refactor rxjava-jdbc * Refactor rxjava-jdbc * Refactoring rxjava-jdbc * BAEL-1171 java.lang.String API * refactor rxjava-jdbc * refactor String * String API - move multiple classes into a single class * move class into test package * BAEL-1171 String.lang.String API --- .../java/com/baeldung/string/StringTest.java | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/core-java/src/test/java/com/baeldung/string/StringTest.java b/core-java/src/test/java/com/baeldung/string/StringTest.java index fd83c903a3..324f4690fc 100644 --- a/core-java/src/test/java/com/baeldung/string/StringTest.java +++ b/core-java/src/test/java/com/baeldung/string/StringTest.java @@ -2,6 +2,13 @@ package com.baeldung.string; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.IllegalFormatException; +import java.util.regex.PatternSyntaxException; import org.junit.Test; @@ -12,6 +19,11 @@ public class StringTest { assertEquals(97, "abcd".codePointAt(0)); } + @Test(expected = StringIndexOutOfBoundsException.class) + public void whenPassNonExistingIndex_thenExceptionThrown() { + int a = "abcd".codePointAt(4); + } + @Test public void whenCallConcat_thenCorrect() { assertEquals("elephant", "elep".concat("hant")); @@ -21,6 +33,180 @@ public class StringTest { public void whenGetBytes_thenCorrect() { byte[] byteArray = "abcd".getBytes(); byte[] expected = new byte[] { 97, 98, 99, 100 }; + assertArrayEquals(expected, byteArray); } + + @Test + public void whenGetBytesUsingUTF16_thenCorrect() { + byte[] byteArray = "efgh".getBytes(StandardCharsets.US_ASCII); + byte[] expected = new byte[] { 101, 102, 103, 104 }; + + assertArrayEquals(expected, byteArray); + } + + @Test + public void whenCreateStringUsingByteArray_thenCorrect() { + byte[] array = new byte[] { 97, 98, 99, 100 }; + String s = new String(array); + + assertEquals("abcd", s); + } + + @Test + public void whenCallCharAt_thenCorrect() { + assertEquals('P', "Paul".charAt(0)); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void whenCharAtOnNonExistingIndex_thenIndexOutOfBoundsExceptionThrown() { + char character = "Paul".charAt(4); + } + + @Test + public void whenCallCodePointCount_thenCorrect() { + assertEquals(2, "abcd".codePointCount(0, 2)); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void whenSecondIndexEqualToLengthOfString_thenIndexOutOfBoundsExceptionThrown() { + char character = "Paul".charAt(4); + } + + @Test + public void whenCallContains_thenCorrect() { + String s = "abcd"; + + assertTrue(s.contains("abc")); + assertFalse(s.contains("cde")); + } + + @Test + public void whenCallCopyValueOf_thenStringConstructed() { + char[] array = new char[] { 'a', 'b', 'c', 'd' }; + + assertEquals("abcd", String.copyValueOf(array)); + } + + @Test + public void whenCallEndsWith_thenCorrect() { + String s1 = "test"; + + assertTrue(s1.endsWith("t")); + } + + @Test + public void whenFormat_thenCorrect() { + String value = "Baeldung"; + String formatted = String.format("Welcome to %s!", value); + + assertEquals("Welcome to Baeldung!", formatted); + } + + @Test(expected = IllegalFormatException.class) + public void whenInvalidFormatSyntax_thenIllegalFormatExceptionThrown() { + String value = "Baeldung"; + String formatted = String.format("Welcome to %x!", value); + } + + @Test + public void whenCallIndexOf_thenCorrect() { + assertEquals(1, "foo".indexOf("o")); + } + + @Test + public void whenCallIsEmpty_thenCorrect() { + String s1 = ""; + + assertTrue(s1.isEmpty()); + } + + @Test + public void whenCallLastIndexOf_thenCorrect() { + assertEquals(2, "foo".lastIndexOf("o")); + } + + @Test + public void whenCallRegionMatches_thenCorrect() { + assertTrue("welcome to baeldung".regionMatches(false, 11, "baeldung", 0, 8)); + } + + @Test + public void whenCallStartsWith_thenCorrect() { + assertTrue("foo".startsWith("f")); + } + + @Test + public void whenTrim_thenCorrect() { + assertEquals("foo", " foo ".trim()); + } + + @Test + public void whenSplit_thenCorrect() { + String s = "Welcome to Baeldung"; + String[] array = new String[] { "Welcome", "to", "Baeldung" }; + + assertArrayEquals(array, s.split(" ")); + } + + @Test(expected = PatternSyntaxException.class) + public void whenPassInvalidParameterToSplit_thenPatternSyntaxExceptionThrown() { + String s = "Welcome*to Baeldung"; + + String[] result = s.split("*"); + } + + @Test + public void whenCallSubstring_thenCorrect() { + String s = "Welcome to Baeldung"; + + assertEquals("Welcome", s.substring(0, 7)); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void whenSecondIndexEqualToLengthOfString_thenCorrect() { + String s = "Welcome to Baeldung"; + + String sub = s.substring(0, 20); + } + + @Test + public void whenConvertToUpperCase_thenCorrect() { + String s = "Welcome to Baeldung!"; + + assertEquals("WELCOME TO BAELDUNG!", s.toUpperCase()); + } + + @Test + public void whenConvertToLowerCase_thenCorrect() { + String s = "WELCOME to BAELDUNG!"; + + assertEquals("welcome to baeldung!", s.toLowerCase()); + } + + @Test + public void whenCallReplace_thenCorrect() { + String s = "I learn Spanish"; + + assertEquals("I learn French", s.replaceAll("Spanish", "French")); + } + + @Test + public void whenIntern_thenCorrect() { + String s1 = "abc"; + String s2 = new String("abc"); + String s3 = new String("foo"); + String s4 = s1.intern(); + String s5 = s2.intern(); + + assertFalse(s3 == s4); + assertTrue(s1 == s5); + } + + @Test + public void whenCallValueOf_thenCorrect() { + long l = 200L; + + assertEquals("200", String.valueOf(l)); + } }