diff --git a/rxjava/pom.xml b/rxjava/pom.xml
index 96d49e0d3c..783833243b 100644
--- a/rxjava/pom.xml
+++ b/rxjava/pom.xml
@@ -3,7 +3,6 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.baeldung
rxjava
1.0-SNAPSHOT
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/ObservableTest.java b/rxjava/src/test/java/com/baeldung/rxjava/ObservableTest.java
index 08fccfb238..3d3bb021d2 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/ObservableTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/ObservableTest.java
@@ -8,7 +8,7 @@ import static junit.framework.Assert.assertTrue;
public class ObservableTest {
- String result = "";
+ private String result = "";
@Test
public void givenString_whenJustAndSubscribe_thenEmitsSingleItem() {
@@ -85,7 +85,7 @@ public class ObservableTest {
.groupBy(i -> 0 == (i % 2) ? "EVEN" : "ODD")
.subscribe(group ->
group.subscribe((number) -> {
- if (group.getKey().toString().equals("EVEN")) {
+ if (group.getKey().equals("EVEN")) {
EVEN[0] += number;
} else {
ODD[0] += number;
@@ -141,5 +141,4 @@ public class ObservableTest {
assertTrue(sum[0] == 10);
}
-
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/ResourceManagementTest.java b/rxjava/src/test/java/com/baeldung/rxjava/ResourceManagementTest.java
index 9c52af61d0..81be84fd0d 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/ResourceManagementTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/ResourceManagementTest.java
@@ -12,16 +12,12 @@ public class ResourceManagementTest {
String[] result = {""};
Observable values = Observable.using(
- () -> {
- return "MyResource";
- },
- r -> {
- return Observable.create(o -> {
- for (Character c : r.toCharArray())
- o.onNext(c);
- o.onCompleted();
- });
- },
+ () -> "MyResource",
+ r -> Observable.create(o -> {
+ for (Character c : r.toCharArray())
+ o.onNext(c);
+ o.onCompleted();
+ }),
r -> System.out.println("Disposed: " + r)
);
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaBackpressureLongRunningUnitTest.java b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaBackpressureLongRunningUnitTest.java
index 458091fd1c..e9dbb48b92 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaBackpressureLongRunningUnitTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaBackpressureLongRunningUnitTest.java
@@ -27,7 +27,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
// then
testSubscriber.awaitTerminalEvent();
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
-
}
@Test
@@ -60,7 +59,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
// then
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
-
}
@Test
@@ -77,7 +75,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
// then
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
-
}
@Test
@@ -88,15 +85,14 @@ public class RxJavaBackpressureLongRunningUnitTest {
// when
source.sample(100, TimeUnit.MILLISECONDS)
- // .throttleFirst(100, TimeUnit.MILLISECONDS)
- .observeOn(Schedulers.computation()).subscribe(testSubscriber);
+ // .throttleFirst(100, TimeUnit.MILLISECONDS)
+ .observeOn(Schedulers.computation()).subscribe(testSubscriber);
IntStream.range(0, 1_000).forEach(source::onNext);
// then
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
-
}
@Test
@@ -111,7 +107,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
// then
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
-
}
@Test
@@ -120,11 +115,11 @@ public class RxJavaBackpressureLongRunningUnitTest {
TestSubscriber testSubscriber = new TestSubscriber<>();
// when
- Observable.range(1, 1_000_000).onBackpressureDrop().observeOn(Schedulers.computation()).subscribe(testSubscriber);
+ Observable.range(1, 1_000_000).onBackpressureDrop().observeOn(Schedulers.computation())
+ .subscribe(testSubscriber);
// then
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
-
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java
index a49103196c..bba891da88 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java
@@ -1,5 +1,15 @@
package com.baeldung.rxjava;
+import org.junit.Test;
+import rx.Observable;
+import rx.Observable.Operator;
+import rx.Observable.Transformer;
+import rx.Subscriber;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import static com.baelding.rxjava.operator.ToCleanString.toCleanString;
import static com.baelding.rxjava.operator.ToLength.toLength;
import static org.hamcrest.Matchers.hasItems;
@@ -7,20 +17,6 @@ import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-import rx.Observable;
-import rx.Observable.Operator;
-import rx.Observable.Transformer;
-import rx.Subscriber;
-
-import com.baelding.rxjava.operator.ToCleanString;
-import com.baelding.rxjava.operator.ToLength;
-
public class RxJavaCustomOperatorUnitTest {
@Test
@@ -29,7 +25,7 @@ public class RxJavaCustomOperatorUnitTest {
final List results = new ArrayList<>();
final Observable observable = Observable.from(list)
- .lift(toCleanString());
+ .lift(toCleanString());
// when
observable.subscribe(results::add);
@@ -46,7 +42,7 @@ public class RxJavaCustomOperatorUnitTest {
final List results = new ArrayList<>();
final Observable observable = Observable.from(list)
- .compose(toLength());
+ .compose(toLength());
// when
observable.subscribe(results::add);
@@ -85,8 +81,8 @@ public class RxJavaCustomOperatorUnitTest {
final List results = new ArrayList<>();
Observable.from(Arrays.asList("ap_p-l@e", "or-an?ge"))
- .lift(cleanStringFn)
- .subscribe(results::add);
+ .lift(cleanStringFn)
+ .subscribe(results::add);
assertThat(results, notNullValue());
assertThat(results, hasSize(2));
@@ -99,8 +95,8 @@ public class RxJavaCustomOperatorUnitTest {
final List results = new ArrayList<>();
Observable.from(Arrays.asList("apple", "orange"))
- .compose(toLengthFn)
- .subscribe(results::add);
+ .compose(toLengthFn)
+ .subscribe(results::add);
assertThat(results, notNullValue());
assertThat(results, hasSize(2));
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaUnitTest.java b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaUnitTest.java
index 1e59b8c2d9..31ec473dc6 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaUnitTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaUnitTest.java
@@ -10,7 +10,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
public class RxJavaUnitTest {
@@ -19,7 +21,8 @@ public class RxJavaUnitTest {
// given
List letters = Arrays.asList("A", "B", "C", "D", "E");
List results = new ArrayList<>();
- Observable observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), (string, index) -> index + "-" + string);
+ Observable observable = Observable.from(letters)
+ .zipWith(Observable.range(1, Integer.MAX_VALUE), (string, index) -> index + "-" + string);
// when
observable.subscribe(results::add);
@@ -36,7 +39,8 @@ public class RxJavaUnitTest {
List letters = Arrays.asList("A", "B", "C", "D", "E");
TestSubscriber subscriber = new TestSubscriber<>();
- Observable observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string));
+ Observable observable = Observable.from(letters)
+ .zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string));
// when
observable.subscribe(subscriber);
@@ -54,7 +58,9 @@ public class RxJavaUnitTest {
List letters = Arrays.asList("A", "B", "C", "D", "E");
TestSubscriber subscriber = new TestSubscriber<>();
- Observable observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string)).concatWith(Observable.error(new RuntimeException("error in Observable")));
+ Observable observable = Observable.from(letters)
+ .zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string))
+ .concatWith(Observable.error(new RuntimeException("error in Observable")));
// when
observable.subscribe(subscriber);
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/SchedulersTest.java b/rxjava/src/test/java/com/baeldung/rxjava/SchedulersTest.java
index 1d36501fed..35714566ca 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/SchedulersTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/SchedulersTest.java
@@ -1,8 +1,6 @@
package com.baeldung.rxjava;
-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -23,9 +21,9 @@ import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertThat;
public class SchedulersTest {
- String result = "";
- String result1 = "";
- String result2 = "";
+ private String result = "";
+ private String result1 = "";
+ private String result2 = "";
@Test
public void givenScheduledWorker_whenScheduleAnAction_thenResultAction() throws InterruptedException {
@@ -108,7 +106,6 @@ public class SchedulersTest {
Assert.assertTrue(result.equals("main"));
}
-
@Test
public void givenObservable_whenTrampolineScheduled_thenExecuteOnMainThread() throws InterruptedException {
System.out.println("trampoline_1");
@@ -161,7 +158,8 @@ public class SchedulersTest {
subscriber.onNext("Alfa");
subscriber.onNext("Beta");
subscriber.onCompleted();
- });;
+ });
+ ;
observable
.subscribeOn(schedulerA)
@@ -203,10 +201,10 @@ public class SchedulersTest {
Observable tick = Observable.interval(1, TimeUnit.SECONDS, scheduler);
- Observable.from(letters)
- .zipWith(tick, (string, index) -> index + "-" + string)
- .subscribeOn(scheduler)
- .subscribe(subscriber);
+ Observable.from(letters)
+ .zipWith(tick, (string, index) -> index + "-" + string)
+ .subscribeOn(scheduler)
+ .subscribe(subscriber);
subscriber.assertNoValues();
subscriber.assertNotCompleted();
@@ -229,10 +227,9 @@ public class SchedulersTest {
Scheduler schedulerA = Schedulers.from(poolA);
Observable.just('A', 'B')
.delay(1, TimeUnit.SECONDS, schedulerA)
- .subscribe(i -> result+= Thread.currentThread().getName() + i + " ");
+ .subscribe(i -> result += Thread.currentThread().getName() + i + " ");
Thread.sleep(2000);
Assert.assertTrue(result.equals("Sched1-A Sched1-B "));
}
-
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/SingleTest.java b/rxjava/src/test/java/com/baeldung/rxjava/SingleTest.java
index 6d428d856b..1352841ed9 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/SingleTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/SingleTest.java
@@ -20,5 +20,4 @@ public class SingleTest {
single.subscribe();
assertTrue(result[0].equals("Hello"));
}
-
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/SubjectTest.java b/rxjava/src/test/java/com/baeldung/rxjava/SubjectTest.java
index 429a7fe231..210ceaa636 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/SubjectTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/SubjectTest.java
@@ -9,7 +9,7 @@ import static junit.framework.Assert.assertTrue;
public class SubjectTest {
@Test
- public void givenSubjectAndTwoSubscribers_whenSubscribeOnSubject_thenSubscriberBeginsToAdd(){
+ public void givenSubjectAndTwoSubscribers_whenSubscribeOnSubject_thenSubscriberBeginsToAdd() {
PublishSubject subject = PublishSubject.create();
subject.subscribe(SubjectImpl.getFirstObserver());
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/UtilityOperatorsTest.java b/rxjava/src/test/java/com/baeldung/rxjava/UtilityOperatorsTest.java
index 8ce370e356..a4fc62aaf1 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/UtilityOperatorsTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/UtilityOperatorsTest.java
@@ -7,6 +7,7 @@ import rx.Observable;
import rx.Observer;
import rx.exceptions.OnErrorNotImplementedException;
import rx.schedulers.Schedulers;
+import rx.schedulers.Timestamped;
import java.util.concurrent.TimeUnit;
@@ -14,9 +15,9 @@ import static org.junit.Assert.assertTrue;
public class UtilityOperatorsTest {
- int emittedTotal = 0;
- int receivedTotal = 0;
- String result = "";
+ private int emittedTotal = 0;
+ private int receivedTotal = 0;
+ private String result = "";
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -44,7 +45,6 @@ public class UtilityOperatorsTest {
assertTrue(receivedTotal == 15000);
}
-
@Test
public void givenObservable_whenObserveOnBeforeOnNext_thenEmitsEventsOnComputeScheduler() throws InterruptedException {
@@ -68,7 +68,6 @@ public class UtilityOperatorsTest {
assertTrue(receivedTotal == 15000);
}
-
@Test
public void givenObservable_whenSubscribeOn_thenEmitsEventsOnComputeScheduler() throws InterruptedException {
@@ -92,7 +91,6 @@ public class UtilityOperatorsTest {
assertTrue(receivedTotal == 15000);
}
-
@Test
public void givenObservableWithOneEvent_whenSingle_thenEmitEvent() {
@@ -197,15 +195,13 @@ public class UtilityOperatorsTest {
@Test
public void givenObservables_whenDelay_thenEventsStartAppearAfterATime() throws InterruptedException {
- Observable source
- = Observable.interval(1, TimeUnit.SECONDS)
+ Observable> source = Observable.interval(1, TimeUnit.SECONDS)
.take(5)
.timestamp();
- Observable delay
- = source.delaySubscription(2, TimeUnit.SECONDS);
+ Observable> delay = source.delaySubscription(2, TimeUnit.SECONDS);
- source.subscribe(
+ source.subscribe(
value -> System.out.println("source :" + value),
t -> System.out.println("source error"),
() -> System.out.println("source completed"));
@@ -231,14 +227,12 @@ public class UtilityOperatorsTest {
Observable values = Observable.using(
() -> "resource",
- r -> {
- return Observable.create(o -> {
- for (Character c : r.toCharArray()) {
- o.onNext(c);
- }
- o.onCompleted();
- });
- },
+ r -> Observable.create(o -> {
+ for (Character c : r.toCharArray()) {
+ o.onNext(c);
+ }
+ o.onCompleted();
+ }),
r -> System.out.println("Disposed: " + r)
);
values.subscribe(
@@ -248,7 +242,6 @@ public class UtilityOperatorsTest {
assertTrue(result.equals("resource"));
}
-
@Test
public void givenObservableCached_whenSubscribesWith2Actions_thenEmitsCachedValues() {
@@ -269,5 +262,4 @@ public class UtilityOperatorsTest {
});
assertTrue(receivedTotal == 8);
}
-
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java
similarity index 80%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java
index f44d4ac6b8..51e163db1f 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapClassIntegrationTest.java
@@ -8,18 +8,16 @@ 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 AutomapClassTest {
+public class AutomapClassIntegrationTest {
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
+ private Database db = Database.from(Connector.connectionProvider);
- Observable create = null;
- Observable insert1, insert2 = null;
+ private Observable create = null;
+ private Observable insert1, insert2 = null;
@Before
public void setup() {
@@ -58,6 +56,6 @@ public class AutomapClassTest {
public void close() {
db.update("DROP TABLE MANAGER")
.dependsOn(create);
- connectionProvider.close();
+ Connector.connectionProvider.close();
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java
similarity index 80%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java
index 79bae281eb..f1182952b1 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java
@@ -8,18 +8,16 @@ 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 AutomapInterfaceTest {
+public class AutomapInterfaceIntegrationTest {
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
+ private Database db = Database.from(Connector.connectionProvider);
- Observable create = null;
- Observable insert1, insert2 = null;
+ private Observable create = null;
+ private Observable insert1, insert2 = null;
@Before
public void setup() {
@@ -58,7 +56,7 @@ public class AutomapInterfaceTest {
public void close() {
db.update("DROP TABLE EMPLOYEE")
.dependsOn(create);
- connectionProvider.close();
+ Connector.connectionProvider.close();
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java
similarity index 63%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java
index 7677b2375d..5bbe175cb0 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java
@@ -1,42 +1,38 @@
package com.baeldung.rxjava.jdbc;
-import static org.junit.Assert.assertEquals;
+import com.github.davidmoten.rx.jdbc.Database;
+import org.junit.After;
+import org.junit.Test;
+import rx.Observable;
import java.util.Arrays;
import java.util.List;
-import org.junit.After;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
-import com.github.davidmoten.rx.jdbc.ConnectionProvider;
-import com.github.davidmoten.rx.jdbc.Database;
+public class BasicQueryTypesIntegrationTest {
-import rx.Observable;
+ private Database db = Database.from(Connector.connectionProvider);
-public class BasicQueryTypesTest {
-
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
-
- Observable create, insert1, insert2, insert3, update, delete = null;
+ private Observable create;
@Test
public void whenCreateTableAndInsertRecords_thenCorrect() {
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
.count();
- insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
+ Observable insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
.dependsOn(create)
.count();
- update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
+ Observable update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
.dependsOn(create)
.count();
- insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
+ Observable insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
.dependsOn(create)
.count();
- insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
+ Observable insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
.dependsOn(create)
.count();
- delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
+ Observable delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
.dependsOn(create)
.count();
List names = db.select("select name from EMPLOYEE where id < ?")
@@ -59,6 +55,6 @@ public class BasicQueryTypesTest {
public void close() {
db.update("DROP TABLE EMPLOYEE")
.dependsOn(create);
- connectionProvider.close();
+ Connector.connectionProvider.close();
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java
similarity index 81%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java
index fb3018ede4..70fc7cf984 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertBlobIntegrationTest.java
@@ -1,30 +1,26 @@
package com.baeldung.rxjava.jdbc;
-import static org.junit.Assert.assertEquals;
+import com.github.davidmoten.rx.jdbc.Database;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import rx.Observable;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
-import com.github.davidmoten.rx.jdbc.ConnectionProvider;
-import com.github.davidmoten.rx.jdbc.Database;
+public class InsertBlobIntegrationTest {
-import rx.Observable;
+ private Database db = Database.from(Connector.connectionProvider);
-public class InsertBlobTest {
+ private String expectedDocument = null;
+ private String actualDocument = null;
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
-
- String expectedDocument = null;
- String actualDocument = null;
-
- Observable create, insert = null;
+ private Observable create, insert = null;
@Before
public void setup() throws IOException {
@@ -60,6 +56,6 @@ public class InsertBlobTest {
public void close() {
db.update("DROP TABLE SERVERLOG")
.dependsOn(create);
- connectionProvider.close();
+ Connector.connectionProvider.close();
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java
similarity index 80%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java
index d29c2e3de2..aea68426ec 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java
@@ -1,29 +1,25 @@
package com.baeldung.rxjava.jdbc;
-import static org.junit.Assert.assertEquals;
+import com.github.davidmoten.rx.jdbc.Database;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import rx.Observable;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
-import com.github.davidmoten.rx.jdbc.ConnectionProvider;
-import com.github.davidmoten.rx.jdbc.Database;
+public class InsertClobIntegrationTest {
-import rx.Observable;
+ private Database db = Database.from(Connector.connectionProvider);
-public class InsertClobTest {
+ private String expectedDocument = null;
+ private String actualDocument = null;
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
-
- String expectedDocument = null;
- String actualDocument = null;
-
- Observable create, insert = null;
+ private Observable create, insert = null;
@Before
public void setup() throws IOException {
@@ -58,6 +54,6 @@ public class InsertClobTest {
public void close() {
db.update("DROP TABLE SERVERLOG")
.dependsOn(create);
- connectionProvider.close();
+ Connector.connectionProvider.close();
}
}
\ No newline at end of file
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java
similarity index 54%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java
index 87604b6c5f..cc5a9fe3be 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java
@@ -1,28 +1,24 @@
package com.baeldung.rxjava.jdbc;
-import static org.assertj.core.api.Assertions.assertThat;
-
+import com.github.davidmoten.rx.jdbc.Database;
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 ReturnKeysTest {
+import static org.assertj.core.api.Assertions.assertThat;
- Observable begin, commit = null;
- Observable createStatement, insertStatement, updateStatement = null;
+public class ReturnKeysIntegrationTest {
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
+ private Observable createStatement;
+
+ private Database db = Database.from(Connector.connectionProvider);
@Before
public void setup() {
- begin = db.beginTransaction();
- createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))")
+ Observable begin = db.beginTransaction();
+ createStatement = db
+ .update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))")
.dependsOn(begin)
.count();
}
@@ -41,8 +37,7 @@ public class ReturnKeysTest {
@After
public void close() {
- db.update("DROP TABLE EMPLOYEE")
- .dependsOn(createStatement);
- connectionProvider.close();
+ db.update("DROP TABLE EMPLOYEE");
+ Connector.connectionProvider.close();
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java
similarity index 71%
rename from rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionTest.java
rename to rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java
index 9603a11c46..2021dcdbb3 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java
@@ -1,22 +1,15 @@
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;
+public class TransactionIntegrationTest {
-import com.github.davidmoten.rx.jdbc.ConnectionProvider;
-import com.github.davidmoten.rx.jdbc.Database;
-
-import rx.Observable;
-
-public class TransactionTest {
-
- Observable begin, commit = null;
- Observable createStatement, insertStatement, updateStatement = null;
-
- ConnectionProvider connectionProvider = Connector.connectionProvider;
- Database db = Database.from(connectionProvider);
+ private Database db = Database.from(Connector.connectionProvider);
@Test
public void whenCommitTransaction_thenRecordUpdated() {
@@ -43,8 +36,7 @@ public class TransactionTest {
@After
public void close() {
- db.update("DROP TABLE EMPLOYEE")
- .dependsOn(createStatement);
- connectionProvider.close();
+ db.update("DROP TABLE EMPLOYEE");
+ Connector.connectionProvider.close();
}
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/onerror/ExceptionHandlingTest.java b/rxjava/src/test/java/com/baeldung/rxjava/onerror/ExceptionHandlingTest.java
index 297cfa980b..b1d711ab39 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/onerror/ExceptionHandlingTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/onerror/ExceptionHandlingTest.java
@@ -9,9 +9,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.Assert.assertTrue;
-/**
- * @author aiet
- */
public class ExceptionHandlingTest {
private Error UNKNOWN_ERROR = new Error("unknown error");
@@ -19,10 +16,10 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenHandleOnErrorReturn_thenResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.onErrorReturn(Throwable::getMessage)
.subscribe(testObserver);
@@ -34,10 +31,10 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenHandleOnErrorResume_thenResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.onErrorResumeNext(Observable.just("one", "two"))
.subscribe(testObserver);
@@ -49,10 +46,10 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenHandleOnErrorResumeItem_thenResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.onErrorReturnItem("singleValue")
.subscribe(testObserver);
@@ -64,10 +61,10 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenHandleOnErrorResumeFunc_thenResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.onErrorResumeNext(throwable -> {
return Observable.just(throwable.getMessage(), "nextValue");
})
@@ -81,11 +78,11 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenChangeStateOnError_thenErrorThrown() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
final AtomicBoolean state = new AtomicBoolean(false);
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.doOnError(throwable -> state.set(true))
.subscribe(testObserver);
@@ -97,10 +94,10 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenExceptionOccurOnError_thenCompositeExceptionThrown() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.doOnError(throwable -> {
throw new RuntimeException("unexcepted");
})
@@ -113,10 +110,10 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndException_whenHandleOnException_thenResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Observable
- .error(UNKNOWN_EXCEPTION)
+ .error(UNKNOWN_EXCEPTION)
.onExceptionResumeNext(Observable.just("exceptionResumed"))
.subscribe(testObserver);
@@ -128,14 +125,14 @@ public class ExceptionHandlingTest {
@Test
public void givenSubscriberAndError_whenHandleOnException_thenNotResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
+
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.onExceptionResumeNext(Observable.just("exceptionResumed"))
.subscribe(testObserver);
testObserver.assertError(UNKNOWN_ERROR);
testObserver.assertNotComplete();
}
-
}
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/onerror/OnErrorRetryTest.java b/rxjava/src/test/java/com/baeldung/rxjava/onerror/OnErrorRetryTest.java
index 0f9c39ad1b..3cc72056ba 100644
--- a/rxjava/src/test/java/com/baeldung/rxjava/onerror/OnErrorRetryTest.java
+++ b/rxjava/src/test/java/com/baeldung/rxjava/onerror/OnErrorRetryTest.java
@@ -9,20 +9,17 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertTrue;
-/**
- * @author aiet
- */
public class OnErrorRetryTest {
private Error UNKNOWN_ERROR = new Error("unknown error");
@Test
public void givenSubscriberAndError_whenRetryOnError_thenRetryConfirmed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
AtomicInteger atomicCounter = new AtomicInteger(0);
Observable
- .error(() -> {
+ .error(() -> {
atomicCounter.incrementAndGet();
return UNKNOWN_ERROR;
})
@@ -37,12 +34,12 @@ public class OnErrorRetryTest {
@Test
public void givenSubscriberAndError_whenRetryConditionallyOnError_thenRetryConfirmed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
AtomicInteger atomicCounter = new AtomicInteger(0);
Observable
- .error(() -> {
+ .error(() -> {
atomicCounter.incrementAndGet();
return UNKNOWN_ERROR;
})
@@ -57,11 +54,11 @@ public class OnErrorRetryTest {
@Test
public void givenSubscriberAndError_whenRetryUntilOnError_thenRetryConfirmed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
AtomicInteger atomicCounter = new AtomicInteger(0);
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.retryUntil(() -> atomicCounter.incrementAndGet() > 3)
.subscribe(testObserver);
@@ -73,12 +70,12 @@ public class OnErrorRetryTest {
@Test
public void givenSubscriberAndError_whenRetryWhenOnError_thenRetryConfirmed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
Exception noretryException = new Exception("don't retry");
Observable
- .error(UNKNOWN_ERROR)
- .retryWhen(throwableObservable -> Observable.error(noretryException))
+ .error(UNKNOWN_ERROR)
+ .retryWhen(throwableObservable -> Observable.error(noretryException))
.subscribe(testObserver);
testObserver.assertError(noretryException);
@@ -88,11 +85,11 @@ public class OnErrorRetryTest {
@Test
public void givenSubscriberAndError_whenRetryWhenOnError_thenCompleted() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
AtomicInteger atomicCounter = new AtomicInteger(0);
Observable
- .error(() -> {
+ .error(() -> {
atomicCounter.incrementAndGet();
return UNKNOWN_ERROR;
})
@@ -107,11 +104,11 @@ public class OnErrorRetryTest {
@Test
public void givenSubscriberAndError_whenRetryWhenOnError_thenResubscribed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
AtomicInteger atomicCounter = new AtomicInteger(0);
Observable
- .error(() -> {
+ .error(() -> {
atomicCounter.incrementAndGet();
return UNKNOWN_ERROR;
})
@@ -126,11 +123,11 @@ public class OnErrorRetryTest {
@Test
public void givenSubscriberAndError_whenRetryWhenForMultipleTimesOnError_thenResumed() {
- TestObserver testObserver = new TestObserver();
+ TestObserver testObserver = new TestObserver<>();
long before = System.currentTimeMillis();
Observable
- .error(UNKNOWN_ERROR)
+ .error(UNKNOWN_ERROR)
.retryWhen(throwableObservable -> throwableObservable
.zipWith(Observable.range(1, 3), (throwable, integer) -> integer)
.flatMap(integer -> {
diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
similarity index 97%
rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java
rename to spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
index c20f968704..33926d6200 100644
--- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestUnitTest.java
+++ b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java
@@ -21,7 +21,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainApplication.class)
-public class ExamplePostControllerRequestUnitTest {
+public class ExamplePostControllerRequestIntegrationTest {
MockMvc mockMvc;
@Mock private ExampleService exampleService;
diff --git a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
similarity index 97%
rename from spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java
rename to spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
index 3d09622c47..5c5e5c0a64 100644
--- a/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseUnitTest.java
+++ b/spring-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java
@@ -23,7 +23,7 @@ import org.baeldung.config.MainApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainApplication.class)
-public class ExamplePostControllerResponseUnitTest {
+public class ExamplePostControllerResponseIntegrationTest {
MockMvc mockMvc;
@Mock private ExampleService exampleService;
diff --git a/spring-rest/src/test/java/com/baeldung/web/log/test/TestTaxiFareController.java b/spring-rest/src/test/java/com/baeldung/web/log/test/TestTaxiFareController.java
deleted file mode 100644
index 398e3c04e9..0000000000
--- a/spring-rest/src/test/java/com/baeldung/web/log/test/TestTaxiFareController.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.baeldung.web.log.test;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import org.junit.Test;
-import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-
-import com.baeldung.web.log.data.TaxiRide;
-
-public class TestTaxiFareController {
-
- private static final String URL = "http://localhost:" + 8082 + "/spring-rest/taxifare/";
-
- @Test
- public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
- TestRestTemplate testRestTemplate = new TestRestTemplate();
- ResponseEntity response = testRestTemplate.getForEntity(URL + "get/", String.class);
-
- assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
- }
-
- @Test
- public void givenTaxiRide_whenCalculatedFare_thanStatus200() {
- TestRestTemplate testRestTemplate = new TestRestTemplate();
- TaxiRide taxiRide = new TaxiRide(true, 10l);
- String fare = testRestTemplate.postForObject(URL + "calculate/", taxiRide, String.class);
-
- assertThat(fare, equalTo("200"));
- }
-}