From 9e273b14741b2626f91fea9dcac186c319edc9ea Mon Sep 17 00:00:00 2001 From: Ahmed Tawila Date: Sun, 8 Oct 2017 11:55:55 +0200 Subject: [PATCH] BAEL-1171 java.lang.String API (#2693) * 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 --- .../java/com/baeldung/string/StringTest.java | 26 ++++++++++++++++ .../jdbc/AutomapClassIntegrationTest.java | 6 ++-- .../jdbc/AutomapInterfaceIntegrationTest.java | 9 +++--- .../jdbc/BasicQueryTypesIntegrationTest.java | 30 ++++++++++-------- .../jdbc/InsertBlobIntegrationTest.java | 22 +++++++------ .../jdbc/InsertClobIntegrationTest.java | 20 +++++++----- .../jdbc/ReturnKeysIntegrationTest.java | 31 +++++++++++-------- .../jdbc/TransactionIntegrationTest.java | 23 +++++++++----- 8 files changed, 110 insertions(+), 57 deletions(-) create mode 100644 core-java/src/test/java/com/baeldung/string/StringTest.java diff --git a/core-java/src/test/java/com/baeldung/string/StringTest.java b/core-java/src/test/java/com/baeldung/string/StringTest.java new file mode 100644 index 0000000000..fd83c903a3 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/string/StringTest.java @@ -0,0 +1,26 @@ +package com.baeldung.string; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class StringTest { + + @Test + public void whenCallCodePointAt_thenDecimalUnicodeReturned() { + assertEquals(97, "abcd".codePointAt(0)); + } + + @Test + public void whenCallConcat_thenCorrect() { + assertEquals("elephant", "elep".concat("hant")); + } + + @Test + public void whenGetBytes_thenCorrect() { + byte[] byteArray = "abcd".getBytes(); + byte[] expected = new byte[] { 97, 98, 99, 100 }; + assertArrayEquals(expected, byteArray); + } +} diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java index 51e163db1f..957b6a4543 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java @@ -8,13 +8,15 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import com.github.davidmoten.rx.jdbc.ConnectionProvider; import com.github.davidmoten.rx.jdbc.Database; import rx.Observable; public class AutomapClassIntegrationTest { - private Database db = Database.from(Connector.connectionProvider); + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); private Observable create = null; private Observable insert1, insert2 = null; @@ -56,6 +58,6 @@ public class AutomapClassIntegrationTest { public void close() { db.update("DROP TABLE MANAGER") .dependsOn(create); - Connector.connectionProvider.close(); + connectionProvider.close(); } } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java index f1182952b1..477a2a1cb8 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java @@ -8,13 +8,15 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import com.github.davidmoten.rx.jdbc.ConnectionProvider; import com.github.davidmoten.rx.jdbc.Database; import rx.Observable; public class AutomapInterfaceIntegrationTest { - private Database db = Database.from(Connector.connectionProvider); + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); private Observable create = null; private Observable insert1, insert2 = null; @@ -55,8 +57,7 @@ public class AutomapInterfaceIntegrationTest { @After public void close() { db.update("DROP TABLE EMPLOYEE") - .dependsOn(create); - Connector.connectionProvider.close(); + .dependsOn(create); + connectionProvider.close(); } - } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java index 5bbe175cb0..c2fb2c32e3 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java @@ -1,38 +1,42 @@ package com.baeldung.rxjava.jdbc; -import com.github.davidmoten.rx.jdbc.Database; -import org.junit.After; -import org.junit.Test; -import rx.Observable; +import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Test; + +import com.github.davidmoten.rx.jdbc.ConnectionProvider; +import com.github.davidmoten.rx.jdbc.Database; + +import rx.Observable; public class BasicQueryTypesIntegrationTest { - private Database db = Database.from(Connector.connectionProvider); + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); - private Observable create; + private Observable create, insert1, insert2, insert3, update, delete = null; @Test public void whenCreateTableAndInsertRecords_thenCorrect() { create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))") .count(); - Observable insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')") + insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')") .dependsOn(create) .count(); - Observable update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1") + update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1") .dependsOn(create) .count(); - Observable insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')") + insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')") .dependsOn(create) .count(); - Observable insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')") + insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')") .dependsOn(create) .count(); - Observable delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2") + delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2") .dependsOn(create) .count(); List names = db.select("select name from EMPLOYEE where id < ?") @@ -55,6 +59,6 @@ public class BasicQueryTypesIntegrationTest { public void close() { db.update("DROP TABLE EMPLOYEE") .dependsOn(create); - Connector.connectionProvider.close(); + connectionProvider.close(); } } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java index 70fc7cf984..71eeded21c 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java @@ -1,21 +1,25 @@ package com.baeldung.rxjava.jdbc; -import com.github.davidmoten.rx.jdbc.Database; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import rx.Observable; +import static org.junit.Assert.assertEquals; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.github.davidmoten.rx.jdbc.ConnectionProvider; +import com.github.davidmoten.rx.jdbc.Database; + +import rx.Observable; public class InsertBlobIntegrationTest { - private Database db = Database.from(Connector.connectionProvider); + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); private String expectedDocument = null; private String actualDocument = null; @@ -56,6 +60,6 @@ public class InsertBlobIntegrationTest { public void close() { db.update("DROP TABLE SERVERLOG") .dependsOn(create); - Connector.connectionProvider.close(); + connectionProvider.close(); } -} +} \ No newline at end of file diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java index aea68426ec..189bca4adb 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java @@ -1,20 +1,24 @@ package com.baeldung.rxjava.jdbc; -import com.github.davidmoten.rx.jdbc.Database; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import rx.Observable; +import static org.junit.Assert.assertEquals; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.github.davidmoten.rx.jdbc.ConnectionProvider; +import com.github.davidmoten.rx.jdbc.Database; + +import rx.Observable; public class InsertClobIntegrationTest { - private Database db = Database.from(Connector.connectionProvider); + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); private String expectedDocument = null; private String actualDocument = null; @@ -54,6 +58,6 @@ public class InsertClobIntegrationTest { public void close() { db.update("DROP TABLE SERVERLOG") .dependsOn(create); - Connector.connectionProvider.close(); + connectionProvider.close(); } } \ No newline at end of file diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java index cc5a9fe3be..2018a9427c 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java @@ -1,24 +1,28 @@ package com.baeldung.rxjava.jdbc; -import com.github.davidmoten.rx.jdbc.Database; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import rx.Observable; - import static org.assertj.core.api.Assertions.assertThat; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.github.davidmoten.rx.jdbc.ConnectionProvider; +import com.github.davidmoten.rx.jdbc.Database; + +import rx.Observable; + public class ReturnKeysIntegrationTest { - private Observable createStatement; + private Observable begin = null; + private Observable createStatement = null; - private Database db = Database.from(Connector.connectionProvider); + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); @Before public void setup() { - Observable begin = db.beginTransaction(); - createStatement = db - .update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))") + begin = db.beginTransaction(); + createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))") .dependsOn(begin) .count(); } @@ -37,7 +41,8 @@ public class ReturnKeysIntegrationTest { @After public void close() { - db.update("DROP TABLE EMPLOYEE"); - Connector.connectionProvider.close(); + db.update("DROP TABLE EMPLOYEE") + .dependsOn(createStatement); + connectionProvider.close(); } } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java index 2021dcdbb3..4e24d7f10e 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java @@ -1,15 +1,21 @@ package com.baeldung.rxjava.jdbc; -import com.github.davidmoten.rx.jdbc.Database; -import org.junit.After; -import org.junit.Test; -import rx.Observable; - import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Test; + +import com.github.davidmoten.rx.jdbc.ConnectionProvider; +import com.github.davidmoten.rx.jdbc.Database; + +import rx.Observable; + public class TransactionIntegrationTest { - private Database db = Database.from(Connector.connectionProvider); + private Observable createStatement = null; + + private ConnectionProvider connectionProvider = Connector.connectionProvider; + private Database db = Database.from(connectionProvider); @Test public void whenCommitTransaction_thenRecordUpdated() { @@ -36,7 +42,8 @@ public class TransactionIntegrationTest { @After public void close() { - db.update("DROP TABLE EMPLOYEE"); - Connector.connectionProvider.close(); + db.update("DROP TABLE EMPLOYEE") + .dependsOn(createStatement); + connectionProvider.close(); } }