diff --git a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java
index e0ee8879a5c2..65d0eb6f588c 100644
--- a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java
+++ b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java
@@ -1,8 +1,9 @@
package com.baeldung.autofactory.provided;
+import com.baeldung.autofactory.model.Camera;
import com.google.auto.factory.AutoFactory;
import com.google.auto.factory.Provided;
-import javafx.scene.Camera;
+
import javax.inject.Provider;
diff --git a/core-groovy-collections/README.md b/core-groovy-collections/README.md
new file mode 100644
index 000000000000..482e33bce157
--- /dev/null
+++ b/core-groovy-collections/README.md
@@ -0,0 +1,6 @@
+# Groovy
+
+## Relevant articles:
+
+- [Maps in Groovy](http://www.baeldung.com/)
+
diff --git a/core-groovy-collections/pom.xml b/core-groovy-collections/pom.xml
new file mode 100644
index 000000000000..bf3ae26592f1
--- /dev/null
+++ b/core-groovy-collections/pom.xml
@@ -0,0 +1,131 @@
+
+
+ 4.0.0
+ core-groovy-collections
+ 1.0-SNAPSHOT
+ core-groovy-collections
+ jar
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.codehaus.groovy
+ groovy
+ ${groovy.version}
+
+
+ org.codehaus.groovy
+ groovy-all
+ ${groovy-all.version}
+ pom
+
+
+ org.codehaus.groovy
+ groovy-dateutil
+ ${groovy.version}
+
+
+ org.codehaus.groovy
+ groovy-sql
+ ${groovy-sql.version}
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+ org.hsqldb
+ hsqldb
+ ${hsqldb.version}
+ test
+
+
+ org.spockframework
+ spock-core
+ ${spock-core.version}
+ test
+
+
+
+
+
+
+ org.codehaus.gmavenplus
+ gmavenplus-plugin
+ ${gmavenplus-plugin.version}
+
+
+
+ addSources
+ addTestSources
+ compile
+ compileTests
+
+
+
+
+
+ maven-failsafe-plugin
+ ${maven-failsafe-plugin.version}
+
+
+ org.junit.platform
+ junit-platform-surefire-provider
+ ${junit.platform.version}
+
+
+
+
+ junit5
+
+ integration-test
+ verify
+
+
+
+ **/*Test5.java
+
+
+
+
+
+
+ maven-surefire-plugin
+ 2.20.1
+
+ false
+
+ **/*Test.java
+ **/*Spec.java
+
+
+
+
+
+
+
+
+ central
+ http://jcenter.bintray.com
+
+
+
+
+ 1.0.0
+ 2.5.6
+ 2.5.6
+ 2.5.6
+ 2.4.0
+ 1.1-groovy-2.4
+ 1.6
+
+
+
diff --git a/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy
new file mode 100644
index 000000000000..c6105eb1c4e3
--- /dev/null
+++ b/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy
@@ -0,0 +1,148 @@
+package com.baeldung.map;
+
+import static groovy.test.GroovyAssert.*
+import org.junit.Test
+
+class MapTest{
+
+ @Test
+ void createMap() {
+
+ def emptyMap = [:]
+ assertNotNull(emptyMap)
+
+ assertTrue(emptyMap instanceof java.util.LinkedHashMap)
+
+ def map = [name:"Jerry", age: 42, city: "New York"]
+ assertTrue(map.size() == 3)
+ }
+
+ @Test
+ void addItemsToMap() {
+
+ def map = [name:"Jerry"]
+
+ map["age"] = 42
+
+ map.city = "New York"
+
+ def hobbyLiteral = "hobby"
+ def hobbyMap = [(hobbyLiteral): "Singing"]
+ map.putAll(hobbyMap)
+
+ assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"])
+ assertTrue(hobbyMap.hobby == "Singing")
+ assertTrue(hobbyMap[hobbyLiteral] == "Singing")
+
+ map.plus([1:20]) // returns new map
+
+ map << [2:30]
+
+ }
+
+ @Test
+ void getItemsFromMap() {
+
+ def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]
+
+ assertTrue(map["name"] == "Jerry")
+
+ assertTrue(map.name == "Jerry")
+
+ def propertyAge = "age"
+ assertTrue(map[propertyAge] == 42)
+ }
+
+ @Test
+ void removeItemsFromMap() {
+
+ def map = [1:20, a:30, 2:42, 4:34, ba:67, 6:39, 7:49]
+
+ def minusMap = map.minus([2:42, 4:34]);
+ assertTrue(minusMap == [1:20, a:30, ba:67, 6:39, 7:49])
+
+ minusMap.removeAll{it -> it.key instanceof String}
+ assertTrue( minusMap == [ 1:20, 6:39, 7:49])
+
+ minusMap.retainAll{it -> it.value %2 == 0}
+ assertTrue( minusMap == [1:20])
+ }
+
+ @Test
+ void iteratingOnMaps(){
+ def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]
+
+ map.each{ entry -> println "$entry.key: $entry.value" }
+
+ map.eachWithIndex{ entry, i -> println "$i $entry.key: $entry.value" }
+
+ map.eachWithIndex{ key, value, i -> println "$i $key: $value" }
+ }
+
+ @Test
+ void filteringAndSearchingMaps(){
+ def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]
+
+ assertTrue(map.find{ it.value == "New York"}.key == "city")
+
+ assertTrue(map.findAll{ it.value == "New York"} == [city : "New York"])
+
+ map.grep{it.value == "New York"}.each{ it -> assertTrue(it.key == "city" && it.value == "New York")}
+
+ assertTrue(map.every{it -> it.value instanceof String} == false)
+
+ assertTrue(map.any{it -> it.value instanceof String} == true)
+ }
+
+ @Test
+ void collect(){
+
+ def map = [1: [name:"Jerry", age: 42, city: "New York"],
+ 2: [name:"Long", age: 25, city: "New York"],
+ 3: [name:"Dustin", age: 29, city: "New York"],
+ 4: [name:"Dustin", age: 34, city: "New York"]]
+
+ def names = map.collect{entry -> entry.value.name} // returns only list
+ assertTrue(names == ["Jerry", "Long", "Dustin", "Dustin"])
+
+ def uniqueNames = map.collect([] as HashSet){entry -> entry.value.name}
+ assertTrue(uniqueNames == ["Jerry", "Long", "Dustin"] as Set)
+
+ def idNames = map.collectEntries{key, value -> [key, value.name]}
+ assertTrue(idNames == [1:"Jerry", 2: "Long", 3:"Dustin", 4: "Dustin"])
+
+ def below30Names = map.findAll{it.value.age < 30}.collect{key, value -> value.name}
+ assertTrue(below30Names == ["Long", "Dustin"])
+
+
+ }
+
+ @Test
+ void group(){
+ def map = [1:20, 2: 40, 3: 11, 4: 93]
+
+ def subMap = map.groupBy{it.value % 2}
+ println subMap
+ assertTrue(subMap == [0:[1:20, 2:40 ], 1:[3:11, 4:93]])
+
+ def keySubMap = map.subMap([1, 2])
+ assertTrue(keySubMap == [1:20, 2:40])
+
+ }
+
+ @Test
+ void sorting(){
+ def map = [ab:20, a: 40, cb: 11, ba: 93]
+
+ def naturallyOrderedMap = map.sort()
+ assertTrue([a:40, ab:20, ba:93, cb:11] == naturallyOrderedMap)
+
+ def compSortedMap = map.sort({ k1, k2 -> k1 <=> k2 } as Comparator)
+ assertTrue([a:40, ab:20, ba:93, cb:11] == compSortedMap)
+
+ def cloSortedMap = map.sort({ it1, it2 -> it1.value <=> it1.value })
+ assertTrue([cb:11, ab:20, a:40, ba:93] == cloSortedMap)
+
+ }
+
+}
diff --git a/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy
new file mode 100644
index 000000000000..f1d528207fc6
--- /dev/null
+++ b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy
@@ -0,0 +1,148 @@
+package com.baeldung.groovy.map;
+
+import static groovy.test.GroovyAssert.*
+import org.junit.Test
+
+class MapTest{
+
+ @Test
+ void createMap() {
+
+ def emptyMap = [:]
+ assertNotNull(emptyMap)
+
+ assertTrue(emptyMap instanceof java.util.LinkedHashMap)
+
+ def map = [name:"Jerry", age: 42, city: "New York"]
+ assertTrue(map.size() == 3)
+ }
+
+ @Test
+ void addItemsToMap() {
+
+ def map = [name:"Jerry"]
+
+ map["age"] = 42
+
+ map.city = "New York"
+
+ def hobbyLiteral = "hobby"
+ def hobbyMap = [(hobbyLiteral): "Singing"]
+ map.putAll(hobbyMap)
+
+ assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"])
+ assertTrue(hobbyMap.hobby == "Singing")
+ assertTrue(hobbyMap[hobbyLiteral] == "Singing")
+
+ map.plus([1:20]) // returns new map
+
+ map << [2:30]
+
+ }
+
+ @Test
+ void getItemsFromMap() {
+
+ def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]
+
+ assertTrue(map["name"] == "Jerry")
+
+ assertTrue(map.name == "Jerry")
+
+ def propertyAge = "age"
+ assertTrue(map[propertyAge] == 42)
+ }
+
+ @Test
+ void removeItemsFromMap() {
+
+ def map = [1:20, a:30, 2:42, 4:34, ba:67, 6:39, 7:49]
+
+ def minusMap = map.minus([2:42, 4:34]);
+ assertTrue(minusMap == [1:20, a:30, ba:67, 6:39, 7:49])
+
+ minusMap.removeAll{it -> it.key instanceof String}
+ assertTrue( minusMap == [ 1:20, 6:39, 7:49])
+
+ minusMap.retainAll{it -> it.value %2 == 0}
+ assertTrue( minusMap == [1:20])
+ }
+
+ @Test
+ void iteratingOnMaps(){
+ def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]
+
+ map.each{ entry -> println "$entry.key: $entry.value" }
+
+ map.eachWithIndex{ entry, i -> println "$i $entry.key: $entry.value" }
+
+ map.eachWithIndex{ key, value, i -> println "$i $key: $value" }
+ }
+
+ @Test
+ void filteringAndSearchingMaps(){
+ def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]
+
+ assertTrue(map.find{ it.value == "New York"}.key == "city")
+
+ assertTrue(map.findAll{ it.value == "New York"} == [city : "New York"])
+
+ map.grep{it.value == "New York"}.each{ it -> assertTrue(it.key == "city" && it.value == "New York")}
+
+ assertTrue(map.every{it -> it.value instanceof String} == false)
+
+ assertTrue(map.any{it -> it.value instanceof String} == true)
+ }
+
+ @Test
+ void collect(){
+
+ def map = [1: [name:"Jerry", age: 42, city: "New York"],
+ 2: [name:"Long", age: 25, city: "New York"],
+ 3: [name:"Dustin", age: 29, city: "New York"],
+ 4: [name:"Dustin", age: 34, city: "New York"]]
+
+ def names = map.collect{entry -> entry.value.name} // returns only list
+ assertTrue(names == ["Jerry", "Long", "Dustin", "Dustin"])
+
+ def uniqueNames = map.collect([] as HashSet){entry -> entry.value.name}
+ assertTrue(uniqueNames == ["Jerry", "Long", "Dustin"] as Set)
+
+ def idNames = map.collectEntries{key, value -> [key, value.name]}
+ assertTrue(idNames == [1:"Jerry", 2: "Long", 3:"Dustin", 4: "Dustin"])
+
+ def below30Names = map.findAll{it.value.age < 30}.collect{key, value -> value.name}
+ assertTrue(below30Names == ["Long", "Dustin"])
+
+
+ }
+
+ @Test
+ void group(){
+ def map = [1:20, 2: 40, 3: 11, 4: 93]
+
+ def subMap = map.groupBy{it.value % 2}
+ println subMap
+ assertTrue(subMap == [0:[1:20, 2:40 ], 1:[3:11, 4:93]])
+
+ def keySubMap = map.subMap([1, 2])
+ assertTrue(keySubMap == [1:20, 2:40])
+
+ }
+
+ @Test
+ void sorting(){
+ def map = [ab:20, a: 40, cb: 11, ba: 93]
+
+ def naturallyOrderedMap = map.sort()
+ assertTrue([a:40, ab:20, ba:93, cb:11] == naturallyOrderedMap)
+
+ def compSortedMap = map.sort({ k1, k2 -> k1 <=> k2 } as Comparator)
+ assertTrue([a:40, ab:20, ba:93, cb:11] == compSortedMap)
+
+ def cloSortedMap = map.sort({ it1, it2 -> it1.value <=> it1.value })
+ assertTrue([cb:11, ab:20, a:40, ba:93] == cloSortedMap)
+
+ }
+
+}
diff --git a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java b/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java
index 4cb2551faeb5..bd7943c77bb5 100644
--- a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java
+++ b/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java
@@ -27,34 +27,35 @@ public void whenCreatesEmptyOptional_thenCorrect() {
@Test
public void givenNonNull_whenCreatesNonNullable_thenCorrect() {
String name = "baeldung";
- Optional.of(name);
+ Optional opt = Optional.of(name);
+ assertTrue(opt.isPresent());
}
@Test(expected = NullPointerException.class)
public void givenNull_whenThrowsErrorOnCreate_thenCorrect() {
String name = null;
- Optional opt = Optional.of(name);
+ Optional.of(name);
}
@Test
public void givenNonNull_whenCreatesOptional_thenCorrect() {
String name = "baeldung";
Optional opt = Optional.of(name);
- assertEquals("Optional[baeldung]", opt.toString());
+ assertTrue(opt.isPresent());
}
@Test
public void givenNonNull_whenCreatesNullable_thenCorrect() {
String name = "baeldung";
Optional opt = Optional.ofNullable(name);
- assertEquals("Optional[baeldung]", opt.toString());
+ assertTrue(opt.isPresent());
}
@Test
public void givenNull_whenCreatesNullable_thenCorrect() {
String name = null;
Optional opt = Optional.ofNullable(name);
- assertEquals("Optional.empty", opt.toString());
+ assertFalse(opt.isPresent());
}
// Checking Value With isPresent()
diff --git a/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java b/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java
new file mode 100644
index 000000000000..dcd61cdfa787
--- /dev/null
+++ b/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java
@@ -0,0 +1,34 @@
+package com.baeldung.array;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class AddElementToEndOfArray {
+
+ public Integer[] addElementUsingArraysCopyOf(Integer[] srcArray, int elementToAdd) {
+ Integer[] destArray = Arrays.copyOf(srcArray, srcArray.length + 1);
+
+ destArray[destArray.length - 1] = elementToAdd;
+ return destArray;
+ }
+
+ public Integer[] addElementUsingArrayList(Integer[] srcArray, int elementToAdd) {
+ Integer[] destArray = new Integer[srcArray.length + 1];
+
+ ArrayList arrayList = new ArrayList<>(Arrays.asList(srcArray));
+ arrayList.add(elementToAdd);
+
+ return arrayList.toArray(destArray);
+ }
+
+ public Integer[] addElementUsingSystemArrayCopy(Integer[] srcArray, int elementToAdd) {
+ Integer[] destArray = new Integer[srcArray.length + 1];
+
+ System.arraycopy(srcArray, 0, destArray, 0, srcArray.length);
+
+ destArray[destArray.length - 1] = elementToAdd;
+
+ return destArray;
+ }
+
+}
diff --git a/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java
new file mode 100644
index 000000000000..f6f1f954f647
--- /dev/null
+++ b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java
@@ -0,0 +1,49 @@
+package com.baeldung.array;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+
+public class AddElementToEndOfArrayUnitTest {
+
+ AddElementToEndOfArray addElementToEndOfArray;
+
+ @Before
+ public void init() {
+ addElementToEndOfArray = new AddElementToEndOfArray();
+ }
+
+ @Test
+ public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded() {
+ Integer[] sourceArray = {1, 2, 3, 4};
+ int elementToAdd = 5;
+
+ Integer[] destArray = addElementToEndOfArray.addElementUsingArraysCopyOf(sourceArray, elementToAdd);
+
+ Integer[] expectedArray = {1, 2, 3, 4, 5};
+ assertArrayEquals(expectedArray, destArray);
+ }
+
+ @Test
+ public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded() {
+ Integer[] sourceArray = {1, 2, 3, 4};
+ int elementToAdd = 5;
+
+ Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd);
+
+ Integer[] expectedArray = {1, 2, 3, 4, 5};
+ assertArrayEquals(expectedArray, destArray);
+ }
+
+ @Test
+ public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded() {
+ Integer[] sourceArray = {1, 2, 3, 4};
+ int elementToAdd = 5;
+
+ Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd);
+
+ Integer[] expectedArray = {1, 2, 3, 4, 5};
+ assertArrayEquals(expectedArray, destArray);
+ }
+}
diff --git a/core-java-collections-map/README.md b/core-java-collections-map/README.md
deleted file mode 100644
index da02928118d4..000000000000
--- a/core-java-collections-map/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-=========
-
-## Core Java Collections 2
-
-### Relevant Articles:
-- Java - Copying a HashMap
diff --git a/core-java-collections-map/pom.xml b/core-java-collections-map/pom.xml
deleted file mode 100644
index 8c0aef54bf8c..000000000000
--- a/core-java-collections-map/pom.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-
- 4.0.0
- core-java-collections-map
- 0.1.0-SNAPSHOT
- core-java-collections-map
- jar
-
-
- com.baeldung
- parent-java
- 0.0.1-SNAPSHOT
- ../parent-java
-
-
-
-
- org.apache.commons
- commons-collections4
- ${commons-collections4.version}
-
-
- org.apache.commons
- commons-lang3
- ${commons-lang3.version}
-
-
- org.eclipse.collections
- eclipse-collections
- ${eclipse.collections.version}
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
- org.junit.platform
- junit-platform-runner
- ${junit.platform.version}
- test
-
-
- org.openjdk.jmh
- jmh-core
- ${openjdk.jmh.version}
-
-
- org.openjdk.jmh
- jmh-generator-annprocess
- ${openjdk.jmh.version}
-
-
- org.apache.commons
- commons-exec
- ${commons-exec.version}
-
-
- org.projectlombok
- lombok
- ${lombok.version}
- provided
-
-
-
-
- 1.19
- 1.2.0
- 3.8.1
- 4.1
- 4.01
- 1.7.0
- 3.11.1
- 7.1.0
- 1.3
-
-
diff --git a/core-java-collections-set/README.md b/core-java-collections-set/README.md
new file mode 100644
index 000000000000..710484a2e1f6
--- /dev/null
+++ b/core-java-collections-set/README.md
@@ -0,0 +1,6 @@
+=========
+
+## Core Java Sets Cookbooks and Examples
+
+### Relevant Articles:
+- [Set Operations in Java](http://www.baeldung.com/set-operations-in-java)
diff --git a/core-java-collections-set/pom.xml b/core-java-collections-set/pom.xml
new file mode 100644
index 000000000000..d5f79376457c
--- /dev/null
+++ b/core-java-collections-set/pom.xml
@@ -0,0 +1,33 @@
+
+ 4.0.0
+ core-java-collections-set
+ 0.1.0-SNAPSHOT
+ core-java-collections-set
+ jar
+
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+
+
+ 4.3
+ 27.1-jre
+
+
diff --git a/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java b/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java
new file mode 100644
index 000000000000..7c25585e4988
--- /dev/null
+++ b/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java
@@ -0,0 +1,93 @@
+package com.baeldung.set;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.collections4.SetUtils;
+import org.junit.Test;
+
+import com.google.common.collect.Sets;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class SetOperationsUnitTest {
+
+ private Set setA = setOf(1,2,3,4);
+ private Set setB = setOf(2,4,6,8);
+
+ private static Set setOf(Integer... values) {
+ return new HashSet(Arrays.asList(values));
+ }
+
+ @Test
+ public void givenTwoSets_WhenWeRetainAll_ThenWeIntersectThem() {
+ Set intersectSet = new HashSet<>(setA);
+ intersectSet.retainAll(setB);
+ assertEquals(setOf(2,4), intersectSet);
+ }
+
+ @Test
+ public void givenTwoSets_WhenWeAddAll_ThenWeUnionThem() {
+ Set unionSet = new HashSet<>(setA);
+ unionSet.addAll(setB);
+ assertEquals(setOf(1,2,3,4,6,8), unionSet);
+ }
+
+ @Test
+ public void givenTwoSets_WhenRemoveAll_ThenWeGetTheDifference() {
+ Set differenceSet = new HashSet<>(setA);
+ differenceSet.removeAll(setB);
+ assertEquals(setOf(1,3), differenceSet);
+ }
+
+ @Test
+ public void givenTwoStreams_WhenWeFilterThem_ThenWeCanGetTheIntersect() {
+ Set intersectSet = setA.stream()
+ .filter(setB::contains)
+ .collect(Collectors.toSet());
+ assertEquals(setOf(2,4), intersectSet);
+ }
+
+ @Test
+ public void givenTwoStreams_WhenWeConcatThem_ThenWeGetTheUnion() {
+ Set unionSet = Stream.concat(setA.stream(), setB.stream())
+ .collect(Collectors.toSet());
+ assertEquals(setOf(1,2,3,4,6,8), unionSet);
+ }
+
+ @Test
+ public void givenTwoStreams_WhenWeFilterThem_ThenWeCanGetTheDifference() {
+ Set differenceSet = setA.stream()
+ .filter(val -> !setB.contains(val))
+ .collect(Collectors.toSet());
+ assertEquals(setOf(1,3), differenceSet);
+ }
+
+ @Test
+ public void givenTwoSets_WhenWeUseApacheCommonsIntersect_ThenWeGetTheIntersect() {
+ Set intersectSet = SetUtils.intersection(setA, setB);
+ assertEquals(setOf(2,4), intersectSet);
+ }
+
+ @Test
+ public void givenTwoSets_WhenWeUseApacheCommonsUnion_ThenWeGetTheUnion() {
+ Set unionSet = SetUtils.union(setA, setB);
+ assertEquals(setOf(1,2,3,4,6,8), unionSet);
+ }
+
+
+ @Test
+ public void givenTwoSets_WhenWeUseGuavaIntersect_ThenWeGetTheIntersect() {
+ Set intersectSet = Sets.intersection(setA, setB);
+ assertEquals(setOf(2,4), intersectSet);
+ }
+
+ @Test
+ public void givenTwoSets_WhenWeUseGuavaUnion_ThenWeGetTheUnion() {
+ Set unionSet = Sets.union(setA, setB);
+ assertEquals(setOf(1,2,3,4,6,8), unionSet);
+ }
+}
diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml
new file mode 100644
index 000000000000..ad49cceb9d5e
--- /dev/null
+++ b/core-java-modules/pom.xml
@@ -0,0 +1,19 @@
+
+
+ 4.0.0
+ core-java-modules
+ core-java-modules
+ pom
+
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+
+
+
+ pre-jpms
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/pre-jpms/pom.xml b/core-java-modules/pre-jpms/pom.xml
new file mode 100644
index 000000000000..169cd21f3efe
--- /dev/null
+++ b/core-java-modules/pre-jpms/pom.xml
@@ -0,0 +1,74 @@
+
+ 4.0.0
+ pre-jpms
+ 0.0.1-SNAPSHOT
+ jar
+ pre-jpms
+
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+ ../../
+
+
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.25
+
+
+
+ pre-jpms
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.0
+
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.1.1
+
+
+ copy-dependencies
+ package
+
+ copy-dependencies
+
+
+
+ ${project.build.directory}/dependency-jars/
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ com.baeldung.prejpms.App
+ true
+ dependency-jars/
+
+
+
+
+
+
+
+
+ UTF-8
+
+
diff --git a/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java
new file mode 100644
index 000000000000..1afaae30e41a
--- /dev/null
+++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java
@@ -0,0 +1,77 @@
+package com.baeldung.prejpms;
+
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.crypto.provider.SunJCE;
+
+import sun.misc.BASE64Encoder;
+import sun.reflect.Reflection;
+
+public class App {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
+
+ public static void main(String[] args) throws Exception {
+
+ getCrytpographyProviderName();
+ getCallStackClassNames();
+ getXmlFromObject(new Book(100, "Java Modules Architecture"));
+ getBase64EncodedString("Java");
+ }
+
+ private static void getCrytpographyProviderName() {
+ try {
+ LOGGER.info("1. JCE Provider Name: {}\n", new SunJCE().getName());
+ } catch (Throwable e) {
+ LOGGER.error(e.toString());
+ }
+ }
+
+ private static void getCallStackClassNames() {
+ try {
+ StringBuffer sbStack = new StringBuffer();
+ int i = 0;
+ Class> caller = Reflection.getCallerClass(i++);
+ do {
+ sbStack.append(i + ".")
+ .append(caller.getName())
+ .append("\n");
+ caller = Reflection.getCallerClass(i++);
+ } while (caller != null);
+ LOGGER.info("2. Call Stack:\n{}", sbStack);
+ } catch (Throwable e) {
+ LOGGER.error(e.toString());
+ }
+ }
+
+ private static void getXmlFromObject(Book book) {
+ try {
+ Marshaller marshallerObj = JAXBContext.newInstance(Book.class)
+ .createMarshaller();
+ marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+
+ StringWriter sw = new StringWriter();
+ marshallerObj.marshal(book, sw);
+ LOGGER.info("3. Xml for Book object:\n{}", sw);
+ } catch (Throwable e) {
+ LOGGER.error(e.toString());
+ }
+
+ }
+
+ private static void getBase64EncodedString(String inputString) {
+ try {
+ String encodedString = new BASE64Encoder().encode(inputString.getBytes());
+ LOGGER.info("4. Base Encoded String: {}", encodedString);
+ } catch (Throwable e) {
+ LOGGER.error(e.toString());
+ }
+ }
+}
diff --git a/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java
new file mode 100644
index 000000000000..6780c737388d
--- /dev/null
+++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java
@@ -0,0 +1,37 @@
+package com.baeldung.prejpms;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "book")
+public class Book {
+ private long id;
+ private String name;
+
+ public Book() {
+ }
+
+ public Book(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @XmlElement(name = "title")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+}
diff --git a/core-java-modules/pre-jpms/src/main/resources/logback.xml b/core-java-modules/pre-jpms/src/main/resources/logback.xml
new file mode 100644
index 000000000000..7c5914e58e12
--- /dev/null
+++ b/core-java-modules/pre-jpms/src/main/resources/logback.xml
@@ -0,0 +1,10 @@
+
+
+
+ [%level] %msg%n
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core-kotlin-io/pom.xml b/core-kotlin-io/pom.xml
index 2e21079d7f94..a0b688a223cd 100644
--- a/core-kotlin-io/pom.xml
+++ b/core-kotlin-io/pom.xml
@@ -20,9 +20,21 @@
${kotlin.version}
- org.junit.platform
- junit-platform-runner
- ${junit.platform.version}
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.jupiter.version}
+ test
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+ net.bytebuddy
+ byte-buddy
+ ${byte-buddy.version}
test
@@ -37,6 +49,12 @@
${kotlin.version}
test
+
+ org.jetbrains.kotlin
+ kotlin-test-junit5
+ ${kotlin.version}
+ test
+
@@ -69,10 +87,11 @@
- 1.2.71
- 1.1.1
- 5.2.0
+ 1.3.30
+ 5.4.2
+ 2.27.0
+ 1.9.12
3.10.0
-
\ No newline at end of file
+
diff --git a/core-kotlin-2/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt b/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt
similarity index 100%
rename from core-kotlin-2/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt
rename to core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt
diff --git a/core-kotlin-2/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
similarity index 100%
rename from core-kotlin-2/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
rename to core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt
new file mode 100644
index 000000000000..3f9922b88b3e
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt
@@ -0,0 +1,31 @@
+package com.baeldung.jvmannotations
+
+import java.util.*
+
+interface Document {
+
+ @JvmDefault
+ fun getType() = "document"
+}
+
+class TextDocument : Document {
+ override fun getType() = "text"
+
+ fun transformList(list : List) : List {
+ return list.filter { n -> n.toInt() > 1 }
+ }
+
+ fun transformListInverseWildcards(list : List<@JvmSuppressWildcards Number>) : List<@JvmWildcard Number> {
+ return list.filter { n -> n.toInt() > 1 }
+ }
+
+ var list : List<@JvmWildcard Any> = ArrayList()
+}
+
+class XmlDocument(d : Document) : Document by d
+
+fun main() {
+ val myDocument = TextDocument()
+ val myTextDocument = XmlDocument(myDocument)
+ println("${myDocument.getType()} ${myTextDocument.getType()}")
+}
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java
new file mode 100644
index 000000000000..feb71772cb5a
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java
@@ -0,0 +1,9 @@
+package com.baeldung.jvmannotations;
+
+public class HtmlDocument implements Document {
+
+ @Override
+ public String getType() {
+ return "HTML";
+ }
+}
\ No newline at end of file
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt
new file mode 100644
index 000000000000..80180bd92477
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt
@@ -0,0 +1,66 @@
+@file:JvmName("MessageHelper")
+@file:JvmMultifileClass //used
+package com.baeldung.jvmannotations
+
+import java.util.*
+
+@JvmName("getMyUsername")
+fun getMyName() : String {
+ return "myUserId"
+}
+
+object MessageBroker {
+ @JvmStatic
+ var totalMessagesSent = 0
+
+ const val maxMessageLength = 0
+
+ @JvmStatic
+ fun clearAllMessages() {
+ }
+
+ @JvmStatic
+ @JvmOverloads
+ @Throws(Exception::class)
+ fun findMessages(sender : String, type : String = "text", maxResults : Int = 10) : List {
+ if(sender.isEmpty()) {
+ throw Exception()
+ }
+ return ArrayList()
+ }
+}
+
+class Message {
+
+ // this would cause a compilation error since sender is immutable
+ // @set:JvmName("setSender")
+ val sender = "myself"
+
+ // this works as name is overridden
+ @JvmName("getSenderName")
+ fun getSender() : String = "from:$sender"
+
+ @get:JvmName("getReceiverName")
+ @set:JvmName("setReceiverName")
+ var receiver : String = ""
+
+ @get:JvmName("getContent")
+ @set:JvmName("setContent")
+ var text = ""
+
+ // generates a warning
+ @get:JvmName("getId")
+ private val id = 0
+
+ @get:JvmName("hasAttachment")
+ var hasAttachment = true
+
+ var isEncrypted = true
+
+ fun setReceivers(receiverNames : List) {
+ }
+
+ @JvmName("setReceiverIds")
+ fun setReceivers(receiverNames : List) {
+ }
+}
\ No newline at end of file
diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt
new file mode 100644
index 000000000000..3b19b12e1053
--- /dev/null
+++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt
@@ -0,0 +1,6 @@
+@file:JvmMultifileClass
+@file:JvmName("MessageHelper") //applies to all top level functions / variables / constants
+package com.baeldung.jvmannotations
+
+fun convert(message: Message) {
+}
diff --git a/fastUtil/pom.xml b/fastUtil/pom.xml
new file mode 100644
index 000000000000..fcd902074788
--- /dev/null
+++ b/fastUtil/pom.xml
@@ -0,0 +1,44 @@
+
+
+ 4.0.0
+
+ com.baeldung
+ fastUtil
+ 1.0-SNAPSHOT
+
+
+
+
+ it.unimi.dsi
+ fastutil
+ 8.2.2
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+ org.openjdk.jmh
+ jmh-core
+ 1.19
+ test
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ 1.19
+ test
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java b/fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java
new file mode 100644
index 000000000000..a794d1a2f646
--- /dev/null
+++ b/fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung;
+
+import it.unimi.dsi.fastutil.ints.IntBigArrays;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+public class BigArraysUnitTest {
+
+ @Test
+ public void givenValidAray_whenWrapped_checkAccessFromIntBigArraysMethodsCorrect() {
+ int[] oneDArray = new int[] { 2, 1, 5, 2, 1, 7 };
+ int[][] twoDArray = IntBigArrays.wrap(oneDArray.clone());
+
+ int firstIndex = IntBigArrays.get(twoDArray, 0);
+ int lastIndex = IntBigArrays.get(twoDArray, IntBigArrays.length(twoDArray)-1);
+
+ assertEquals(2, firstIndex);
+ assertEquals(7, lastIndex);
+
+ }
+
+}
diff --git a/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java
new file mode 100644
index 000000000000..2c77989fe58e
--- /dev/null
+++ b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java
@@ -0,0 +1,58 @@
+package com.baeldung;
+
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+public class FastUtilTypeSpecificBenchmarkUnitTest {
+
+ @Param({"100", "1000", "10000", "100000"})
+ public int setSize;
+
+ @Benchmark
+ public IntSet givenFastUtilsIntSetWithInitialSizeSet_whenPopulated_checkTimeTaken() {
+ IntSet intSet = new IntOpenHashSet(setSize);
+ for(int i = 0; i < setSize; i++){
+ intSet.add(i);
+ }
+ return intSet;
+ }
+
+
+ @Benchmark
+ public Set givenCollectionsHashSetWithInitialSizeSet_whenPopulated_checkTimeTaken() {
+ Set intSet = new HashSet(setSize);
+ for(int i = 0; i < setSize; i++){
+ intSet.add(i);
+ }
+ return intSet;
+ }
+
+ public static void main(String... args) throws RunnerException {
+ Options opts = new OptionsBuilder()
+ .include(".*")
+ .warmupIterations(1)
+ .measurementIterations(2)
+ .jvmArgs("-Xms2g", "-Xmx2g")
+ .shouldDoGC(true)
+ .forks(1)
+ .build();
+
+ new Runner(opts).run();
+ }
+
+
+
+
+}
diff --git a/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java
new file mode 100644
index 000000000000..61295cc6f1ba
--- /dev/null
+++ b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java
@@ -0,0 +1,20 @@
+package com.baeldung;
+
+import it.unimi.dsi.fastutil.doubles.Double2DoubleMap;
+import it.unimi.dsi.fastutil.doubles.Double2DoubleOpenHashMap;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+
+public class FastUtilTypeSpecificUnitTest {
+
+ @Test
+ public void givenValidDouble2DoubleMap_whenContentsQueried_checkCorrect(){
+ Double2DoubleMap d2dMap = new Double2DoubleOpenHashMap();
+ d2dMap.put(2.0, 5.5);
+ d2dMap.put(3.0, 6.6);
+ assertEquals(5.5, d2dMap.get(2.0));
+ }
+
+}
diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md
index b4d8d619934f..492f3bc5b4f5 100644
--- a/httpclient-simple/README.md
+++ b/httpclient-simple/README.md
@@ -9,4 +9,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code)
- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)
-- [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout)
\ No newline at end of file
+- [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout)
+- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies)
+- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header)
+- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication)
+- [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request)
diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java
similarity index 100%
rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java
rename to httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java
diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java
similarity index 100%
rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java
rename to httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java
diff --git a/httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java
similarity index 100%
rename from httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java
rename to httpclient-simple/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java
diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java
similarity index 96%
rename from httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java
rename to httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java
index c9956e58526f..96278b481a6e 100644
--- a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java
+++ b/httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java
@@ -23,19 +23,18 @@
import org.junit.Test;
import java.io.IOException;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/*
- * NOTE : Need module spring-security-rest-basic-auth to be running
+ * NOTE : Need module httpclient-simple to be running
*/
public class HttpClientAuthLiveTest {
- private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8081/spring-security-rest-basic-auth/api/foos/1";
+ private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8082/httpclient-simple/api/foos/1";
private static final String DEFAULT_USER = "user1";
private static final String DEFAULT_PASS = "user1Pass";
@@ -111,7 +110,7 @@ private CredentialsProvider provider() {
}
private HttpContext context() {
- final HttpHost targetHost = new HttpHost("localhost", 8080, "http");
+ final HttpHost targetHost = new HttpHost("localhost", 8082, "http");
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS));
diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java
similarity index 100%
rename from httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java
rename to httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java
diff --git a/httpclient/README.md b/httpclient/README.md
index ce98d7e72ef4..a5fc29b0899b 100644
--- a/httpclient/README.md
+++ b/httpclient/README.md
@@ -7,13 +7,10 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
-- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies)
- [HttpClient 4 – Cancel Request](http://www.baeldung.com/httpclient-cancel-request)
- [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4)
- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient)
- [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post)
-- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header)
-- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication)
- [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload)
- [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial)
- [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide)
diff --git a/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java b/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java
index 5be4121bc70f..1de600aebf5b 100644
--- a/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java
+++ b/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java
@@ -33,9 +33,6 @@ public static void setUpClass() {
srcCollection.add(sam);
srcCollection.add(alice);
srcCollection.add(buffy);
-
- // make sure the collection isn't sorted accidentally
- assertFalse("Oops: source collection is already sorted!", isSorted(srcCollection));
}
/**
diff --git a/java-collections-maps-2/pom.xml b/java-collections-maps-2/pom.xml
index 4ab94a7ae3ff..5f27eaa2d8b3 100644
--- a/java-collections-maps-2/pom.xml
+++ b/java-collections-maps-2/pom.xml
@@ -36,6 +36,17 @@
colt
${colt.version}
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
@@ -43,6 +54,8 @@
3.0.2
8.1.0
1.2.0
+ 3.8.1
+ 3.11.1
\ No newline at end of file
diff --git a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java b/java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java
similarity index 98%
rename from core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java
rename to java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java
index e1649f593c38..2ebc9413c805 100644
--- a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java
+++ b/java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java
@@ -1,4 +1,4 @@
-package com.baeldung.copyinghashmap;
+package com.baeldung.map;
import java.util.HashMap;
import java.util.Map;
diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java b/java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java
similarity index 98%
rename from core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java
rename to java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java
index 400696d97a1d..c400eea1531c 100644
--- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java
+++ b/java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.copyinghashmap;
+package com.baeldung.map;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java b/java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java
similarity index 91%
rename from core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java
rename to java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java
index b47fdc768e74..7963fa811c24 100644
--- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java
+++ b/java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java
@@ -1,4 +1,4 @@
-package com.baeldung.copyinghashmap;
+package com.baeldung.map;
import java.io.Serializable;
diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml
index a839f56b56cf..965cb195bf24 100644
--- a/libraries-2/pom.xml
+++ b/libraries-2/pom.xml
@@ -30,6 +30,16 @@
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+
+
+ io.github.classgraph
+ classgraph
+ ${classgraph.version}
+
org.jbpm
jbpm-test
@@ -38,6 +48,8 @@
+ 3.6.2
+ 4.8.22
6.0.0.Final
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java
new file mode 100644
index 000000000000..3dc99e6a3288
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java
@@ -0,0 +1,74 @@
+package com.baeldung.classgraph;
+
+import io.github.classgraph.*;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.function.Consumer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ClassGraphUnitTest {
+
+ @Test
+ public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
+ doTest(result -> {
+ ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName());
+ assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName());
+ });
+ }
+
+ @Test
+ public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
+ doTest(result -> {
+ ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName());
+ assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName());
+ });
+ }
+
+ @Test
+ public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() {
+ doTest(result -> {
+ ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName());
+ ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> {
+ return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> {
+ AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName());
+ if (annotationInfo == null) {
+ return false;
+ }
+
+ return "web".equals(annotationInfo.getParameterValues().getValue("value"));
+ });
+ });
+ assertThat(filteredClassInfos)
+ .extracting(ClassInfo::getName)
+ .contains(MethodWithAnnotationParameterWeb.class.getName());
+ });
+ }
+
+ @Test
+ public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
+ doTest(result -> {
+ ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName());
+ assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName());
+ });
+ }
+
+ @Test
+ public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException {
+ try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) {
+ ResourceList resources = result.getResourcesWithExtension("config");
+ assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config");
+ assertThat(resources.get(0).getContentAsString()).isEqualTo("my data");
+ }
+ }
+
+ private void doTest(Consumer checker) {
+ try (ScanResult result = new ClassGraph().enableAllInfo()
+ .whitelistPackages(getClass().getPackage().getName())
+ .scan())
+ {
+ checker.accept(result);
+ }
+ }
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java
new file mode 100644
index 000000000000..fe476769a64e
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java
@@ -0,0 +1,5 @@
+package com.baeldung.classgraph;
+
+@TestAnnotation
+public class ClassWithAnnotation {
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java
new file mode 100644
index 000000000000..f72a7621f96f
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java
@@ -0,0 +1,7 @@
+package com.baeldung.classgraph;
+
+public class FieldWithAnnotation {
+
+ @TestAnnotation
+ private String s;
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java
new file mode 100644
index 000000000000..29a59c09ea42
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java
@@ -0,0 +1,8 @@
+package com.baeldung.classgraph;
+
+public class MethodWithAnnotation {
+
+ @TestAnnotation
+ public void service() {
+ }
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java
new file mode 100644
index 000000000000..f01c2743eb29
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java
@@ -0,0 +1,8 @@
+package com.baeldung.classgraph;
+
+public class MethodWithAnnotationParameterDao {
+
+ @TestAnnotation("dao")
+ public void service() {
+ }
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java
new file mode 100644
index 000000000000..bf01f7d23cff
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java
@@ -0,0 +1,8 @@
+package com.baeldung.classgraph;
+
+public class MethodWithAnnotationParameterWeb {
+
+ @TestAnnotation("web")
+ public void service() {
+ }
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java
new file mode 100644
index 000000000000..e3f5df92ed5c
--- /dev/null
+++ b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java
@@ -0,0 +1,14 @@
+package com.baeldung.classgraph;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.*;
+
+@Target({TYPE, METHOD, FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TestAnnotation {
+
+ String value() default "";
+}
\ No newline at end of file
diff --git a/libraries-2/src/test/resources/classgraph/my.config b/libraries-2/src/test/resources/classgraph/my.config
new file mode 100644
index 000000000000..b99df573f6d3
--- /dev/null
+++ b/libraries-2/src/test/resources/classgraph/my.config
@@ -0,0 +1 @@
+my data
\ No newline at end of file
diff --git a/libraries-security/README.md b/libraries-security/README.md
index 6923e0474efa..b9bbf11cdf02 100644
--- a/libraries-security/README.md
+++ b/libraries-security/README.md
@@ -2,3 +2,4 @@
- [Guide to ScribeJava](https://www.baeldung.com/scribejava)
- [Guide to Passay](https://www.baeldung.com/java-passay)
+- [Guide to Google Tink](https://www.baeldung.com/google-tink)
diff --git a/maven-java-11/multimodule-maven-project/daomodule/pom.xml b/maven-java-11/multimodule-maven-project/daomodule/pom.xml
new file mode 100644
index 000000000000..de9be656d41d
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/daomodule/pom.xml
@@ -0,0 +1,14 @@
+
+
+ 4.0.0
+
+ com.baeldung.multimodule-maven-project
+ multimodule-maven-project
+ 1.0
+
+ com.baeldung.daomodule
+ daomodule
+ jar
+ 1.0
+ daomodule
+
diff --git a/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java
new file mode 100644
index 000000000000..f86ae8abb38d
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java
@@ -0,0 +1,12 @@
+package com.baeldung.dao;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface Dao {
+
+ Optional findById(int id);
+
+ List findAll();
+
+}
diff --git a/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java
new file mode 100644
index 000000000000..072d7ad0074d
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java
@@ -0,0 +1,3 @@
+module com.baeldung.dao {
+ exports com.baeldung.dao;
+}
diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml b/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml
new file mode 100644
index 000000000000..8e700e62b52c
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml
@@ -0,0 +1,18 @@
+
+
+ 4.0.0
+
+ com.baeldung.multimodule-maven-project
+ multimodule-maven-project
+ 1.0
+
+ com.baeldung.entitymodule
+ entitymodule
+ jar
+ 1.0
+ entitymodule
+
+ 11
+ 11
+
+
diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java
new file mode 100644
index 000000000000..22022a2e6d26
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java
@@ -0,0 +1,19 @@
+package com.baeldung.entity;
+
+public class User {
+
+ private final String name;
+
+ public User(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" + "name=" + name + '}';
+ }
+}
diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java
new file mode 100644
index 000000000000..67a3097352a4
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java
@@ -0,0 +1,3 @@
+module com.baeldung.entity {
+ exports com.baeldung.entity;
+}
diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml b/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml
new file mode 100644
index 000000000000..d2c94527f18c
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml
@@ -0,0 +1,32 @@
+
+
+ 4.0.0
+
+ com.baeldung.multimodule-maven-project
+ multimodule-maven-project
+ 1.0
+
+ com.baeldung.mainappmodule
+ mainappmodule
+ 1.0
+ jar
+ mainappmodule
+
+
+
+ com.baeldung.entitymodule
+ entitymodule
+ 1.0
+
+
+ com.baeldung.daomodule
+ daomodule
+ 1.0
+
+
+ com.baeldung.userdaomodule
+ userdaomodule
+ 1.0
+
+
+
diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java
new file mode 100644
index 000000000000..0c0df7461b2a
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java
@@ -0,0 +1,19 @@
+package com.baeldung.mainapp;
+
+import com.baeldung.dao.Dao;
+import com.baeldung.entity.User;
+import com.baeldung.userdao.UserDao;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Application {
+
+ public static void main(String[] args) {
+ Map users = new HashMap<>();
+ users.put(1, new User("Julie"));
+ users.put(2, new User("David"));
+ Dao userDao = new UserDao(users);
+ userDao.findAll().forEach(System.out::println);
+ }
+
+}
diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java
new file mode 100644
index 000000000000..c688fcf7de86
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java
@@ -0,0 +1,6 @@
+module com.baeldung.mainapp {
+ requires com.baeldung.entity;
+ requires com.baeldung.userdao;
+ requires com.baeldung.dao;
+ uses com.baeldung.dao.Dao;
+}
diff --git a/maven-java-11/multimodule-maven-project/pom.xml b/maven-java-11/multimodule-maven-project/pom.xml
new file mode 100644
index 000000000000..f22541738c7e
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/pom.xml
@@ -0,0 +1,58 @@
+
+
+ 4.0.0
+ com.baeldung.multimodule-maven-project
+ multimodule-maven-project
+ 1.0
+ pom
+ multimodule-maven-project
+
+ com.baeldung.maven-java-11
+ maven-java-11
+ 1.0
+
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ org.assertj
+ assertj-core
+ 3.12.2
+ test
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.0
+
+
+ 11
+
+
+
+
+
+
+
+ entitymodule
+ daomodule
+ userdaomodule
+ mainappmodule
+
+
+
+ UTF-8
+
+
diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml
new file mode 100644
index 000000000000..b4fe7f039859
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+
+ com.baeldung.multimodule-maven-project
+ multimodule-maven-project
+ 1.0
+
+ com.baeldung.userdaomodule
+ userdaomodule
+ 1.0
+ jar
+ userdaomodule
+
+
+ com.baeldung.entitymodule
+ entitymodule
+ 1.0
+
+
+ com.baeldung.daomodule
+ daomodule
+ 1.0
+
+
+ junit
+ junit
+ test
+
+
+
diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java
new file mode 100644
index 000000000000..1f1ea38a6028
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java
@@ -0,0 +1,32 @@
+package com.baeldung.userdao;
+
+import com.baeldung.dao.Dao;
+import com.baeldung.entity.User;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class UserDao implements Dao {
+
+ private final Map users;
+
+ public UserDao() {
+ users = new HashMap<>();
+ }
+
+ public UserDao(Map users) {
+ this.users = users;
+ }
+
+ @Override
+ public List findAll() {
+ return new ArrayList<>(users.values());
+ }
+
+ @Override
+ public Optional findById(int id) {
+ return Optional.ofNullable(users.get(id));
+ }
+}
\ No newline at end of file
diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java
new file mode 100644
index 000000000000..f1cb217e2353
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java
@@ -0,0 +1,6 @@
+module com.baeldung.userdao {
+ requires com.baeldung.entity;
+ requires com.baeldung.dao;
+ provides com.baeldung.dao.Dao with com.baeldung.userdao.UserDao;
+ exports com.baeldung.userdao;
+}
diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java
new file mode 100644
index 000000000000..191d17ff3228
--- /dev/null
+++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java
@@ -0,0 +1,36 @@
+package com.baeldung.userdao.test;
+
+import com.baeldung.dao.Dao;
+import com.baeldung.entity.User;
+import com.baeldung.userdao.UserDao;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.Before;
+import org.junit.Test;
+
+public class UserDaoUnitTest {
+
+ private Dao userDao;
+
+ @Before
+ public void setUpUserDaoInstance() {
+ Map users = new HashMap<>();
+ users.put(1, new User("Julie"));
+ users.put(2, new User("David"));
+ userDao = new UserDao(users);
+ }
+
+ @Test
+ public void givenUserDaoIntance_whenCalledFindById_thenCorrect() {
+ assertThat(userDao.findById(1), isA(Optional.class));
+ }
+
+ @Test
+ public void givenUserDaoIntance_whenCalledFindAll_thenCorrect() {
+ assertThat(userDao.findAll(), isA(List.class));
+ }
+}
diff --git a/maven-java-11/pom.xml b/maven-java-11/pom.xml
new file mode 100644
index 000000000000..ff958405238a
--- /dev/null
+++ b/maven-java-11/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+ com.baeldung.maven-java-11
+ maven-java-11
+ 1.0
+ pom
+ maven-java-11
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+
+
+ multimodule-maven-project
+
+
+ UTF-8
+ 11
+ 11
+
+
diff --git a/maven/profiles/pom.xml b/maven/profiles/pom.xml
new file mode 100644
index 000000000000..110016f3a27a
--- /dev/null
+++ b/maven/profiles/pom.xml
@@ -0,0 +1,88 @@
+
+ 4.0.0
+ com.baeldung
+ profiles
+ 0.0.1-SNAPSHOT
+ profiles
+
+
+
+ no-tests
+
+ true
+
+
+
+ integration-tests
+
+ true
+
+
+
+ mutation-tests
+
+
+ active-on-jdk-11
+
+ 11
+
+
+
+ active-on-windows-10
+
+
+ windows 10
+ Windows
+ amd64
+ 10.0
+
+
+
+
+ active-on-property-environment
+
+
+ environment
+ !test
+
+
+
+
+ active-on-missing-file
+
+
+ target/testreport.html
+
+
+
+
+ active-on-present-file
+
+
+ target/artifact.jar
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-help-plugin
+ 3.2.0
+
+
+ show-profiles
+ compile
+
+ active-profiles
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/persistence-modules/java-mongodb/pom.xml b/persistence-modules/java-mongodb/pom.xml
index 9658ef567fb2..0f5efedb9649 100644
--- a/persistence-modules/java-mongodb/pom.xml
+++ b/persistence-modules/java-mongodb/pom.xml
@@ -35,8 +35,8 @@
1.8
1.8
- 3.4.1
+ 3.10.1
1.11
-
\ No newline at end of file
+
diff --git a/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java b/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java
new file mode 100644
index 000000000000..0ad3dfae3001
--- /dev/null
+++ b/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java
@@ -0,0 +1,79 @@
+package com.baeldung;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class MongoBsonExample
+{
+ public static void main(String[] args)
+ {
+ //
+ // 4.1 Connect to cluster (default is localhost:27017)
+ //
+
+ MongoClient mongoClient = MongoClients.create();
+ MongoDatabase database = mongoClient.getDatabase("myDB");
+ MongoCollection collection = database.getCollection("employees");
+
+ //
+ // 4.2 Insert new document
+ //
+
+ Document employee = new Document()
+ .append("first_name", "Joe")
+ .append("last_name", "Smith")
+ .append("title", "Java Developer")
+ .append("years_of_service", 3)
+ .append("skills", Arrays.asList("java", "spring", "mongodb"))
+ .append("manager", new Document()
+ .append("first_name", "Sally")
+ .append("last_name", "Johanson"));
+ collection.insertOne(employee);
+
+ //
+ // 4.3 Find documents
+ //
+
+
+ Document query = new Document("last_name", "Smith");
+ List results = new ArrayList<>();
+ collection.find(query).into(results);
+
+ query =
+ new Document("$or", Arrays.asList(
+ new Document("last_name", "Smith"),
+ new Document("first_name", "Joe")));
+ results = new ArrayList<>();
+ collection.find(query).into(results);
+
+ //
+ // 4.4 Update document
+ //
+
+ query = new Document(
+ "skills",
+ new Document(
+ "$elemMatch",
+ new Document("$eq", "spring")));
+ Document update = new Document(
+ "$push",
+ new Document("skills", "security"));
+ collection.updateMany(query, update);
+
+ //
+ // 4.5 Delete documents
+ //
+
+ query = new Document(
+ "years_of_service",
+ new Document("$lt", 0));
+ collection.deleteMany(query);
+ }
+}
diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml
index ee55325b2039..67a5c36fedc9 100644
--- a/persistence-modules/pom.xml
+++ b/persistence-modules/pom.xml
@@ -35,7 +35,7 @@
querydsl
redis
solr
- spring-boot-h2/spring-boot-h2-database
+ spring-boot-persistence-h2
spring-boot-persistence
spring-boot-persistence-mongodb
spring-data-cassandra
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/.gitignore b/persistence-modules/spring-boot-persistence-h2/.gitignore
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/.gitignore
rename to persistence-modules/spring-boot-persistence-h2/.gitignore
diff --git a/persistence-modules/spring-boot-h2/README.md b/persistence-modules/spring-boot-persistence-h2/README.md
similarity index 67%
rename from persistence-modules/spring-boot-h2/README.md
rename to persistence-modules/spring-boot-persistence-h2/README.md
index af5f3954403a..377b7c8939e8 100644
--- a/persistence-modules/spring-boot-h2/README.md
+++ b/persistence-modules/spring-boot-persistence-h2/README.md
@@ -1,2 +1,3 @@
### Relevant Articles:
- [Access the Same In-Memory H2 Database in Multiple Spring Boot Applications](https://www.baeldung.com/spring-boot-access-h2-database-multiple-apps)
+- [Spring Boot With H2 Database](https://www.baeldung.com/spring-boot-h2-database)
\ No newline at end of file
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml b/persistence-modules/spring-boot-persistence-h2/pom.xml
similarity index 97%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml
rename to persistence-modules/spring-boot-persistence-h2/pom.xml
index 882b88b5350e..4c8073ddb41b 100644
--- a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml
+++ b/persistence-modules/spring-boot-persistence-h2/pom.xml
@@ -14,7 +14,7 @@
parent-boot-2
com.baeldung
0.0.1-SNAPSHOT
- ../../../parent-boot-2
+ ../../parent-boot-2
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java
rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java
rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java
rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java
rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java
rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java
rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application.properties
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties
rename to persistence-modules/spring-boot-persistence-h2/src/main/resources/application.properties
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql
rename to persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java
rename to persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java
diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringContextIntegrationTest.java
similarity index 100%
rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringContextIntegrationTest.java
rename to persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringContextIntegrationTest.java
diff --git a/persistence-modules/spring-data-jpa-2/pom.xml b/persistence-modules/spring-data-jpa-2/pom.xml
index 251007ba6d43..fbc19810ef70 100644
--- a/persistence-modules/spring-data-jpa-2/pom.xml
+++ b/persistence-modules/spring-data-jpa-2/pom.xml
@@ -26,6 +26,12 @@
h2
+
+ net.ttddyy
+ datasource-proxy
+ 1.4.1
+
+
com.fasterxml.jackson.core
jackson-databind
@@ -35,7 +41,5 @@
org.springframework
spring-oxm
-
-
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java
new file mode 100644
index 000000000000..504357db445e
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java
@@ -0,0 +1,53 @@
+package com.baeldung.batchinserts;
+
+import java.lang.reflect.Method;
+import javax.sql.DataSource;
+import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.annotation.Profile;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ReflectionUtils;
+
+@Component
+@Profile("batchinserts")
+public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor {
+
+ @Override
+ public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
+ return bean;
+ }
+
+ @Override
+ public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
+ if (bean instanceof DataSource) {
+ ProxyFactory factory = new ProxyFactory(bean);
+ factory.setProxyTargetClass(true);
+ factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean));
+ return factory.getProxy();
+ }
+
+ return bean;
+ }
+
+ private static class ProxyDataSourceInterceptor implements MethodInterceptor {
+
+ private final DataSource dataSource;
+
+ public ProxyDataSourceInterceptor(final DataSource dataSource) {
+ this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("Batch-Insert-Logger").asJson().countQuery().logQueryToSysOut().build();
+ }
+
+ @Override
+ public Object invoke(final MethodInvocation invocation) throws Throwable {
+ Method proxyMethod = ReflectionUtils.findMethod(dataSource.getClass(), invocation.getMethod().getName());
+ if (proxyMethod != null) {
+ return proxyMethod.invoke(dataSource, invocation.getArguments());
+ }
+ return invocation.proceed();
+ }
+ }
+}
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java
new file mode 100644
index 000000000000..6d2f333ac7bc
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java
@@ -0,0 +1,45 @@
+package com.baeldung.batchinserts.model;
+
+import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class School {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
+ private long id;
+
+ private String name;
+
+ @OneToMany(mappedBy = "school")
+ private List students;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getStudents() {
+ return students;
+ }
+
+ public void setStudents(List students) {
+ this.students = students;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java
new file mode 100644
index 000000000000..d38214f1221d
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java
@@ -0,0 +1,44 @@
+package com.baeldung.batchinserts.model;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class Student {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
+ private long id;
+
+ private String name;
+
+ @ManyToOne
+ private School school;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public School getSchool() {
+ return school;
+ }
+
+ public void setSchool(School school) {
+ this.school = school;
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties
new file mode 100644
index 000000000000..4141f5668e1b
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties
@@ -0,0 +1,6 @@
+spring.jpa.show-sql=false
+
+spring.jpa.properties.hibernate.jdbc.batch_size=5
+spring.jpa.properties.hibernate.order_inserts=true
+spring.jpa.properties.hibernate.order_updates=true
+spring.jpa.properties.hibernate.batch_versioned_data=true
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java
new file mode 100644
index 000000000000..9e81dbc04dec
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java
@@ -0,0 +1,94 @@
+package com.baeldung.batchinserts;
+
+import static com.baeldung.batchinserts.TestObjectHelper.createSchool;
+import static com.baeldung.batchinserts.TestObjectHelper.createStudent;
+
+import com.baeldung.batchinserts.model.School;
+import com.baeldung.batchinserts.model.Student;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.TypedQuery;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@Transactional
+@ActiveProfiles("batchinserts")
+public class JpaBatchInsertsIntegrationTest {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ private static final int BATCH_SIZE = 5;
+
+ @Transactional
+ @Test
+ public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() {
+ for (int i = 0; i < 10; i++) {
+ School school = createSchool(i);
+ entityManager.persist(school);
+ }
+ }
+
+ @Transactional
+ @Test
+ public void whenFlushingAfterBatch_ThenClearsMemory() {
+ for (int i = 0; i < 10; i++) {
+ if (i > 0 && i % BATCH_SIZE == 0) {
+ entityManager.flush();
+ entityManager.clear();
+ }
+
+ School school = createSchool(i);
+ entityManager.persist(school);
+ }
+ }
+
+ @Transactional
+ @Test
+ public void whenThereAreMultipleEntities_ThenCreatesNewBatch() {
+ for (int i = 0; i < 10; i++) {
+ if (i > 0 && i % BATCH_SIZE == 0) {
+ entityManager.flush();
+ entityManager.clear();
+ }
+
+ School school = createSchool(i);
+ entityManager.persist(school);
+ Student firstStudent = createStudent(school);
+ Student secondStudent = createStudent(school);
+ entityManager.persist(firstStudent);
+ entityManager.persist(secondStudent);
+ }
+ }
+
+ @Transactional
+ @Test
+ public void whenUpdatingEntities_thenCreatesBatch() {
+ for (int i = 0; i < 10; i++) {
+ School school = createSchool(i);
+ entityManager.persist(school);
+ }
+
+ entityManager.flush();
+
+ TypedQuery schoolQuery = entityManager.createQuery("SELECT s from School s", School.class);
+ List allSchools = schoolQuery.getResultList();
+
+ for (School school : allSchools) {
+ school.setName("Updated_" + school.getName());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ entityManager.flush();
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java
new file mode 100644
index 000000000000..20502c793d5c
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java
@@ -0,0 +1,39 @@
+package com.baeldung.batchinserts;
+
+import static com.baeldung.batchinserts.TestObjectHelper.createSchool;
+
+import com.baeldung.batchinserts.model.School;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@Transactional
+@ActiveProfiles("batchinserts")
+@TestPropertySource(properties = "spring.jpa.properties.hibernate.jdbc.batch_size=-1")
+public class JpaNoBatchInsertsIntegrationTest {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Test
+ public void whenNotConfigured_ThenSendsInsertsSeparately() {
+ for (int i = 0; i < 10; i++) {
+ School school = createSchool(i);
+ entityManager.persist(school);
+ }
+ }
+
+ @After
+ public void tearDown() {
+ entityManager.flush();
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java
new file mode 100644
index 000000000000..fcd26cb72157
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java
@@ -0,0 +1,20 @@
+package com.baeldung.batchinserts;
+
+import com.baeldung.batchinserts.model.School;
+import com.baeldung.batchinserts.model.Student;
+
+public class TestObjectHelper {
+
+ public static School createSchool(int nameIdentifier) {
+ School school = new School();
+ school.setName("School" + (nameIdentifier + 1));
+ return school;
+ }
+
+ public static Student createStudent(School school) {
+ Student student = new Student();
+ student.setName("Student-" + school.getName());
+ student.setSchool(school);
+ return student;
+ }
+}
diff --git a/picocli/pom.xml b/picocli/pom.xml
new file mode 100644
index 000000000000..0334f5463d16
--- /dev/null
+++ b/picocli/pom.xml
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+
+ com.baeldung
+ parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
+
+
+ picocli
+
+
+
+ info.picocli
+ picocli
+ 3.9.6
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+ 2.1.4.RELEASE
+
+
+
\ No newline at end of file
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/Application.java b/picocli/src/main/java/com/baeldung/picocli/git/Application.java
new file mode 100644
index 000000000000..04af524e4553
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/Application.java
@@ -0,0 +1,41 @@
+package com.baeldung.picocli.git;
+
+import com.baeldung.picocli.git.commands.programmative.GitCommand;
+import com.baeldung.picocli.git.commands.subcommands.GitAddCommand;
+import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand;
+import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import picocli.CommandLine;
+
+@SpringBootApplication
+public class Application implements CommandLineRunner {
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+ private GitCommand gitCommand;
+ private GitAddCommand addCommand;
+ private GitCommitCommand commitCommand;
+ private GitConfigCommand configCommand;
+
+ @Autowired
+ public Application(GitCommand gitCommand, GitAddCommand addCommand, GitCommitCommand commitCommand, GitConfigCommand configCommand) {
+ this.gitCommand = gitCommand;
+ this.addCommand = addCommand;
+ this.commitCommand = commitCommand;
+ this.configCommand = configCommand;
+ }
+
+ @Override
+ public void run(String... args) {
+ CommandLine commandLine = new CommandLine(gitCommand);
+ commandLine.addSubcommand("add", addCommand);
+ commandLine.addSubcommand("commit", commitCommand);
+ commandLine.addSubcommand("config", configCommand);
+
+ commandLine.parseWithHandler(new CommandLine.RunLast(), args);
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java
new file mode 100644
index 000000000000..f3c690a3e6c1
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java
@@ -0,0 +1,32 @@
+package com.baeldung.picocli.git.commands.declarative;
+
+import com.baeldung.picocli.git.model.ConfigElement;
+import com.baeldung.picocli.git.commands.subcommands.GitAddCommand;
+import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand;
+import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand;
+import picocli.CommandLine;
+
+import static picocli.CommandLine.*;
+import static picocli.CommandLine.Command;
+
+@Command(
+ name = "git",
+ subcommands = {
+ GitAddCommand.class,
+ GitCommitCommand.class,
+ GitConfigCommand.class
+ }
+)
+public class GitCommand implements Runnable {
+ public static void main(String[] args) {
+ CommandLine commandLine = new CommandLine(new GitCommand());
+ commandLine.registerConverter(ConfigElement.class, ConfigElement::from);
+
+ commandLine.parseWithHandler(new RunLast(), args);
+ }
+
+ @Override
+ public void run() {
+ System.out.println("The popular git command");
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java
new file mode 100644
index 000000000000..2c3e440b8b9a
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java
@@ -0,0 +1,27 @@
+package com.baeldung.picocli.git.commands.methods;
+
+import picocli.CommandLine;
+
+import static picocli.CommandLine.Command;
+
+@Command(name = "git")
+public class GitCommand implements Runnable {
+ public static void main(String[] args) {
+ CommandLine.run(new GitCommand(), args);
+ }
+
+ @Override
+ public void run() {
+ System.out.println("The popular git command");
+ }
+
+ @Command(name = "add")
+ public void addCommand() {
+ System.out.println("Adding some files to the staging area");
+ }
+
+ @Command(name = "commit")
+ public void commitCommand() {
+ System.out.println("Committing files in the staging area, how wonderful?");
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java
new file mode 100644
index 000000000000..81ecfd78bea3
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java
@@ -0,0 +1,26 @@
+package com.baeldung.picocli.git.commands.programmative;
+
+import com.baeldung.picocli.git.commands.subcommands.GitAddCommand;
+import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand;
+import org.springframework.stereotype.Component;
+import picocli.CommandLine;
+
+import static picocli.CommandLine.Command;
+import static picocli.CommandLine.RunLast;
+
+@Command(name = "git")
+@Component
+public class GitCommand implements Runnable {
+ public static void main(String[] args) {
+ CommandLine commandLine = new CommandLine(new GitCommand());
+ commandLine.addSubcommand("add", new GitAddCommand());
+ commandLine.addSubcommand("commit", new GitCommitCommand());
+
+ commandLine.parseWithHandler(new RunLast(), args);
+ }
+
+ @Override
+ public void run() {
+ System.out.println("The popular git command");
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java
new file mode 100644
index 000000000000..803cd8dc7d68
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java
@@ -0,0 +1,31 @@
+package com.baeldung.picocli.git.commands.subcommands;
+
+import org.springframework.stereotype.Component;
+
+import java.nio.file.Path;
+import java.util.List;
+
+import static picocli.CommandLine.*;
+
+@Command(
+ name = "add"
+)
+@Component
+public class GitAddCommand implements Runnable {
+ @Option(names = "-A")
+ private boolean allFiles;
+
+ @Parameters(index = "0..*")
+ private List files;
+
+ @Override
+ public void run() {
+ if (allFiles) {
+ System.out.println("Adding all files to the staging area");
+ }
+
+ if (files != null) {
+ files.forEach(path -> System.out.println("Adding " + path + " to the staging area"));
+ }
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java
new file mode 100644
index 000000000000..df4928983cbe
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java
@@ -0,0 +1,26 @@
+package com.baeldung.picocli.git.commands.subcommands;
+
+import org.springframework.stereotype.Component;
+
+import static picocli.CommandLine.Command;
+import static picocli.CommandLine.Option;
+
+@Command(
+ name = "commit"
+)
+@Component
+public class GitCommitCommand implements Runnable {
+ @Option(names = {"-m", "--message"}, required = true)
+ private String[] messages;
+
+ @Override
+ public void run() {
+ System.out.println("Committing files in the staging area, how wonderful?");
+ if (messages != null) {
+ System.out.println("The commit message is");
+ for (String message : messages) {
+ System.out.println(message);
+ }
+ }
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java
new file mode 100644
index 000000000000..80e14c0121a9
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java
@@ -0,0 +1,24 @@
+package com.baeldung.picocli.git.commands.subcommands;
+
+import com.baeldung.picocli.git.model.ConfigElement;
+import org.springframework.stereotype.Component;
+
+import static picocli.CommandLine.Command;
+import static picocli.CommandLine.Parameters;
+
+@Command(
+ name = "config"
+)
+@Component
+public class GitConfigCommand implements Runnable {
+ @Parameters(index = "0")
+ private ConfigElement element;
+
+ @Parameters(index = "1")
+ private String value;
+
+ @Override
+ public void run() {
+ System.out.println("Setting " + element.value() + " to " + value);
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java b/picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java
new file mode 100644
index 000000000000..edc6573d885d
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java
@@ -0,0 +1,25 @@
+package com.baeldung.picocli.git.model;
+
+import java.util.Arrays;
+
+public enum ConfigElement {
+ USERNAME("user.name"),
+ EMAIL("user.email");
+
+ private final String value;
+
+ ConfigElement(String value) {
+ this.value = value;
+ }
+
+ public String value() {
+ return value;
+ }
+
+ public static ConfigElement from(String value) {
+ return Arrays.stream(values())
+ .filter(element -> element.value.equals(value))
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("The argument " + value + " doesn't match any ConfigElement"));
+ }
+}
diff --git a/picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java b/picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java
new file mode 100644
index 000000000000..97a861e2f058
--- /dev/null
+++ b/picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java
@@ -0,0 +1,20 @@
+package com.baeldung.picocli.helloworld;
+
+import picocli.CommandLine;
+
+import static picocli.CommandLine.Command;
+
+@Command(
+ name = "hello",
+ description = "Says hello"
+)
+public class HelloWorldCommand implements Runnable {
+ public static void main(String[] args) {
+ CommandLine.run(new HelloWorldCommand(), args);
+ }
+
+ @Override
+ public void run() {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/pom.xml b/pom.xml
index 0de4a363369d..de6f47d71dd1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,6 +12,7 @@
lombok-custom
+ picocli
@@ -377,6 +378,7 @@
checker-plugin
core-groovy
core-groovy-2
+ core-groovy-collections
@@ -387,8 +389,8 @@
core-java-arrays
core-java-collections
- core-java-collections-map
core-java-collections-list
+ core-java-collections-set
core-java-concurrency-basic
core-java-concurrency-collections
core-java-io
@@ -397,6 +399,7 @@
core-java-lang
core-java-lang-oop
core-java-lang-oop-2
+ core-java-modules
core-java-networking
core-java-perf
core-java-sun
@@ -619,18 +622,20 @@
spring-boot-camel
spring-boot-client
- spring-boot-configuration
+
spring-boot-crud
spring-boot-ctx-fluent
spring-boot-custom-starter
spring-boot-disable-console-logging
+ spring-boot-exceptions
spring-boot-jasypt
spring-boot-keycloak
spring-boot-logging-log4j2
spring-boot-mvc
spring-boot-mvc-birt
spring-boot-ops
+ spring-boot-ops-2
spring-boot-rest
spring-boot-data
spring-boot-property-exp
@@ -820,9 +825,9 @@
spring-boot-bootstrap
spring-boot-camel
spring-boot-client
- spring-boot-configuration
spring-boot-custom-starter
- greeter-spring-boot-autoconfigure
+ spring-boot-exceptions
+ greeter-spring-boot-autoconfigure
greeter-spring-boot-sample-app
persistence-modules/spring-boot-h2/spring-boot-h2-database
spring-boot-jasypt
@@ -1049,6 +1054,7 @@
checker-plugin
core-groovy
core-groovy-2
+ core-groovy-collections
core-java-8
@@ -1057,8 +1063,8 @@
core-java-arrays
core-java-collections
- core-java-collections-map
core-java-collections-list
+ core-java-collections-set
core-java-concurrency-basic
core-java-concurrency-collections
core-java-io
@@ -1067,6 +1073,7 @@
core-java-lang
core-java-lang-oop
core-java-lang-oop-2
+ core-java-modules
core-java-networking
core-java-perf
core-java-sun
@@ -1168,6 +1175,7 @@
mapstruct
maven
+
maven-archetype
maven-polyglot/maven-polyglot-json-extension
@@ -1275,11 +1283,11 @@
spring-boot-camel
spring-boot-client
- spring-boot-configuration
spring-boot-crud
spring-boot-ctx-fluent
spring-boot-custom-starter
spring-boot-disable-console-logging
+ spring-boot-exceptions
spring-boot-jasypt
spring-boot-keycloak
@@ -1287,6 +1295,7 @@
spring-boot-mvc
spring-boot-mvc-birt
spring-boot-ops
+ spring-boot-ops-2
spring-boot-rest
spring-boot-data
spring-boot-property-exp
@@ -1495,8 +1504,9 @@
UTF-8
UTF-8
- refs/remotes/origin/master
- true
+ refs/remotes/origin/master
+ true
+ false
false
false
false
@@ -1537,7 +1547,7 @@
0.3.1
2.5.1
0.0.1
- 3.4
+ 3.8
2.3
3.8
diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java
new file mode 100644
index 000000000000..ae03e0a802c0
--- /dev/null
+++ b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java
@@ -0,0 +1,16 @@
+package com.baeldung.cognito;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@PropertySource("cognito/application_cognito.yml")
+public class CognitoWebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("home");
+ }
+}
diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java
new file mode 100644
index 000000000000..7f7b751cd94c
--- /dev/null
+++ b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java
@@ -0,0 +1,14 @@
+package com.baeldung.cognito;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.PropertySource;
+
+@SpringBootApplication
+@PropertySource("cognito/application_cognito.yml")
+public class SpringCognitoApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringCognitoApplication.class, args);
+ }
+}
diff --git a/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml b/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml
new file mode 100644
index 000000000000..0a28dbccb422
--- /dev/null
+++ b/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml
@@ -0,0 +1,15 @@
+spring:
+ security:
+ oauth2:
+ client:
+ registration:
+ cognito:
+ client-id: clientId
+ client-secret: clientSecret
+ scope: openid
+ redirectUriTemplate: "http://localhost:8080/login/oauth2/code/cognito"
+ clientName: cognito-client-name
+ provider:
+ cognito:
+ issuerUri: https://cognito-idp.{region}.amazonaws.com/{poolId}
+ usernameAttribute: cognito:username
diff --git a/spring-5-security-oauth/src/main/resources/cognito/home.html b/spring-5-security-oauth/src/main/resources/cognito/home.html
new file mode 100644
index 000000000000..f0bd9e52a8c0
--- /dev/null
+++ b/spring-5-security-oauth/src/main/resources/cognito/home.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+ OAuth2 Cognito Demo
+
+
+
+
+
+
+
+
+
OAuth2 Spring Security Cognito Demo
+
+
+
+
+
+
+
+
+
diff --git a/spring-5-security-oauth/src/main/resources/cognito/style.css b/spring-5-security-oauth/src/main/resources/cognito/style.css
new file mode 100644
index 000000000000..45190d6d70fe
--- /dev/null
+++ b/spring-5-security-oauth/src/main/resources/cognito/style.css
@@ -0,0 +1,9 @@
+.login {
+ background-color: #7289da;
+ color: #fff;
+}
+
+.login:hover {
+ background-color: #697ec4;
+ color: #fff;
+}
diff --git a/spring-boot-configuration/README.MD b/spring-boot-configuration/README.MD
deleted file mode 100644
index e69de29bb2d1..000000000000
diff --git a/spring-boot-configuration/pom.xml b/spring-boot-configuration/pom.xml
deleted file mode 100644
index 2ecef7bb02bd..000000000000
--- a/spring-boot-configuration/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
- 4.0.0
-
-
- parent-boot-2
- com.baeldung
- 0.0.1-SNAPSHOT
- ../parent-boot-2
-
-
- com.baeldung
- spring-boot-configuration
- 0.0.1-SNAPSHOT
- spring-boot-configuration
- Demo project for Spring Boot configuration
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-
-
diff --git a/spring-boot-configuration/.gitignore b/spring-boot-exceptions/.gitignore
similarity index 100%
rename from spring-boot-configuration/.gitignore
rename to spring-boot-exceptions/.gitignore
diff --git a/spring-boot-exceptions/pom.xml b/spring-boot-exceptions/pom.xml
new file mode 100644
index 000000000000..105f60e29586
--- /dev/null
+++ b/spring-boot-exceptions/pom.xml
@@ -0,0 +1,37 @@
+
+
+ 4.0.0
+
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+ com.baeldung
+ spring-boot-exceptions
+ 0.0.4-SNAPSHOT
+ pass-exception-to-client-json-spring-boot
+ Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot
+
+
+ 1.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java
new file mode 100644
index 000000000000..f1a1d94f5435
--- /dev/null
+++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java
@@ -0,0 +1,11 @@
+package com.baeldung.jsonexception;
+
+public class CustomException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public CustomException() {
+ super("Custom exception message.");
+ }
+
+}
\ No newline at end of file
diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java
new file mode 100644
index 000000000000..a890dfa3a2cd
--- /dev/null
+++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java
@@ -0,0 +1,19 @@
+package com.baeldung.jsonexception;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+@ControllerAdvice
+@ResponseBody
+public class ErrorHandler {
+
+ @ExceptionHandler(CustomException.class)
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ public CustomException handleCustomException(CustomException ce) {
+ return ce;
+ }
+
+}
\ No newline at end of file
diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java
new file mode 100644
index 000000000000..188584bd7ca2
--- /dev/null
+++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java
@@ -0,0 +1,13 @@
+package com.baeldung.jsonexception;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class JsonErrorApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(JsonErrorApplication.class, args);
+ }
+
+}
\ No newline at end of file
diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java
new file mode 100644
index 000000000000..5d73c239a4f5
--- /dev/null
+++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java
@@ -0,0 +1,14 @@
+package com.baeldung.jsonexception;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class MainController {
+
+ @GetMapping("/")
+ public void index() throws CustomException {
+ throw new CustomException();
+ }
+
+}
\ No newline at end of file
diff --git a/spring-boot-configuration/src/main/resources/application.properties b/spring-boot-exceptions/src/main/resources/application.properties
similarity index 100%
rename from spring-boot-configuration/src/main/resources/application.properties
rename to spring-boot-exceptions/src/main/resources/application.properties
diff --git a/spring-boot-exceptions/src/main/resources/static/.gitignore b/spring-boot-exceptions/src/main/resources/static/.gitignore
new file mode 100644
index 000000000000..5e7d2734cfc6
--- /dev/null
+++ b/spring-boot-exceptions/src/main/resources/static/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/spring-boot-exceptions/src/main/resources/templates/.gitignore b/spring-boot-exceptions/src/main/resources/templates/.gitignore
new file mode 100644
index 000000000000..5e7d2734cfc6
--- /dev/null
+++ b/spring-boot-exceptions/src/main/resources/templates/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java
new file mode 100644
index 000000000000..77e71b7d21de
--- /dev/null
+++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java
@@ -0,0 +1,19 @@
+package com.baeldung.jsonexception;
+
+import org.junit.Test;
+
+import com.baeldung.jsonexception.CustomException;
+import com.baeldung.jsonexception.MainController;
+
+public class MainControllerIntegrationTest {
+
+ @Test(expected = CustomException.class)
+ public void givenIndex_thenCustomException() throws CustomException {
+
+ MainController mainController = new MainController();
+
+ mainController.index();
+
+ }
+
+}
\ No newline at end of file
diff --git a/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java
new file mode 100644
index 000000000000..aa91e242ab06
--- /dev/null
+++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.jsonexception;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringContextIntegrationTest {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/spring-boot-ops-2/.gitignore b/spring-boot-ops-2/.gitignore
new file mode 100644
index 000000000000..153c9335ebd7
--- /dev/null
+++ b/spring-boot-ops-2/.gitignore
@@ -0,0 +1,29 @@
+HELP.md
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+/build/
+
+### VS Code ###
+.vscode/
diff --git a/spring-boot-ops-2/README.MD b/spring-boot-ops-2/README.MD
new file mode 100644
index 000000000000..20b30515fbdb
--- /dev/null
+++ b/spring-boot-ops-2/README.MD
@@ -0,0 +1,3 @@
+### Relevant Articles
+
+- [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat)
\ No newline at end of file
diff --git a/spring-boot-ops-2/pom.xml b/spring-boot-ops-2/pom.xml
new file mode 100644
index 000000000000..dc5280df4896
--- /dev/null
+++ b/spring-boot-ops-2/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+
+
+ parent-boot-2
+ com.baeldung
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+ com.baeldung
+ spring-boot-ops-2
+ 0.0.1-SNAPSHOT
+ spring-boot-ops-2
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java b/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
similarity index 65%
rename from spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
rename to spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
index b4f5681475fd..96297459a4a9 100644
--- a/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
+++ b/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java
@@ -6,8 +6,8 @@
@SpringBootApplication
public class SpringBootConfigurationApplication {
- public static void main(String[] args) {
- SpringApplication.run(SpringBootConfigurationApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootConfigurationApplication.class, args);
+ }
}
diff --git a/spring-boot-configuration/src/main/resources/application-tomcat.properties b/spring-boot-ops-2/src/main/resources/application-tomcat.properties
similarity index 100%
rename from spring-boot-configuration/src/main/resources/application-tomcat.properties
rename to spring-boot-ops-2/src/main/resources/application-tomcat.properties
diff --git a/spring-boot-ops-2/src/main/resources/application.properties b/spring-boot-ops-2/src/main/resources/application.properties
new file mode 100644
index 000000000000..8b137891791f
--- /dev/null
+++ b/spring-boot-ops-2/src/main/resources/application.properties
@@ -0,0 +1 @@
+
diff --git a/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
similarity index 86%
rename from spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
rename to spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
index d6b2b50a2fe5..24bef73ef953 100644
--- a/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
+++ b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java
@@ -9,8 +9,7 @@
@SpringBootTest
public class SpringContextIntegrationTest {
- @Test
- public void contextLoads() {
- }
-
+ @Test
+ public void contextLoads() {
+ }
}
diff --git a/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java
index c0cbca5220f9..68c17975d448 100644
--- a/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java
+++ b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java
@@ -21,6 +21,7 @@
import com.baeldung.modelmapper.service.IUserService;
@Controller
+@RequestMapping("/posts")
public class PostRestController {
@Autowired
diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java
index 3698d8ef3066..1a3c985fe49f 100644
--- a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java
+++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java
@@ -9,6 +9,7 @@
import javax.validation.constraints.Pattern;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.validation.annotation.Validated;
@@ -80,4 +81,10 @@ public Credentials getCredentials() {
public void setCredentials(Credentials credentials) {
this.credentials = credentials;
}
+
+ @Bean
+ @ConfigurationProperties(prefix = "item")
+ public Item item(){
+ return new Item();
+ }
}
diff --git a/spring-boot/src/main/java/org/baeldung/properties/Item.java b/spring-boot/src/main/java/org/baeldung/properties/Item.java
new file mode 100644
index 000000000000..0314654adae8
--- /dev/null
+++ b/spring-boot/src/main/java/org/baeldung/properties/Item.java
@@ -0,0 +1,31 @@
+package org.baeldung.properties;
+
+public class Item {
+
+ private String name;
+ private int size;
+
+ public Item() {
+ }
+
+ public Item(String name, int size) {
+ this.name = name;
+ this.size = size;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+}
diff --git a/spring-boot/src/main/resources/configprops.properties b/spring-boot/src/main/resources/configprops.properties
index 2dad11f9cc6b..424b3632f991 100644
--- a/spring-boot/src/main/resources/configprops.properties
+++ b/spring-boot/src/main/resources/configprops.properties
@@ -17,4 +17,8 @@ mail.credentials.username=john
mail.credentials.password=password
mail.credentials.authMethod=SHA1
+#Bean method properties
+item.name=Item name
+item.size=42
+
diff --git a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java
index 4ba6bf29d8c5..f864fd4f8c6b 100644
--- a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java
+++ b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java
@@ -53,4 +53,11 @@ public void whenObjectPropertyQueriedthenReturnsProperty() throws Exception {
Assert.assertEquals("Incorrectly bound object property, username", "john", credentials.getUsername());
Assert.assertEquals("Incorrectly bound object property, password", "password", credentials.getPassword());
}
+
+ @Test
+ public void whenBeanMethodAnnotatedThenPropertiesCorrectlyBound(){
+ Item item = properties.item();
+ Assert.assertEquals("Incorrectly bound object property, item.name","Test item name", item.getName());
+ Assert.assertEquals("Incorrectly bound object property, item.size", 21, item.getSize());
+ }
}
diff --git a/spring-boot/src/test/resources/configprops-test.properties b/spring-boot/src/test/resources/configprops-test.properties
index 697771ae6eb9..ea11f2159e0b 100644
--- a/spring-boot/src/test/resources/configprops-test.properties
+++ b/spring-boot/src/test/resources/configprops-test.properties
@@ -17,3 +17,6 @@ mail.credentials.username=john
mail.credentials.password=password
mail.credentials.authMethod=SHA1
+#Bean method properties
+item.name=Test item name
+item.size=21
diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md
index 1624a3abfd79..abbacb69cc67 100644
--- a/spring-data-rest/README.md
+++ b/spring-data-rest/README.md
@@ -22,3 +22,4 @@ To view the running application, visit [http://localhost:8080](http://localhost:
- [Spring Data REST Events with @RepositoryEventHandler](http://www.baeldung.com/spring-data-rest-events)
- [Customizing HTTP Endpoints in Spring Data REST](https://www.baeldung.com/spring-data-rest-customize-http-endpoints)
- [Spring Boot with SQLite](https://www.baeldung.com/spring-boot-sqlite)
+- [Spring Data Web Support](https://www.baeldung.com/spring-data-web-support)
diff --git a/vaadin/pom.xml b/vaadin/pom.xml
index 145a6af293d5..ec69e240e25e 100644
--- a/vaadin/pom.xml
+++ b/vaadin/pom.xml
@@ -70,17 +70,6 @@
com.vaadin
vaadin-maven-plugin
${vaadin.plugin.version}
-
-
-
- update-theme
- update-widgetset
- compile
-
- compile-theme
-
-
-
org.apache.maven.plugins