From 9c0b6b4a47fb6af1e69ec387420e0f248c897aa8 Mon Sep 17 00:00:00 2001
From: YasinBhojawala <31448190+YasinBhojawala@users.noreply.github.com>
Date: Tue, 10 Oct 2017 21:51:35 +0530
Subject: [PATCH 001/114] BAEL-1139 move to new saas module (#2719)
* Removed unintentionally commented code
* BAEL-1139 move jira API to a new saas module
* no tabs only spaces
* changes
---
libraries/pom.xml | 20 -----
pom.xml | 1 +
saas/.gitignore | 26 ++++++
saas/pom.xml | 84 +++++++++++++++++++
.../com/baeldung/saas}/jira/MyJiraClient.java | 2 +-
5 files changed, 112 insertions(+), 21 deletions(-)
create mode 100644 saas/.gitignore
create mode 100644 saas/pom.xml
rename {libraries/src/main/java/com/baeldung => saas/src/main/java/com/baeldung/saas}/jira/MyJiraClient.java (99%)
diff --git a/libraries/pom.xml b/libraries/pom.xml
index c7c5da95a6..e539c0916f 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -575,22 +575,6 @@
hazelcast
${hazelcast.version}
-
- com.atlassian.jira
- jira-rest-java-client-core
- 4.0.0
-
-
- com.atlassian.fugue
- fugue
- 2.6.1
-
-
-
org.jgrapht
jgrapht-core
@@ -626,10 +610,6 @@
bintray
http://dl.bintray.com/cuba-platform/main
-
- atlassian-public
- https://packages.atlassian.com/maven/repository/public
-
0.1.0
diff --git a/pom.xml b/pom.xml
index c3915e4fce..3bdeac3672 100644
--- a/pom.xml
+++ b/pom.xml
@@ -248,6 +248,7 @@
mockserver
undertow
vertx-and-rxjava
+ saas
deeplearning4j
diff --git a/saas/.gitignore b/saas/.gitignore
new file mode 100644
index 0000000000..3de4cc647e
--- /dev/null
+++ b/saas/.gitignore
@@ -0,0 +1,26 @@
+*.class
+
+0.*
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+.resourceCache
+
+# Packaged files #
+*.jar
+*.war
+*.ear
+
+# Files generated by integration tests
+*.txt
+backup-pom.xml
+/bin/
+/temp
+
+#IntelliJ specific
+.idea/
+*.iml
\ No newline at end of file
diff --git a/saas/pom.xml b/saas/pom.xml
new file mode 100644
index 0000000000..7c8745910f
--- /dev/null
+++ b/saas/pom.xml
@@ -0,0 +1,84 @@
+
+ 4.0.0
+ com.baeldung
+ saas
+ 0.1.0-SNAPSHOT
+ jar
+ saas
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ com.atlassian.jira
+ jira-rest-java-client-core
+ 4.0.0
+
+
+ com.atlassian.fugue
+ fugue
+ 2.6.1
+
+
+ com.google.guava
+ guava
+ 19.0
+
+
+
+
+
+ saas
+
+
+ src/main/resources
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ 1.8
+ 1.8
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.6.0
+
+ java
+ com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
+
+ -Xmx300m
+ -XX:+UseParallelGC
+ -classpath
+
+ com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
+
+
+
+
+
+
+
+
+ atlassian-public
+ https://packages.atlassian.com/maven/repository/public
+
+
+
+
+ 3.6.0
+
+
\ No newline at end of file
diff --git a/libraries/src/main/java/com/baeldung/jira/MyJiraClient.java b/saas/src/main/java/com/baeldung/saas/jira/MyJiraClient.java
similarity index 99%
rename from libraries/src/main/java/com/baeldung/jira/MyJiraClient.java
rename to saas/src/main/java/com/baeldung/saas/jira/MyJiraClient.java
index ea1d73f52a..ff1de5a6d0 100644
--- a/libraries/src/main/java/com/baeldung/jira/MyJiraClient.java
+++ b/saas/src/main/java/com/baeldung/saas/jira/MyJiraClient.java
@@ -1,4 +1,4 @@
-package com.baeldung.jira;
+package com.baeldung.saas.jira;
import com.atlassian.jira.rest.client.api.IssueRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClient;
From f8db7b02c5d8e4f7e9f786f69fd2705f1415d10c Mon Sep 17 00:00:00 2001
From: Graham Cox
Date: Wed, 11 Oct 2017 02:44:50 +0100
Subject: [PATCH 002/114] Kotlin junit5 (#2672)
* Fixed the core-kotlin module to build, and set it up to run JUnit 5 tests using Failsafe
* Example JUnit5 tests in Kotlin
---
core-kotlin/pom.xml | 56 ++++++++++++-
.../com/baeldung/kotlin/junit5/Calculator.kt | 17 ++++
.../baeldung/kotlin/junit5/CalculatorTest5.kt | 82 +++++++++++++++++++
.../kotlin/junit5/DivideByZeroException.kt | 3 +
.../com/baeldung/kotlin/junit5/SimpleTest5.kt | 21 +++++
5 files changed, 178 insertions(+), 1 deletion(-)
create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt
create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt
create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt
create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt
diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml
index 856a37ded0..e795d1e042 100644
--- a/core-kotlin/pom.xml
+++ b/core-kotlin/pom.xml
@@ -5,6 +5,7 @@
core-kotlin
1.0-SNAPSHOT
+ jar
com.baeldung
@@ -20,6 +21,24 @@
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.jupiter.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+ junit
+ junit
+ ${junit4.version}
+ test
+
org.jetbrains.kotlin
kotlin-stdlib
@@ -116,16 +135,51 @@
+
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ maven-failsafe-plugin
+ 2.19.1
+
+
+ org.junit.platform
+ junit-platform-surefire-provider
+ ${junit.platform.version}
+
+
+
+
+ junit5
+
+ integration-test
+ verify
+
+
+
+ **/*Test5.java
+
+
+
+
+
+ UTF-8
1.1.2
1.1.2
1.1.2
1.1.2
0.15
1.5.0
+
+ 5.0.0
+ 1.0.0
+ 4.12.0
+ 4.12
-
\ No newline at end of file
+
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt
new file mode 100644
index 0000000000..1b61c05887
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/Calculator.kt
@@ -0,0 +1,17 @@
+package com.baeldung.kotlin.junit5
+
+class Calculator {
+ fun add(a: Int, b: Int) = a + b
+
+ fun divide(a: Int, b: Int) = if (b == 0) {
+ throw DivideByZeroException(a)
+ } else {
+ a / b
+ }
+
+ fun square(a: Int) = a * a
+
+ fun squareRoot(a: Int) = Math.sqrt(a.toDouble())
+
+ fun log(base: Int, value: Int) = Math.log(value.toDouble()) / Math.log(base.toDouble())
+}
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt
new file mode 100644
index 0000000000..dd35805044
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt
@@ -0,0 +1,82 @@
+package com.baeldung.kotlin.junit5
+
+import org.junit.jupiter.api.*
+import org.junit.jupiter.api.function.Executable
+
+class CalculatorTest5 {
+ private val calculator = Calculator()
+
+ @Test
+ fun testAddition() {
+ Assertions.assertEquals(4, calculator.add(1, 3))
+ }
+
+ @Test
+ fun testDivideByZero() {
+ val exception = Assertions.assertThrows(DivideByZeroException::class.java) {
+ calculator.divide(5, 0)
+ }
+
+ Assertions.assertEquals(5, exception.numerator)
+ }
+
+ @Test
+ fun testSquares() {
+ Assertions.assertAll(
+ Executable { Assertions.assertEquals(1, calculator.square(1)) },
+ Executable { Assertions.assertEquals(4, calculator.square(2)) },
+ Executable { Assertions.assertEquals(9, calculator.square(3)) }
+ )
+ }
+
+ @TestFactory
+ fun testSquaresFactory() = listOf(
+ DynamicTest.dynamicTest("1 squared") { Assertions.assertEquals(1,calculator.square(1))},
+ DynamicTest.dynamicTest("2 squared") { Assertions.assertEquals(4,calculator.square(2))},
+ DynamicTest.dynamicTest("3 squared") { Assertions.assertEquals(9,calculator.square(3))}
+ )
+
+ @TestFactory
+ fun testSquaresFactory2() = listOf(
+ 1 to 1,
+ 2 to 4,
+ 3 to 9,
+ 4 to 16,
+ 5 to 25)
+ .map { (input, expected) ->
+ DynamicTest.dynamicTest("$input squared") {
+ Assertions.assertEquals(expected, calculator.square(input))
+ }
+ }
+
+ private val squaresTestData = listOf(
+ 1 to 1,
+ 2 to 4,
+ 3 to 9,
+ 4 to 16,
+ 5 to 25)
+
+ @TestFactory
+ fun testSquaresFactory3() = squaresTestData
+ .map { (input, expected) ->
+ DynamicTest.dynamicTest("$input squared") {
+ Assertions.assertEquals(expected, calculator.square(input))
+ }
+ }
+ @TestFactory
+ fun testSquareRootsFactory3() = squaresTestData
+ .map { (expected, input) ->
+ DynamicTest.dynamicTest("Square root of $input") {
+ Assertions.assertEquals(expected.toDouble(), calculator.squareRoot(input))
+ }
+ }
+
+ @Tags(
+ Tag("slow"),
+ Tag("logarithms")
+ )
+ @Test
+ fun testLogarithms() {
+ Assertions.assertEquals(3.0, calculator.log(2, 8))
+ }
+}
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt
new file mode 100644
index 0000000000..60bc4e2944
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/DivideByZeroException.kt
@@ -0,0 +1,3 @@
+package com.baeldung.kotlin.junit5
+
+class DivideByZeroException(val numerator: Int) : Exception()
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt
new file mode 100644
index 0000000000..c04ab568f7
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt
@@ -0,0 +1,21 @@
+package com.baeldung.kotlin.junit5
+
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Disabled
+import org.junit.jupiter.api.Test
+
+class SimpleTest5 {
+ @Test
+ fun testEmpty() {
+ val list = listOf()
+ Assertions.assertTrue(list::isEmpty)
+ }
+
+ @Test
+ @Disabled
+ fun testMessage() {
+ Assertions.assertEquals(3, 4) {
+ "Three does not equal four"
+ }
+ }
+}
From 31f4581de3b4fcf94e6af8812b62d8a3cf08603e Mon Sep 17 00:00:00 2001
From: Anton
Date: Wed, 11 Oct 2017 04:53:59 +0300
Subject: [PATCH 003/114] BAEL-1041 Introduction to Caffeine (#2585)
* BAEL-748 quick guide to @Value
* BAEL-748 changes from review
* BAEL-748 inject comma-separated values into array
* BAEL-768 Introduction to Netty
* BAEL-768 remove commented code
* BAEL-861 Introduction to Awaitility
* BAEL-861 rename Test to UnitTest
* BAEL-1041 Introduction in Caffeine
* BAEL-1041 fix test
* BAEL-1041 fix formatting
* BAEL-1041 fix expected/actual order
* BAEL-1041 remove trailing underscore
* Formatting after merge
* BAEL-1041 add spaces between data and assertions
* BAEL-1041 soft values example
* BAEL-1041 remove duplicate dependency
* BAEL-1041 formatting fix
* BAEL-1041 formatting fix
---
libraries/pom.xml | 16 +-
.../com/baeldung/caffeine/DataObject.java | 28 +++
.../baeldung/caffeine/CaffeineUnitTest.java | 174 ++++++++++++++++++
3 files changed, 213 insertions(+), 5 deletions(-)
create mode 100644 libraries/src/main/java/com/baeldung/caffeine/DataObject.java
create mode 100644 libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java
diff --git a/libraries/pom.xml b/libraries/pom.xml
index e539c0916f..b519b9cd53 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -590,11 +590,16 @@
docx4j
3.3.5
-
- javax.xml.bind
- jaxb-api
- 2.1
-
+
+ javax.xml.bind
+ jaxb-api
+ 2.1
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+ ${caffeine.version}
+
@@ -666,5 +671,6 @@
1.0.3
1.0.0
3.8.4
+ 2.5.5
diff --git a/libraries/src/main/java/com/baeldung/caffeine/DataObject.java b/libraries/src/main/java/com/baeldung/caffeine/DataObject.java
new file mode 100644
index 0000000000..2a8b60b045
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/caffeine/DataObject.java
@@ -0,0 +1,28 @@
+package com.baeldung.caffeine;
+
+final class DataObject {
+ private final String data;
+
+ private static int objectCounter = 0;
+
+ private DataObject(String data) {
+ this.data = data;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ @Override
+ public String toString() {
+ return "DataObject{" +
+ "data='" + data + '\'' +
+ '}';
+ }
+
+ public static DataObject get(String data) {
+ objectCounter++;
+ System.out.println(String.format("Initializing DataObject#%d with data '%s'", objectCounter, data));
+ return new DataObject(data);
+ }
+}
diff --git a/libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java b/libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java
new file mode 100644
index 0000000000..56dbda5974
--- /dev/null
+++ b/libraries/src/test/java/com/baeldung/caffeine/CaffeineUnitTest.java
@@ -0,0 +1,174 @@
+package com.baeldung.caffeine;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.Nonnull;
+
+import org.junit.Test;
+
+import com.github.benmanes.caffeine.cache.*;
+
+public class CaffeineUnitTest {
+
+ @Test
+ public void givenCache_whenPopulate_thenValueStored() {
+ Cache cache = Caffeine.newBuilder()
+ .expireAfterWrite(1, TimeUnit.MINUTES)
+ .maximumSize(100)
+ .build();
+
+ String key = "A";
+ DataObject dataObject = cache.getIfPresent(key);
+
+ assertNull(dataObject);
+
+ dataObject = cache.get(key, k -> DataObject.get("Data for A"));
+
+ assertNotNull(dataObject);
+ assertEquals("Data for A", dataObject.getData());
+
+ cache.put(key, dataObject);
+ dataObject = cache.getIfPresent(key);
+
+ assertNotNull(dataObject);
+
+ cache.invalidate(key);
+ dataObject = cache.getIfPresent(key);
+
+ assertNull(dataObject);
+ }
+
+ @Test
+ public void givenLoadingCache_whenGet_thenValuePopulated() {
+ LoadingCache cache = Caffeine.newBuilder()
+ .maximumSize(100)
+ .expireAfterWrite(1, TimeUnit.MINUTES)
+ .build(k -> DataObject.get("Data for " + k));
+ String key = "A";
+
+ DataObject dataObject = cache.get(key);
+
+ assertNotNull(dataObject);
+ assertEquals("Data for " + key, dataObject.getData());
+
+ Map dataObjectMap = cache.getAll(Arrays.asList("A", "B", "C"));
+
+ assertEquals(3, dataObjectMap.size());
+ }
+
+ @Test
+ public void givenAsyncLoadingCache_whenGet_thenValuePopulated() {
+
+ AsyncLoadingCache cache = Caffeine.newBuilder()
+ .maximumSize(100)
+ .expireAfterWrite(1, TimeUnit.MINUTES)
+ .buildAsync(k -> DataObject.get("Data for " + k));
+ String key = "A";
+
+ cache.get(key).thenAccept(dataObject -> {
+ assertNotNull(dataObject);
+ assertEquals("Data for " + key, dataObject.getData());
+ });
+
+ cache.getAll(Arrays.asList("A", "B", "C"))
+ .thenAccept(dataObjectMap -> assertEquals(3, dataObjectMap.size()));
+ }
+
+ @Test
+ public void givenLoadingCacheWithSmallSize_whenPut_thenSizeIsConstant() {
+ LoadingCache cache = Caffeine.newBuilder()
+ .maximumSize(1)
+ .refreshAfterWrite(10, TimeUnit.MINUTES)
+ .build(k -> DataObject.get("Data for " + k));
+
+ assertEquals(0, cache.estimatedSize());
+
+ cache.get("A");
+
+ assertEquals(1, cache.estimatedSize());
+
+ cache.get("B");
+ cache.cleanUp();
+
+ assertEquals(1, cache.estimatedSize());
+ }
+
+ @Test
+ public void givenLoadingCacheWithWeigher_whenPut_thenSizeIsConstant() {
+ LoadingCache cache = Caffeine.newBuilder()
+ .maximumWeight(10)
+ .weigher((k,v) -> 5)
+ .build(k -> DataObject.get("Data for " + k));
+
+ assertEquals(0, cache.estimatedSize());
+
+ cache.get("A");
+
+ assertEquals(1, cache.estimatedSize());
+
+ cache.get("B");
+
+ assertEquals(2, cache.estimatedSize());
+
+ cache.get("C");
+ cache.cleanUp();
+
+ assertEquals(2, cache.estimatedSize());
+ }
+
+ @Test
+ public void givenTimeEvictionCache_whenTimeLeft_thenValueEvicted() {
+ LoadingCache cache = Caffeine.newBuilder()
+ .expireAfterAccess(5, TimeUnit.MINUTES)
+ .build(k -> DataObject.get("Data for " + k));
+
+ cache = Caffeine.newBuilder()
+ .expireAfterWrite(10, TimeUnit.SECONDS)
+ .weakKeys()
+ .weakValues()
+ .build(k -> DataObject.get("Data for " + k));
+
+ cache = Caffeine.newBuilder()
+ .expireAfterWrite(10, TimeUnit.SECONDS)
+ .softValues()
+ .build(k -> DataObject.get("Data for " + k));
+
+ cache = Caffeine.newBuilder().expireAfter(new Expiry() {
+ @Override
+ public long expireAfterCreate(@Nonnull String key, @Nonnull DataObject value, long currentTime) {
+ return value.getData().length() * 1000;
+ }
+
+ @Override
+ public long expireAfterUpdate(@Nonnull String key, @Nonnull DataObject value, long currentTime, long currentDuration) {
+ return currentDuration;
+ }
+
+ @Override
+ public long expireAfterRead(@Nonnull String key, @Nonnull DataObject value, long currentTime, long currentDuration) {
+ return currentDuration;
+ }
+ }).build(k -> DataObject.get("Data for " + k));
+
+ cache = Caffeine.newBuilder()
+ .refreshAfterWrite(1, TimeUnit.MINUTES)
+ .build(k -> DataObject.get("Data for " + k));
+ }
+
+ @Test
+ public void givenCache_whenStatsEnabled_thenStatsRecorded() {
+ LoadingCache cache = Caffeine.newBuilder()
+ .maximumSize(100)
+ .recordStats()
+ .build(k -> DataObject.get("Data for " + k));
+ cache.get("A");
+ cache.get("A");
+
+ assertEquals(1, cache.stats().hitCount());
+ assertEquals(1, cache.stats().missCount());
+ }
+}
\ No newline at end of file
From 5f1c2abc6e4ab166a6517b8f9b4fa1daceb3f03f Mon Sep 17 00:00:00 2001
From: ahmetcetin39 <30636222+ahmetcetin39@users.noreply.github.com>
Date: Wed, 11 Oct 2017 10:30:27 +0300
Subject: [PATCH 004/114] BAEL-1088 Jsp page changed to Thymeleaf page (#2706)
* add dependency to pom.xml about thymeleaf
* Update and rename viewPage.jsp to viewPage.html
---
spring-all/pom.xml | 8 ++++++--
spring-all/src/main/webapp/WEB-INF/view/viewPage.html | 9 +++++++++
spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp | 11 -----------
3 files changed, 15 insertions(+), 13 deletions(-)
create mode 100644 spring-all/src/main/webapp/WEB-INF/view/viewPage.html
delete mode 100644 spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp
diff --git a/spring-all/pom.xml b/spring-all/pom.xml
index 1ecb824c40..6615e1d6cd 100644
--- a/spring-all/pom.xml
+++ b/spring-all/pom.xml
@@ -195,7 +195,11 @@
spring-core
${org.springframework.version}
-
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
@@ -280,4 +284,4 @@
-
\ No newline at end of file
+
diff --git a/spring-all/src/main/webapp/WEB-INF/view/viewPage.html b/spring-all/src/main/webapp/WEB-INF/view/viewPage.html
new file mode 100644
index 0000000000..71f766407e
--- /dev/null
+++ b/spring-all/src/main/webapp/WEB-INF/view/viewPage.html
@@ -0,0 +1,9 @@
+
+
+
+ Title
+
+
+ Web Application. Passed parameter : th:text="${message}"
+
+
diff --git a/spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp b/spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp
deleted file mode 100644
index ca638b33f5..0000000000
--- a/spring-all/src/main/webapp/WEB-INF/view/viewPage.jsp
+++ /dev/null
@@ -1,11 +0,0 @@
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-
-
- Title
-
-
-
- Web Application. Passed parameter : ${message}
-
-
-
From 6655ca0ba1025966007bebcb16d8d185edebc97b Mon Sep 17 00:00:00 2001
From: araknoid
Date: Thu, 12 Oct 2017 10:03:29 +0200
Subject: [PATCH 005/114] RxJava Mathematical and Aggregate operators (#2697)
* RxJava Mathematical and Aggregate Operators
* Fixed test case names
* Resolved merge conflict
* Fixed test case names
---
rxjava/pom.xml | 6 +
.../operators/RxAggregateOperatorsTest.java | 210 ++++++++++++++++++
.../RxMathematicalOperatorsTest.java | 139 ++++++++++++
3 files changed, 355 insertions(+)
create mode 100644 rxjava/src/test/java/com/baeldung/rxjava/operators/RxAggregateOperatorsTest.java
create mode 100644 rxjava/src/test/java/com/baeldung/rxjava/operators/RxMathematicalOperatorsTest.java
diff --git a/rxjava/pom.xml b/rxjava/pom.xml
index 783833243b..0f950914ff 100644
--- a/rxjava/pom.xml
+++ b/rxjava/pom.xml
@@ -25,6 +25,12 @@
2.1.3
+
+ io.reactivex
+ rxjava-math
+ 1.0.0
+
+
com.jayway.awaitility
awaitility
diff --git a/rxjava/src/test/java/com/baeldung/rxjava/operators/RxAggregateOperatorsTest.java b/rxjava/src/test/java/com/baeldung/rxjava/operators/RxAggregateOperatorsTest.java
new file mode 100644
index 0000000000..1af41f795f
--- /dev/null
+++ b/rxjava/src/test/java/com/baeldung/rxjava/operators/RxAggregateOperatorsTest.java
@@ -0,0 +1,210 @@
+package com.baeldung.rxjava.operators;
+
+import org.junit.Test;
+import rx.Observable;
+import rx.observers.TestSubscriber;
+
+import java.util.*;
+
+public class RxAggregateOperatorsTest {
+
+ @Test
+ public void givenTwoObservable_whenConcatenatingThem_thenSuccessfull() {
+ // given
+ List listOne = Arrays.asList(1, 2, 3, 4);
+ Observable observableOne = Observable.from(listOne);
+
+ List listTwo = Arrays.asList(5, 6, 7, 8);
+ Observable observableTwo = Observable.from(listTwo);
+
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable concatObservable = observableOne.concatWith(observableTwo);
+
+ concatObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(8);
+ subscriber.assertValues(1, 2, 3, 4, 5, 6, 7, 8);
+
+ }
+
+ @Test
+ public void givenObservable_whenCounting_thenObtainingNumberOfElements() {
+ // given
+ List lettersList = Arrays.asList("A", "B", "C", "D", "E", "F", "G");
+
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable sourceObservable = Observable.from(lettersList)
+ .count();
+ sourceObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(1);
+ subscriber.assertValue(7);
+ }
+
+ @Test
+ public void givenObservable_whenReducing_thenObtainingInvertedConcatenatedString() {
+ // given
+ List list = Arrays.asList("A", "B", "C", "D", "E", "F", "G");
+
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable reduceObservable = Observable.from(list)
+ .reduce((letter1, letter2) -> letter2 + letter1);
+ reduceObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(1);
+ subscriber.assertValue("GFEDCBA");
+ }
+
+ @Test
+ public void givenObservable_whenCollecting_thenObtainingASet() {
+ // given
+ List list = Arrays.asList("A", "B", "C", "B", "B", "A", "D");
+
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable reduceListObservable = Observable.from(list)
+ .collect(() -> new HashSet(), (set, item) -> set.add(item));
+ reduceListObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(1);
+ subscriber.assertValues(new HashSet(list));
+ }
+
+ @Test
+ public void givenObservable_whenUsingToList_thenObtainedAList() {
+ // given
+ Observable sourceObservable = Observable.range(1, 5);
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable> listObservable = sourceObservable.toList();
+ listObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(1);
+ subscriber.assertValue(Arrays.asList(1, 2, 3, 4, 5));
+
+ }
+
+ @Test
+ public void givenObservable_whenUsingToSortedList_thenObtainedASortedList() {
+ // given
+ Observable sourceObservable = Observable.range(10, 5);
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable> listObservable = sourceObservable.toSortedList();
+ listObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(1);
+ subscriber.assertValue(Arrays.asList(10, 11, 12, 13, 14));
+ }
+
+ @Test
+ public void givenObservable_whenUsingToSortedListWithComparator_thenObtainedAnInverseSortedList() {
+ // given
+ Observable sourceObservable = Observable.range(10, 5);
+ TestSubscriber subscriber = TestSubscriber.create();
+
+ // when
+ Observable> listObservable = sourceObservable.toSortedList((int1, int2) -> int2 - int1);
+ listObservable.subscribe(subscriber);
+
+ // then
+ subscriber.assertCompleted();
+ subscriber.assertNoErrors();
+ subscriber.assertValueCount(1);
+ subscriber.assertValue(Arrays.asList(14, 13, 12, 11, 10));
+
+ }
+
+ @Test
+ public void givenObservable_whenUsingToMap_thenObtainedAMap() {
+ // given
+ Observable bookObservable = Observable.just(new Book("The North Water", 2016), new Book("Origin", 2017), new Book("Sleeping Beauties", 2017));
+ TestSubscriber