diff --git a/apache-spark/src/test/java/com/baeldung/dataframes/CustomerToDataFrameConverterAppUnitTest.java b/apache-spark/src/test/java/com/baeldung/dataframes/CustomerToDataFrameConverterAppUnitTest.java
index 06c8f66bcd..c16ca34fdc 100644
--- a/apache-spark/src/test/java/com/baeldung/dataframes/CustomerToDataFrameConverterAppUnitTest.java
+++ b/apache-spark/src/test/java/com/baeldung/dataframes/CustomerToDataFrameConverterAppUnitTest.java
@@ -8,6 +8,8 @@ import java.util.List;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
class CustomerToDataFrameConverterAppUnitTest {
@@ -59,4 +61,9 @@ class CustomerToDataFrameConverterAppUnitTest {
assertEquals( "Male", row2.getAs("gender"));
assertEquals( 1200, (int)row2.getAs("transaction_amount"));
}
+
+ @AfterEach
+ public void cleanup() {
+ SparkSession.getActiveSession().get().close();
+ }
}
diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md
index 07cdf9859c..00fd2fa320 100644
--- a/core-java-modules/core-java-14/README.md
+++ b/core-java-modules/core-java-14/README.md
@@ -11,3 +11,4 @@ This module contains articles about Java 14.
- [Foreign Memory Access API in Java 14](https://www.baeldung.com/java-foreign-memory-access)
- [Java 14 Record Keyword](https://www.baeldung.com/java-record-keyword)
- [New Features in Java 14](https://www.baeldung.com/java-14-new-features)
+- [Java 14 Record vs. Lombok](https://www.baeldung.com/java-record-vs-lombok)
diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml
index 35ea0bd2d0..f78edd622a 100644
--- a/core-java-modules/core-java-14/pom.xml
+++ b/core-java-modules/core-java-14/pom.xml
@@ -14,6 +14,15 @@
1.0.0-SNAPSHOT
+
+
+ org.projectlombok
+ lombok
+ 1.18.24
+ provided
+
+
+
diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorData.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorData.java
new file mode 100644
index 0000000000..6d50c63ba5
--- /dev/null
+++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorData.java
@@ -0,0 +1,18 @@
+package com.baeldung.java14.recordvslombok;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class ColorData {
+
+ private int red;
+ private int green;
+ private int blue;
+
+ public String getHexString() {
+ return String.format("#%02X%02X%02X", red, green, blue);
+ }
+
+}
diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorRecord.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorRecord.java
new file mode 100644
index 0000000000..03d1f5c264
--- /dev/null
+++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorRecord.java
@@ -0,0 +1,8 @@
+package com.baeldung.java14.recordvslombok;
+
+public record ColorRecord(int red, int green, int blue) {
+
+ public String getHexString() {
+ return String.format("#%02X%02X%02X", red, green, blue);
+ }
+}
diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorValueObject.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorValueObject.java
new file mode 100644
index 0000000000..eca33662c2
--- /dev/null
+++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/ColorValueObject.java
@@ -0,0 +1,17 @@
+package com.baeldung.java14.recordvslombok;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Value;
+
+@Value
+@Getter(AccessLevel.NONE)
+public class ColorValueObject {
+ int red;
+ int green;
+ int blue;
+
+ public String getHexString() {
+ return String.format("#%02X%02X%02X", red, green, blue);
+ }
+}
diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/MonochromeColor.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/MonochromeColor.java
new file mode 100644
index 0000000000..6672cb49ea
--- /dev/null
+++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/MonochromeColor.java
@@ -0,0 +1,12 @@
+package com.baeldung.java14.recordvslombok;
+
+import lombok.Value;
+
+@Value
+public class MonochromeColor extends ColorData {
+
+ public MonochromeColor(int grayScale) {
+ super(grayScale, grayScale, grayScale);
+ }
+
+}
diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/StudentBuilder.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/StudentBuilder.java
new file mode 100644
index 0000000000..318634788e
--- /dev/null
+++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/StudentBuilder.java
@@ -0,0 +1,17 @@
+package com.baeldung.java14.recordvslombok;
+
+import lombok.Builder;
+import lombok.Getter;
+
+@Getter
+@Builder
+public class StudentBuilder {
+ private String firstName;
+ private String lastName;
+ private Long studentId;
+ private String email;
+ private String phoneNumber;
+ private String address;
+ private String country;
+ private int age;
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/StudentRecord.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/StudentRecord.java
new file mode 100644
index 0000000000..2d51fadd12
--- /dev/null
+++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/recordvslombok/StudentRecord.java
@@ -0,0 +1,4 @@
+package com.baeldung.java14.recordvslombok;
+
+public record StudentRecord(String firstName, String lastName, Long studentId, String email, String phoneNumber, String address, String country, int age) {
+}
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/recordvslombok/RecordVsLombokUntTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/recordvslombok/RecordVsLombokUntTest.java
new file mode 100644
index 0000000000..1cca13133f
--- /dev/null
+++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/recordvslombok/RecordVsLombokUntTest.java
@@ -0,0 +1,43 @@
+package com.baeldung.java14.recordvslombok;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+public class RecordVsLombokUntTest {
+
+ @Test
+ public void givenAColorRecord_hexStringIsCorrect() {
+ var red = new ColorRecord(255, 0, 0);
+
+ assertThat(red.getHexString()).isEqualTo("#FF0000");
+ }
+
+ @Test
+ public void givenAColorValueObject_hexStringIsCorrect() {
+ var red = new ColorValueObject(255, 0, 0);
+
+ assertThat(red.getHexString()).isEqualTo("#FF0000");
+ }
+
+ @Test
+ public void givenRecordWithManyAttributes_firstNameShouldBeJohn() {
+ StudentRecord john = new StudentRecord("John", "Doe", null, "john@doe.com", null, null, "England", 20);
+
+ assertThat(john.firstName()).isEqualTo("John");
+ }
+
+ @Test
+ public void givenBuilderWithManyAttributes_firstNameShouldBeJohn() {
+ StudentBuilder john = StudentBuilder.builder()
+ .firstName("John")
+ .lastName("Doe")
+ .email("john@doe.com")
+ .country("England")
+ .age(20)
+ .build();
+
+ assertThat(john.getFirstName()).isEqualTo("John");
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-15/README.md b/core-java-modules/core-java-15/README.md
index 4b163fcfb5..6c4fcff419 100644
--- a/core-java-modules/core-java-15/README.md
+++ b/core-java-modules/core-java-15/README.md
@@ -5,4 +5,3 @@ This module contains articles about Java 15.
### Relevant articles
- [Hidden Classes in Java 15](https://www.baeldung.com/java-hidden-classes)
-- [Sealed Classes and Interfaces in Java 15](https://www.baeldung.com/java-sealed-classes-interfaces)
diff --git a/core-java-modules/core-java-16/src/main/java/com/baeldung/java_16_features/groupingby/BlogPost.java b/core-java-modules/core-java-16/src/main/java/com/baeldung/java_16_features/groupingby/BlogPost.java
index 960a75a58e..314fbeeeb5 100644
--- a/core-java-modules/core-java-16/src/main/java/com/baeldung/java_16_features/groupingby/BlogPost.java
+++ b/core-java-modules/core-java-16/src/main/java/com/baeldung/java_16_features/groupingby/BlogPost.java
@@ -4,15 +4,15 @@ import java.util.IntSummaryStatistics;
public class BlogPost {
-
+
private String title;
private String author;
private BlogPostType type;
private int likes;
record AuthPostTypesLikes(String author, BlogPostType type, int likes) {};
- record PostcountTitlesLikesStats(long postCount, String titles, IntSummaryStatistics likesStats){};
+ record PostCountTitlesLikesStats(long postCount, String titles, IntSummaryStatistics likesStats){};
record TitlesBoundedSumOfLikes(String titles, int boundedSumOfLikes) {};
-
+
public BlogPost(String title, String author, BlogPostType type, int likes) {
this.title = title;
this.author = author;
diff --git a/core-java-modules/core-java-16/src/test/java/com/baeldung/java_16_features/groupingby/JavaGroupingByCollectorUnitTest.java b/core-java-modules/core-java-16/src/test/java/com/baeldung/java_16_features/groupingby/JavaGroupingByCollectorUnitTest.java
index 0dea142658..603bebb7c5 100644
--- a/core-java-modules/core-java-16/src/test/java/com/baeldung/java_16_features/groupingby/JavaGroupingByCollectorUnitTest.java
+++ b/core-java-modules/core-java-16/src/test/java/com/baeldung/java_16_features/groupingby/JavaGroupingByCollectorUnitTest.java
@@ -257,7 +257,7 @@ public class JavaGroupingByCollectorUnitTest {
@Test
public void givenListOfPosts_whenGroupedByAuthor_thenGetAMapUsingCollectingAndThen() {
- Map postsPerAuthor = posts.stream()
+ Map postsPerAuthor = posts.stream()
.collect(groupingBy(BlogPost::getAuthor, collectingAndThen(toList(), list -> {
long count = list.stream()
.map(BlogPost::getTitle)
@@ -267,10 +267,10 @@ public class JavaGroupingByCollectorUnitTest {
.collect(joining(" : "));
IntSummaryStatistics summary = list.stream()
.collect(summarizingInt(BlogPost::getLikes));
- return new BlogPost.PostcountTitlesLikesStats(count, titles, summary);
+ return new BlogPost.PostCountTitlesLikesStats(count, titles, summary);
})));
- BlogPost.PostcountTitlesLikesStats result = postsPerAuthor.get("Author 1");
+ BlogPost.PostCountTitlesLikesStats result = postsPerAuthor.get("Author 1");
assertThat(result.postCount()).isEqualTo(3L);
assertThat(result.titles()).isEqualTo("News item 1 : Programming guide : Tech review 2");
assertThat(result.likesStats().getMax()).isEqualTo(20);
@@ -294,7 +294,7 @@ public class JavaGroupingByCollectorUnitTest {
.toUpperCase(),
u1.boundedSumOfLikes() + likes);
}));
-
+
BlogPost.TitlesBoundedSumOfLikes result = postsPerAuthor.get("Author 1");
assertThat(result.titles()).isEqualTo("NEWS ITEM 1 : PROGRAMMING GUIDE : TECH REVIEW 2");
assertThat(result.boundedSumOfLikes()).isEqualTo(47);
diff --git a/core-java-modules/core-java-17/README.md b/core-java-modules/core-java-17/README.md
index 1f061bd7c1..d77a487932 100644
--- a/core-java-modules/core-java-17/README.md
+++ b/core-java-modules/core-java-17/README.md
@@ -5,3 +5,4 @@
- [Introduction to HexFormat in Java 17](https://www.baeldung.com/java-hexformat)
- [New Features in Java 17](https://www.baeldung.com/java-17-new-features)
- [Random Number Generators in Java 17](https://www.baeldung.com/java-17-random-number-generators)
+- [Sealed Classes and Interfaces in Java 17](https://www.baeldung.com/java-sealed-classes-interfaces)
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/alternative/Vehicles.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/alternative/Vehicles.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Car.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Car.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Service.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Service.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Truck.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Truck.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Vehicle.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Vehicle.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/records/Car.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/records/Car.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/records/Truck.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/records/Truck.java
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java b/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/records/Vehicle.java
similarity index 100%
rename from core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java
rename to core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/records/Vehicle.java
diff --git a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java b/core-java-modules/core-java-17/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
similarity index 93%
rename from core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
rename to core-java-modules/core-java-17/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
index b614981a43..73d8aad810 100644
--- a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
+++ b/core-java-modules/core-java-17/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
@@ -21,7 +21,7 @@ public class VehicleUnitTest {
public void givenCar_whenUsingReflectionAPI_thenSuperClassIsSealed() {
Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false);
Assertions.assertThat(car.getClass().getSuperclass().isSealed()).isEqualTo(true);
- Assertions.assertThat(car.getClass().getSuperclass().permittedSubclasses())
+ Assertions.assertThat(car.getClass().getSuperclass().getPermittedSubclasses())
.contains(ClassDesc.of(car.getClass().getCanonicalName()));
}
@@ -29,7 +29,7 @@ public class VehicleUnitTest {
public void givenTruck_whenUsingReflectionAPI_thenSuperClassIsSealed() {
Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false);
Assertions.assertThat(truck.getClass().getSuperclass().isSealed()).isEqualTo(true);
- Assertions.assertThat(truck.getClass().getSuperclass().permittedSubclasses())
+ Assertions.assertThat(truck.getClass().getSuperclass().getPermittedSubclasses())
.contains(ClassDesc.of(truck.getClass().getCanonicalName()));
}
diff --git a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java b/core-java-modules/core-java-17/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java
similarity index 100%
rename from core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java
rename to core-java-modules/core-java-17/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java
diff --git a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/inputstream/outputstream/InputStreamToOutputStreamUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/inputstream/outputstream/InputStreamToOutputStreamUnitTest.java
index 814824e580..69c2e7d69d 100644
--- a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/inputstream/outputstream/InputStreamToOutputStreamUnitTest.java
+++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/inputstream/outputstream/InputStreamToOutputStreamUnitTest.java
@@ -20,7 +20,7 @@ public class InputStreamToOutputStreamUnitTest {
void copy(InputStream source, OutputStream target) throws IOException {
byte[] buf = new byte[8192];
int length;
- while ((length = source.read(buf)) > 0) {
+ while ((length = source.read(buf)) != -1) {
target.write(buf, 0, length);
}
}
diff --git a/core-java-modules/core-java-jar/README.md b/core-java-modules/core-java-jar/README.md
index b1e24e3ab9..c99ea63b22 100644
--- a/core-java-modules/core-java-jar/README.md
+++ b/core-java-modules/core-java-jar/README.md
@@ -10,3 +10,5 @@ This module contains articles about JAR files
- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names)
- [Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)
- [Creating JAR Files Programmatically](https://www.baeldung.com/jar-create-programatically)
+- [Guide to Creating Jar Executables and Windows Executables from Java](https://www.baeldung.com/jar-windows-executables)
+- [Get the Full Path of a JAR File From a Class](https://www.baeldung.com/java-full-path-of-jar-from-class)
diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml
index 19da9b8a56..c56fcbd8b5 100644
--- a/core-java-modules/core-java-jar/pom.xml
+++ b/core-java-modules/core-java-jar/pom.xml
@@ -54,6 +54,12 @@
moneta
${javamoney.moneta.version}
+
+ org.mockito
+ mockito-junit-jupiter
+ ${mockito.version}
+ test
+
@@ -266,6 +272,7 @@
0.4
1.8.7
+ 4.6.1
1.1
3.0.0-M1
@@ -279,4 +286,4 @@
1.8
-
\ No newline at end of file
+
diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java
new file mode 100644
index 0000000000..86d52eed56
--- /dev/null
+++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java
@@ -0,0 +1,31 @@
+package com.baeldung.jar;
+
+import java.awt.event.*;
+import java.awt.*;
+
+import javax.swing.*;
+
+public class MySampleGUIAppn extends JFrame {
+ public MySampleGUIAppn() {
+ if (!GraphicsEnvironment.isHeadless()) {
+ setSize(300,300);
+ setTitle("MySampleGUIAppn");
+ Button b = new Button("Click Me!");
+ b.setBounds(30,100,80,30);
+ add(b);
+ setVisible(true);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ dispose();
+ System.exit(0);
+ }
+ });
+ }
+ else {
+ System.exit(0);
+ }
+ }
+ public static void main(String[] args) {
+ MySampleGUIAppn app=new MySampleGUIAppn();
+ }
+}
diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jarfile/JarFilePathResolver.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jarfile/JarFilePathResolver.java
new file mode 100644
index 0000000000..3dab91f31a
--- /dev/null
+++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jarfile/JarFilePathResolver.java
@@ -0,0 +1,42 @@
+package com.baeldung.jarfile;
+
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Paths;
+
+public class JarFilePathResolver {
+
+ public String getJarFilePath(Class clazz) {
+ try {
+ return byGetProtectionDomain(clazz);
+ } catch (Exception e) {
+ // cannot get jar file path using byGetProtectionDomain
+ // Exception handling omitted
+ }
+ return byGetResource(clazz);
+ }
+
+ String byGetProtectionDomain(Class clazz) throws URISyntaxException {
+ URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
+ return Paths.get(url.toURI()).toString();
+ }
+
+ String byGetResource(Class clazz) {
+ final URL classResource = clazz.getResource(clazz.getSimpleName() + ".class");
+ if (classResource == null) {
+ throw new RuntimeException("class resource is null");
+ }
+
+ final String url = classResource.toString();
+ if (url.startsWith("jar:file:")) {
+ // extract 'file:......jarName.jar' part from the url string
+ String path = url.replaceAll("^jar:(file:.*[.]jar)!/.*", "$1");
+ try {
+ return Paths.get(new URL(path).toURI()).toString();
+ } catch (Exception e) {
+ throw new RuntimeException("Invalid Jar File URL String");
+ }
+ }
+ throw new RuntimeException("Invalid Jar File URL String");
+ }
+}
diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java
new file mode 100644
index 0000000000..106531008c
--- /dev/null
+++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java
@@ -0,0 +1,15 @@
+package com.baeldung.jar;
+
+import java.io.IOException;
+
+import org.junit.jupiter.api.Test;
+
+class MySampleGUIAppnUnitTest {
+ @Test
+ void testMain() throws IOException {
+ System.setProperty("java.awt.headless", "true");
+ String [] args = null;
+ System.exit(0);
+ MySampleGUIAppn.main(args);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jarfile/JarFilePathResolverUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jarfile/JarFilePathResolverUnitTest.java
new file mode 100644
index 0000000000..ad84bd9379
--- /dev/null
+++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jarfile/JarFilePathResolverUnitTest.java
@@ -0,0 +1,55 @@
+package com.baeldung.jarfile;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Ascii;
+import java.io.File;
+import java.net.URISyntaxException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class JarFilePathResolverUnitTest {
+ @Spy
+ JarFilePathResolver jarFilePathResolver;
+
+ @Test
+ void givenClassObjectWhenCallingByGetProtectionDomainShouldGetExpectedPath() throws Exception {
+ String jarPath = jarFilePathResolver.byGetProtectionDomain(Ascii.class);
+ assertThat(jarPath).endsWith(".jar").contains("guava");
+ assertThat(new File(jarPath)).exists();
+ }
+
+ @Test
+ void givenClassObjectWhenCallingByGetResourceShouldGetExpectedPath() {
+ String jarPath = jarFilePathResolver.byGetResource(Ascii.class);
+ assertThat(jarPath).endsWith(".jar").contains("guava");
+ assertThat(new File(jarPath)).exists();
+ }
+
+ @Test
+ void givenClassObjectWhenNoSecurityExceptionRaisedShouldGetExpectedPath() throws URISyntaxException {
+ String jarPath = jarFilePathResolver.getJarFilePath(Ascii.class);
+ assertThat(jarPath).endsWith(".jar").contains("guava");
+ assertThat(new File(jarPath)).exists();
+ verify(jarFilePathResolver, times(1)).byGetProtectionDomain(Ascii.class);
+ verify(jarFilePathResolver, never()).byGetResource(Ascii.class);
+ }
+
+ @Test
+ void givenClassObjectWhenSecurityExceptionRaisedShouldGetExpectedPath() throws URISyntaxException {
+ when(jarFilePathResolver.byGetProtectionDomain(Ascii.class)).thenThrow(new SecurityException("not allowed"));
+ String jarPath = jarFilePathResolver.getJarFilePath(Ascii.class);
+ assertThat(jarPath).endsWith(".jar").contains("guava");
+ assertThat(new File(jarPath)).exists();
+ verify(jarFilePathResolver, times(1)).byGetProtectionDomain(Ascii.class);
+ verify(jarFilePathResolver, times(1)).byGetResource(Ascii.class);
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-5/README.md b/core-java-modules/core-java-lang-5/README.md
index 8920e9c231..9505d02fc2 100644
--- a/core-java-modules/core-java-lang-5/README.md
+++ b/core-java-modules/core-java-lang-5/README.md
@@ -5,3 +5,4 @@ This module contains articles about core features in the Java language
### Relevant Articles:
- [Difference Between == and equals() in Java](https://www.baeldung.com/java-equals-method-operator-difference)
+- [Advantages and Disadvantages of Using Java Wildcard Imports](https://www.baeldung.com/java-wildcard-imports)
diff --git a/core-java-modules/core-java-lang-5/pom.xml b/core-java-modules/core-java-lang-5/pom.xml
index 6d3771bd31..5255866f03 100644
--- a/core-java-modules/core-java-lang-5/pom.xml
+++ b/core-java-modules/core-java-lang-5/pom.xml
@@ -13,7 +13,6 @@
core-java-modules
0.0.1-SNAPSHOT
-
core-java-lang-5
@@ -23,5 +22,4 @@
-
-
\ No newline at end of file
+
diff --git a/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/specific/Book.java b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/specific/Book.java
new file mode 100644
index 0000000000..5877147082
--- /dev/null
+++ b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/specific/Book.java
@@ -0,0 +1,17 @@
+package com.baeldung.imports.specific;
+
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+public class Book {
+
+ private UUID id;
+
+ private String name;
+
+ private Date datePublished;
+
+ private List authors;
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/Book.java b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/Book.java
new file mode 100644
index 0000000000..18754cdd28
--- /dev/null
+++ b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/Book.java
@@ -0,0 +1,15 @@
+package com.baeldung.imports.wildcard;
+
+import java.util.*;
+
+public class Book {
+
+ private UUID id;
+
+ private String name;
+
+ private Date datePublished;
+
+ private List authors;
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/BookView.java b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/BookView.java
new file mode 100644
index 0000000000..e6e21ab03d
--- /dev/null
+++ b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/BookView.java
@@ -0,0 +1,17 @@
+package com.baeldung.imports.wildcard;
+
+import java.awt.*;
+import java.util.*;
+import java.util.List;
+
+public class BookView extends Frame {
+
+ private UUID id;
+
+ private String name;
+
+ private Date datePublished;
+
+ private List authors;
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/Library.java b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/Library.java
new file mode 100644
index 0000000000..8e1d79aca4
--- /dev/null
+++ b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/imports/wildcard/Library.java
@@ -0,0 +1,19 @@
+package com.baeldung.imports.wildcard;
+
+import java.util.*;
+import java.sql.*;
+import java.sql.Date;
+
+public class Library {
+
+ private UUID id;
+
+ private String name;
+
+ private Time openingTime;
+
+ private Time closingTime;
+
+ private List datesClosed;
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java
index b1a6a1fe57..cb1b5e926a 100644
--- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java
+++ b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/PersonAndEmployeeReflectionUnitTest.java
@@ -9,7 +9,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import static org.junit.Assert.*;
diff --git a/core-java-modules/core-java-string-apis/README.md b/core-java-modules/core-java-string-apis/README.md
index 0dd24d7e9a..68f2176ed6 100644
--- a/core-java-modules/core-java-string-apis/README.md
+++ b/core-java-modules/core-java-string-apis/README.md
@@ -11,3 +11,4 @@ This module contains articles about string APIs.
- [StringBuilder vs StringBuffer in Java](https://www.baeldung.com/java-string-builder-string-buffer)
- [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password)
- [Getting a Character by Index From a String in Java](https://www.baeldung.com/java-character-at-position)
+- [Clearing a StringBuilder or StringBuffer](https://www.baeldung.com/java-clear-stringbuilder-stringbuffer)
diff --git a/core-java-modules/core-java-string-apis/src/main/java/com/baeldung/clearstringbuilderorstringbuffer/BenchmarkRunner.java b/core-java-modules/core-java-string-apis/src/main/java/com/baeldung/clearstringbuilderorstringbuffer/BenchmarkRunner.java
new file mode 100644
index 0000000000..e0cead9c77
--- /dev/null
+++ b/core-java-modules/core-java-string-apis/src/main/java/com/baeldung/clearstringbuilderorstringbuffer/BenchmarkRunner.java
@@ -0,0 +1,32 @@
+package com.baeldung.clearstringbuilderorstringbuffer;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.infra.Blackhole;
+
+public class BenchmarkRunner {
+
+ public static void main(String[] args) throws Exception {
+ org.openjdk.jmh.Main.main(args);
+ }
+
+ @State(Scope.Benchmark)
+ public static class MyState {
+ final String HELLO = "Hello World";
+ final StringBuilder sb = new StringBuilder().append(HELLO);
+ }
+
+ @Benchmark
+ public void evaluateSetLength(Blackhole blackhole, MyState state) {
+ state.sb.setLength(0);
+ blackhole.consume(state.sb.toString());
+ }
+
+ @Benchmark
+ public void evaluateDelete(Blackhole blackhole, MyState state) {
+ state.sb.delete(0, state.sb.length());
+ blackhole.consume(state.sb.toString());
+ }
+
+}
diff --git a/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/clearstringbuilderorstringbuffer/ClearStringBuilderOrStringBufferUnitTest.java b/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/clearstringbuilderorstringbuffer/ClearStringBuilderOrStringBufferUnitTest.java
new file mode 100644
index 0000000000..ad46c23969
--- /dev/null
+++ b/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/clearstringbuilderorstringbuffer/ClearStringBuilderOrStringBufferUnitTest.java
@@ -0,0 +1,66 @@
+package com.baeldung.clearstringbuilderorstringbuffer;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ClearStringBuilderOrStringBufferUnitTest {
+
+ @Test
+ void whenSetLengthToZero_ThenStringBuilderIsCleared() {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("Hello World");
+ int initialCapacity = stringBuilder.capacity();
+ stringBuilder.setLength(0);
+ assertEquals("", stringBuilder.toString());
+ assertEquals(initialCapacity, stringBuilder.capacity());
+ }
+
+ @Test
+ void whenDeleteAll_ThenStringBuilderIsCleared() {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("Hello World");
+ int initialCapacity = stringBuilder.capacity();
+ stringBuilder.delete(0, stringBuilder.length());
+ assertEquals("", stringBuilder.toString());
+ assertEquals(initialCapacity, stringBuilder.capacity());
+ }
+
+ @Test
+ void whenSetLengthToZero_ThenStringBufferIsCleared() {
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append("Hello World");
+ int initialCapacity = stringBuffer.capacity();
+ stringBuffer.setLength(0);
+ assertEquals("", stringBuffer.toString());
+ assertEquals(initialCapacity, stringBuffer.capacity());
+ }
+
+ @Test
+ void whenDeleteAll_ThenStringBufferIsCleared() {
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append("Hello World");
+ int initialCapacity = stringBuffer.capacity();
+ stringBuffer.delete(0, stringBuffer.length());
+ assertEquals("", stringBuffer.toString());
+ assertEquals(initialCapacity, stringBuffer.capacity());
+ }
+
+ // Note: It did not make the cut to the article, but here is another way to reset a StringBuilder
+ @Test
+ void whenAssignedToNewStringBuilder_ThenStringBuilderIsCleared() {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("Hello World");
+ stringBuilder = new StringBuilder();
+ assertEquals("", stringBuilder.toString());
+ }
+
+ @Test
+ void whenAssignedToNewStringBuffer_ThenStringBufferIsCleared() {
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append("Hello World");
+ stringBuffer = new StringBuffer();
+ assertEquals("", stringBuffer.toString());
+ }
+
+}
diff --git a/core-java-modules/core-java-string-operations-4/README.md b/core-java-modules/core-java-string-operations-4/README.md
index ff6d887154..ac52ee4ab5 100644
--- a/core-java-modules/core-java-string-operations-4/README.md
+++ b/core-java-modules/core-java-string-operations-4/README.md
@@ -7,4 +7,4 @@
- [String equals() Vs contentEquals() in Java](https://www.baeldung.com/java-string-equals-vs-contentequals)
- [Check if a String Ends with a Certain Pattern in Java](https://www.baeldung.com/java-string-ends-pattern)
- [Check if a Character is a Vowel in Java](https://www.baeldung.com/java-check-character-vowel)
-
+- [How to Truncate a String in Java](https://www.baeldung.com/java-truncating-strings)
diff --git a/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/Java8EncodeDecodeUnitTest.java b/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/Java8EncodeDecodeUnitTest.java
index 191a3628e8..f7efd7c731 100644
--- a/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/Java8EncodeDecodeUnitTest.java
+++ b/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/Java8EncodeDecodeUnitTest.java
@@ -96,7 +96,23 @@ public class Java8EncodeDecodeUnitTest {
assertNotNull(decodedMime);
}
- //
+ @Test
+ public void whenEncodedStringHasValidCharacters_thenStringCanBeDecoded() {
+ final String encodedString = "dGVzdCMkaW5wdXQ+";
+ final byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
+ final String decodedString = new String(decodedBytes);
+
+ assertNotNull(decodedString);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void whenEncodedStringHasInvalidCharacters_thenIllegalArgumentException() {
+ final String encodedString = "dGVzdCMkaW5wdXQ#";
+ final byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
+ final String decodedString = new String(decodedBytes);
+
+ assertNotNull(decodedString);
+ }
private static StringBuilder getMimeBuffer() {
final StringBuilder buffer = new StringBuilder();
diff --git a/docker-modules/docker-java-jar/Dockerfile b/docker-modules/docker-java-jar/Dockerfile
new file mode 100644
index 0000000000..bc26e031c3
--- /dev/null
+++ b/docker-modules/docker-java-jar/Dockerfile
@@ -0,0 +1,4 @@
+FROM openjdk:11
+MAINTAINER baeldung.com
+COPY target/docker-java-jar-0.0.1-SNAPSHOT.jar app.jar
+ENTRYPOINT ["java","-jar","/app.jar"]
diff --git a/docker-modules/docker-java-jar/pom.xml b/docker-modules/docker-java-jar/pom.xml
new file mode 100644
index 0000000000..0ca0146ac0
--- /dev/null
+++ b/docker-modules/docker-java-jar/pom.xml
@@ -0,0 +1,37 @@
+
+
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
+ 4.0.0
+
+ docker-java-jar
+
+
+ 11
+ 11
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ ${maven-jar-plugin.version}
+
+
+
+ com.baeldung.HelloWorld
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docker-modules/docker-java-jar/src/main/java/com/baeldung/HelloWorld.java b/docker-modules/docker-java-jar/src/main/java/com/baeldung/HelloWorld.java
new file mode 100644
index 0000000000..50e0044c48
--- /dev/null
+++ b/docker-modules/docker-java-jar/src/main/java/com/baeldung/HelloWorld.java
@@ -0,0 +1,8 @@
+package com.baeldung;
+
+public class HelloWorld {
+
+ public static void main(String[] args){
+ System.out.println("Welcome to our application");
+ }
+}
diff --git a/docker-modules/pom.xml b/docker-modules/pom.xml
index f2b8f059a1..d80e5341b0 100644
--- a/docker-modules/pom.xml
+++ b/docker-modules/pom.xml
@@ -23,6 +23,7 @@
docker-images
docker-spring-boot
docker-spring-boot-postgres
+ docker-java-jar
diff --git a/gradle-modules/README.md b/gradle-modules/README.md
new file mode 100644
index 0000000000..a4d8875b15
--- /dev/null
+++ b/gradle-modules/README.md
@@ -0,0 +1,3 @@
+## Gradle Modules
+
+This module contains submodules of Gradle.
\ No newline at end of file
diff --git a/gradle-5/.gitignore b/gradle-modules/gradle-5/.gitignore
similarity index 100%
rename from gradle-5/.gitignore
rename to gradle-modules/gradle-5/.gitignore
diff --git a/gradle-5/README.md b/gradle-modules/gradle-5/README.md
similarity index 100%
rename from gradle-5/README.md
rename to gradle-modules/gradle-5/README.md
diff --git a/gradle-5/build.gradle b/gradle-modules/gradle-5/build.gradle
similarity index 100%
rename from gradle-5/build.gradle
rename to gradle-modules/gradle-5/build.gradle
diff --git a/gradle-5/cmd-line-args/README.md b/gradle-modules/gradle-5/cmd-line-args/README.md
similarity index 100%
rename from gradle-5/cmd-line-args/README.md
rename to gradle-modules/gradle-5/cmd-line-args/README.md
diff --git a/gradle-5/cmd-line-args/build.gradle b/gradle-modules/gradle-5/cmd-line-args/build.gradle
similarity index 100%
rename from gradle-5/cmd-line-args/build.gradle
rename to gradle-modules/gradle-5/cmd-line-args/build.gradle
diff --git a/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java b/gradle-modules/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java
similarity index 100%
rename from gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java
rename to gradle-modules/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java
diff --git a/gradle-5/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle-5/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle-5/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle-5/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle-5/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle-5/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle-5/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle-5/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle-5/gradlew b/gradle-modules/gradle-5/gradlew
similarity index 100%
rename from gradle-5/gradlew
rename to gradle-modules/gradle-5/gradlew
diff --git a/gradle-5/gradlew.bat b/gradle-modules/gradle-5/gradlew.bat
similarity index 100%
rename from gradle-5/gradlew.bat
rename to gradle-modules/gradle-5/gradlew.bat
diff --git a/gradle-5/java-exec/.gitignore b/gradle-modules/gradle-5/java-exec/.gitignore
similarity index 100%
rename from gradle-5/java-exec/.gitignore
rename to gradle-modules/gradle-5/java-exec/.gitignore
diff --git a/gradle-5/java-exec/build.gradle b/gradle-modules/gradle-5/java-exec/build.gradle
similarity index 100%
rename from gradle-5/java-exec/build.gradle
rename to gradle-modules/gradle-5/java-exec/build.gradle
diff --git a/gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java b/gradle-modules/gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java
similarity index 100%
rename from gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java
rename to gradle-modules/gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java
diff --git a/gradle-5/settings.gradle b/gradle-modules/gradle-5/settings.gradle
similarity index 71%
rename from gradle-5/settings.gradle
rename to gradle-modules/gradle-5/settings.gradle
index ede73daf0a..c73af319a3 100644
--- a/gradle-5/settings.gradle
+++ b/gradle-modules/gradle-5/settings.gradle
@@ -1,4 +1,4 @@
-rootProject.name='gradle-5-articles'
+rootProject.name='gradle-5'
include 'java-exec'
include 'unused-dependencies'
include 'source-sets'
diff --git a/gradle-5/source-sets/.gitignore b/gradle-modules/gradle-5/source-sets/.gitignore
similarity index 100%
rename from gradle-5/source-sets/.gitignore
rename to gradle-modules/gradle-5/source-sets/.gitignore
diff --git a/gradle-5/source-sets/README.md b/gradle-modules/gradle-5/source-sets/README.md
similarity index 100%
rename from gradle-5/source-sets/README.md
rename to gradle-modules/gradle-5/source-sets/README.md
diff --git a/gradle-5/source-sets/build.gradle b/gradle-modules/gradle-5/source-sets/build.gradle
similarity index 100%
rename from gradle-5/source-sets/build.gradle
rename to gradle-modules/gradle-5/source-sets/build.gradle
diff --git a/gradle-5/source-sets/src/itest/java/com/baeldung/itest/SourceSetsItest.java b/gradle-modules/gradle-5/source-sets/src/itest/java/com/baeldung/itest/SourceSetsItest.java
similarity index 100%
rename from gradle-5/source-sets/src/itest/java/com/baeldung/itest/SourceSetsItest.java
rename to gradle-modules/gradle-5/source-sets/src/itest/java/com/baeldung/itest/SourceSetsItest.java
diff --git a/gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsMain.java b/gradle-modules/gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsMain.java
similarity index 100%
rename from gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsMain.java
rename to gradle-modules/gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsMain.java
diff --git a/gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsObject.java b/gradle-modules/gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsObject.java
similarity index 100%
rename from gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsObject.java
rename to gradle-modules/gradle-5/source-sets/src/main/java/com/baeldung/main/SourceSetsObject.java
diff --git a/gradle-5/source-sets/src/test/java/com/baeldung/test/SourceSetsTest.java b/gradle-modules/gradle-5/source-sets/src/test/java/com/baeldung/test/SourceSetsTest.java
similarity index 100%
rename from gradle-5/source-sets/src/test/java/com/baeldung/test/SourceSetsTest.java
rename to gradle-modules/gradle-5/source-sets/src/test/java/com/baeldung/test/SourceSetsTest.java
diff --git a/gradle-5/unused-dependencies/.gitignore b/gradle-modules/gradle-5/unused-dependencies/.gitignore
similarity index 100%
rename from gradle-5/unused-dependencies/.gitignore
rename to gradle-modules/gradle-5/unused-dependencies/.gitignore
diff --git a/gradle-5/unused-dependencies/build.gradle b/gradle-modules/gradle-5/unused-dependencies/build.gradle
similarity index 100%
rename from gradle-5/unused-dependencies/build.gradle
rename to gradle-modules/gradle-5/unused-dependencies/build.gradle
diff --git a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java b/gradle-modules/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java
similarity index 100%
rename from gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java
rename to gradle-modules/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java
diff --git a/gradle-6/.gitignore b/gradle-modules/gradle-6/.gitignore
similarity index 100%
rename from gradle-6/.gitignore
rename to gradle-modules/gradle-6/.gitignore
diff --git a/gradle-6/README.md b/gradle-modules/gradle-6/README.md
similarity index 100%
rename from gradle-6/README.md
rename to gradle-modules/gradle-6/README.md
diff --git a/gradle-6/build.gradle.kts b/gradle-modules/gradle-6/build.gradle.kts
similarity index 100%
rename from gradle-6/build.gradle.kts
rename to gradle-modules/gradle-6/build.gradle.kts
diff --git a/gradle-6/configuration-avoidance/build.gradle.kts b/gradle-modules/gradle-6/configuration-avoidance/build.gradle.kts
similarity index 100%
rename from gradle-6/configuration-avoidance/build.gradle.kts
rename to gradle-modules/gradle-6/configuration-avoidance/build.gradle.kts
diff --git a/gradle-6/dependency-constraints/build.gradle.kts b/gradle-modules/gradle-6/dependency-constraints/build.gradle.kts
similarity index 100%
rename from gradle-6/dependency-constraints/build.gradle.kts
rename to gradle-modules/gradle-6/dependency-constraints/build.gradle.kts
diff --git a/gradle-6/dependency-constraints/src/main/java/com/baeldung/gradle/RxHelloWorld.java b/gradle-modules/gradle-6/dependency-constraints/src/main/java/com/baeldung/gradle/RxHelloWorld.java
similarity index 100%
rename from gradle-6/dependency-constraints/src/main/java/com/baeldung/gradle/RxHelloWorld.java
rename to gradle-modules/gradle-6/dependency-constraints/src/main/java/com/baeldung/gradle/RxHelloWorld.java
diff --git a/gradle-6/dependency-constraints/src/test/java/com/baeldung/gradle/RxHelloWorldUnitTest.java b/gradle-modules/gradle-6/dependency-constraints/src/test/java/com/baeldung/gradle/RxHelloWorldUnitTest.java
similarity index 100%
rename from gradle-6/dependency-constraints/src/test/java/com/baeldung/gradle/RxHelloWorldUnitTest.java
rename to gradle-modules/gradle-6/dependency-constraints/src/test/java/com/baeldung/gradle/RxHelloWorldUnitTest.java
diff --git a/gradle-6/fibonacci-recursive/build.gradle.kts b/gradle-modules/gradle-6/fibonacci-recursive/build.gradle.kts
similarity index 100%
rename from gradle-6/fibonacci-recursive/build.gradle.kts
rename to gradle-modules/gradle-6/fibonacci-recursive/build.gradle.kts
diff --git a/gradle-6/fibonacci-recursive/src/main/java/com/baeldung/fibonacci/impl/RecursiveFibonacci.java b/gradle-modules/gradle-6/fibonacci-recursive/src/main/java/com/baeldung/fibonacci/impl/RecursiveFibonacci.java
similarity index 100%
rename from gradle-6/fibonacci-recursive/src/main/java/com/baeldung/fibonacci/impl/RecursiveFibonacci.java
rename to gradle-modules/gradle-6/fibonacci-recursive/src/main/java/com/baeldung/fibonacci/impl/RecursiveFibonacci.java
diff --git a/gradle-6/fibonacci-recursive/src/test/java/com/baeldung/fibonacci/impl/RecursiveFibonacciUnitTest.java b/gradle-modules/gradle-6/fibonacci-recursive/src/test/java/com/baeldung/fibonacci/impl/RecursiveFibonacciUnitTest.java
similarity index 100%
rename from gradle-6/fibonacci-recursive/src/test/java/com/baeldung/fibonacci/impl/RecursiveFibonacciUnitTest.java
rename to gradle-modules/gradle-6/fibonacci-recursive/src/test/java/com/baeldung/fibonacci/impl/RecursiveFibonacciUnitTest.java
diff --git a/gradle-6/fibonacci-spi/build.gradle.kts b/gradle-modules/gradle-6/fibonacci-spi/build.gradle.kts
similarity index 100%
rename from gradle-6/fibonacci-spi/build.gradle.kts
rename to gradle-modules/gradle-6/fibonacci-spi/build.gradle.kts
diff --git a/gradle-6/fibonacci-spi/src/main/java/com/baeldung/fibonacci/FibonacciSequenceGenerator.java b/gradle-modules/gradle-6/fibonacci-spi/src/main/java/com/baeldung/fibonacci/FibonacciSequenceGenerator.java
similarity index 100%
rename from gradle-6/fibonacci-spi/src/main/java/com/baeldung/fibonacci/FibonacciSequenceGenerator.java
rename to gradle-modules/gradle-6/fibonacci-spi/src/main/java/com/baeldung/fibonacci/FibonacciSequenceGenerator.java
diff --git a/gradle-6/fibonacci-spi/src/testFixtures/java/com/baeldung/fibonacci/FibonacciSequenceGeneratorFixture.java b/gradle-modules/gradle-6/fibonacci-spi/src/testFixtures/java/com/baeldung/fibonacci/FibonacciSequenceGeneratorFixture.java
similarity index 100%
rename from gradle-6/fibonacci-spi/src/testFixtures/java/com/baeldung/fibonacci/FibonacciSequenceGeneratorFixture.java
rename to gradle-modules/gradle-6/fibonacci-spi/src/testFixtures/java/com/baeldung/fibonacci/FibonacciSequenceGeneratorFixture.java
diff --git a/gradle-6/gradle.properties b/gradle-modules/gradle-6/gradle.properties
similarity index 100%
rename from gradle-6/gradle.properties
rename to gradle-modules/gradle-6/gradle.properties
diff --git a/gradle-6/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle-6/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle-6/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle-6/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle-6/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle-6/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle-6/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle-6/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle-6/gradlew b/gradle-modules/gradle-6/gradlew
similarity index 100%
rename from gradle-6/gradlew
rename to gradle-modules/gradle-6/gradlew
diff --git a/gradle-6/gradlew.bat b/gradle-modules/gradle-6/gradlew.bat
similarity index 100%
rename from gradle-6/gradlew.bat
rename to gradle-modules/gradle-6/gradlew.bat
diff --git a/gradle-6/httpclient-platform/build.gradle.kts b/gradle-modules/gradle-6/httpclient-platform/build.gradle.kts
similarity index 100%
rename from gradle-6/httpclient-platform/build.gradle.kts
rename to gradle-modules/gradle-6/httpclient-platform/build.gradle.kts
diff --git a/gradle-6/module-metadata-publishing/build.gradle.kts b/gradle-modules/gradle-6/module-metadata-publishing/build.gradle.kts
similarity index 100%
rename from gradle-6/module-metadata-publishing/build.gradle.kts
rename to gradle-modules/gradle-6/module-metadata-publishing/build.gradle.kts
diff --git a/gradle-6/person-rest-client/build.gradle.kts b/gradle-modules/gradle-6/person-rest-client/build.gradle.kts
similarity index 100%
rename from gradle-6/person-rest-client/build.gradle.kts
rename to gradle-modules/gradle-6/person-rest-client/build.gradle.kts
diff --git a/gradle-6/settings.gradle.kts b/gradle-modules/gradle-6/settings.gradle.kts
similarity index 100%
rename from gradle-6/settings.gradle.kts
rename to gradle-modules/gradle-6/settings.gradle.kts
diff --git a/gradle-6/widget-rest-client/build.gradle.kts b/gradle-modules/gradle-6/widget-rest-client/build.gradle.kts
similarity index 100%
rename from gradle-6/widget-rest-client/build.gradle.kts
rename to gradle-modules/gradle-6/widget-rest-client/build.gradle.kts
diff --git a/gradle/.gitignore b/gradle-modules/gradle/.gitignore
similarity index 100%
rename from gradle/.gitignore
rename to gradle-modules/gradle/.gitignore
diff --git a/gradle/.travis.yml b/gradle-modules/gradle/.travis.yml
similarity index 100%
rename from gradle/.travis.yml
rename to gradle-modules/gradle/.travis.yml
diff --git a/gradle/README.md b/gradle-modules/gradle/README.md
similarity index 100%
rename from gradle/README.md
rename to gradle-modules/gradle/README.md
diff --git a/gradle/build.gradle b/gradle-modules/gradle/build.gradle
similarity index 100%
rename from gradle/build.gradle
rename to gradle-modules/gradle/build.gradle
diff --git a/gradle/buildSrc/src/main/groovy/com/baeldung/PrintToolVersionBuildSrcTask.groovy b/gradle-modules/gradle/buildSrc/src/main/groovy/com/baeldung/PrintToolVersionBuildSrcTask.groovy
similarity index 100%
rename from gradle/buildSrc/src/main/groovy/com/baeldung/PrintToolVersionBuildSrcTask.groovy
rename to gradle-modules/gradle/buildSrc/src/main/groovy/com/baeldung/PrintToolVersionBuildSrcTask.groovy
diff --git a/gradle/gradle-cucumber/README.md b/gradle-modules/gradle/gradle-cucumber/README.md
similarity index 100%
rename from gradle/gradle-cucumber/README.md
rename to gradle-modules/gradle/gradle-cucumber/README.md
diff --git a/gradle/gradle-cucumber/build.gradle b/gradle-modules/gradle/gradle-cucumber/build.gradle
similarity index 100%
rename from gradle/gradle-cucumber/build.gradle
rename to gradle-modules/gradle/gradle-cucumber/build.gradle
diff --git a/gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle/gradle-cucumber/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle/gradle-cucumber/gradlew b/gradle-modules/gradle/gradle-cucumber/gradlew
similarity index 100%
rename from gradle/gradle-cucumber/gradlew
rename to gradle-modules/gradle/gradle-cucumber/gradlew
diff --git a/gradle/gradle-cucumber/gradlew.bat b/gradle-modules/gradle/gradle-cucumber/gradlew.bat
similarity index 100%
rename from gradle/gradle-cucumber/gradlew.bat
rename to gradle-modules/gradle/gradle-cucumber/gradlew.bat
diff --git a/gradle/gradle-cucumber/settings.gradle b/gradle-modules/gradle/gradle-cucumber/settings.gradle
similarity index 100%
rename from gradle/gradle-cucumber/settings.gradle
rename to gradle-modules/gradle/gradle-cucumber/settings.gradle
diff --git a/gradle/gradle-cucumber/src/main/java/com/baeldung/Account.java b/gradle-modules/gradle/gradle-cucumber/src/main/java/com/baeldung/Account.java
similarity index 100%
rename from gradle/gradle-cucumber/src/main/java/com/baeldung/Account.java
rename to gradle-modules/gradle/gradle-cucumber/src/main/java/com/baeldung/Account.java
diff --git a/gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/RunCucumberTest.java b/gradle-modules/gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/RunCucumberTest.java
similarity index 100%
rename from gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/RunCucumberTest.java
rename to gradle-modules/gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/RunCucumberTest.java
diff --git a/gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/StepDefinitions.java b/gradle-modules/gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/StepDefinitions.java
similarity index 100%
rename from gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/StepDefinitions.java
rename to gradle-modules/gradle/gradle-cucumber/src/test/java/com/baeldung/cucumber/StepDefinitions.java
diff --git a/gradle/gradle-cucumber/src/test/resources/features/account_credited.feature b/gradle-modules/gradle/gradle-cucumber/src/test/resources/features/account_credited.feature
similarity index 100%
rename from gradle/gradle-cucumber/src/test/resources/features/account_credited.feature
rename to gradle-modules/gradle/gradle-cucumber/src/test/resources/features/account_credited.feature
diff --git a/gradle/gradle-dependency-management/README.md b/gradle-modules/gradle/gradle-dependency-management/README.md
similarity index 100%
rename from gradle/gradle-dependency-management/README.md
rename to gradle-modules/gradle/gradle-dependency-management/README.md
diff --git a/gradle/gradle-dependency-management/build.gradle b/gradle-modules/gradle/gradle-dependency-management/build.gradle
similarity index 100%
rename from gradle/gradle-dependency-management/build.gradle
rename to gradle-modules/gradle/gradle-dependency-management/build.gradle
diff --git a/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle/gradle-dependency-management/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle/gradle-dependency-management/gradlew b/gradle-modules/gradle/gradle-dependency-management/gradlew
similarity index 100%
rename from gradle/gradle-dependency-management/gradlew
rename to gradle-modules/gradle/gradle-dependency-management/gradlew
diff --git a/gradle/gradle-dependency-management/gradlew.bat b/gradle-modules/gradle/gradle-dependency-management/gradlew.bat
similarity index 100%
rename from gradle/gradle-dependency-management/gradlew.bat
rename to gradle-modules/gradle/gradle-dependency-management/gradlew.bat
diff --git a/gradle/gradle-dependency-management/libs/sampleOne.jar b/gradle-modules/gradle/gradle-dependency-management/libs/sampleOne.jar
similarity index 100%
rename from gradle/gradle-dependency-management/libs/sampleOne.jar
rename to gradle-modules/gradle/gradle-dependency-management/libs/sampleOne.jar
diff --git a/gradle/gradle-dependency-management/libs/sampleTwo.jar b/gradle-modules/gradle/gradle-dependency-management/libs/sampleTwo.jar
similarity index 100%
rename from gradle/gradle-dependency-management/libs/sampleTwo.jar
rename to gradle-modules/gradle/gradle-dependency-management/libs/sampleTwo.jar
diff --git a/gradle/gradle-dependency-management/settings.gradle b/gradle-modules/gradle/gradle-dependency-management/settings.gradle
similarity index 100%
rename from gradle/gradle-dependency-management/settings.gradle
rename to gradle-modules/gradle/gradle-dependency-management/settings.gradle
diff --git a/gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java b/gradle-modules/gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java
similarity index 100%
rename from gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java
rename to gradle-modules/gradle/gradle-dependency-management/src/main/java/com/gradle/dependencymanagement/DependencyManagementApplication.java
diff --git a/gradle/gradle-dependency-management/src/main/resources/application.properties b/gradle-modules/gradle/gradle-dependency-management/src/main/resources/application.properties
similarity index 100%
rename from gradle/gradle-dependency-management/src/main/resources/application.properties
rename to gradle-modules/gradle/gradle-dependency-management/src/main/resources/application.properties
diff --git a/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationUnitTests.java b/gradle-modules/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationUnitTests.java
similarity index 100%
rename from gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationUnitTests.java
rename to gradle-modules/gradle/gradle-dependency-management/src/test/java/com/gradle/dependencymanagement/DependencyManagementApplicationUnitTests.java
diff --git a/gradle/gradle-employee-app/.gitignore b/gradle-modules/gradle/gradle-employee-app/.gitignore
similarity index 100%
rename from gradle/gradle-employee-app/.gitignore
rename to gradle-modules/gradle/gradle-employee-app/.gitignore
diff --git a/gradle/gradle-employee-app/README.md b/gradle-modules/gradle/gradle-employee-app/README.md
similarity index 100%
rename from gradle/gradle-employee-app/README.md
rename to gradle-modules/gradle/gradle-employee-app/README.md
diff --git a/gradle/gradle-employee-app/build.gradle b/gradle-modules/gradle/gradle-employee-app/build.gradle
similarity index 100%
rename from gradle/gradle-employee-app/build.gradle
rename to gradle-modules/gradle/gradle-employee-app/build.gradle
diff --git a/gradle/gradle-employee-app/settings.gradle b/gradle-modules/gradle/gradle-employee-app/settings.gradle
similarity index 100%
rename from gradle/gradle-employee-app/settings.gradle
rename to gradle-modules/gradle/gradle-employee-app/settings.gradle
diff --git a/gradle/gradle-employee-app/src/main/java/employee/Employee.java b/gradle-modules/gradle/gradle-employee-app/src/main/java/employee/Employee.java
similarity index 100%
rename from gradle/gradle-employee-app/src/main/java/employee/Employee.java
rename to gradle-modules/gradle/gradle-employee-app/src/main/java/employee/Employee.java
diff --git a/gradle/gradle-employee-app/src/main/java/employee/EmployeeApp.java b/gradle-modules/gradle/gradle-employee-app/src/main/java/employee/EmployeeApp.java
similarity index 100%
rename from gradle/gradle-employee-app/src/main/java/employee/EmployeeApp.java
rename to gradle-modules/gradle/gradle-employee-app/src/main/java/employee/EmployeeApp.java
diff --git a/gradle/gradle-employee-app/src/test/java/employee/EmployeeAppTest.java b/gradle-modules/gradle/gradle-employee-app/src/test/java/employee/EmployeeAppTest.java
similarity index 100%
rename from gradle/gradle-employee-app/src/test/java/employee/EmployeeAppTest.java
rename to gradle-modules/gradle/gradle-employee-app/src/test/java/employee/EmployeeAppTest.java
diff --git a/gradle/gradle-fat-jar/README.md b/gradle-modules/gradle/gradle-fat-jar/README.md
similarity index 100%
rename from gradle/gradle-fat-jar/README.md
rename to gradle-modules/gradle/gradle-fat-jar/README.md
diff --git a/gradle/gradle-fat-jar/build.gradle b/gradle-modules/gradle/gradle-fat-jar/build.gradle
similarity index 100%
rename from gradle/gradle-fat-jar/build.gradle
rename to gradle-modules/gradle/gradle-fat-jar/build.gradle
diff --git a/gradle/gradle-fat-jar/settings.gradle b/gradle-modules/gradle/gradle-fat-jar/settings.gradle
similarity index 100%
rename from gradle/gradle-fat-jar/settings.gradle
rename to gradle-modules/gradle/gradle-fat-jar/settings.gradle
diff --git a/gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java b/gradle-modules/gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java
similarity index 100%
rename from gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java
rename to gradle-modules/gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java
diff --git a/gradle/gradle-jacoco/README.md b/gradle-modules/gradle/gradle-jacoco/README.md
similarity index 100%
rename from gradle/gradle-jacoco/README.md
rename to gradle-modules/gradle/gradle-jacoco/README.md
diff --git a/gradle/gradle-jacoco/build.gradle b/gradle-modules/gradle/gradle-jacoco/build.gradle
similarity index 100%
rename from gradle/gradle-jacoco/build.gradle
rename to gradle-modules/gradle/gradle-jacoco/build.gradle
diff --git a/gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle/gradle-jacoco/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle/gradle-jacoco/gradlew b/gradle-modules/gradle/gradle-jacoco/gradlew
similarity index 100%
rename from gradle/gradle-jacoco/gradlew
rename to gradle-modules/gradle/gradle-jacoco/gradlew
diff --git a/gradle/gradle-jacoco/gradlew.bat b/gradle-modules/gradle/gradle-jacoco/gradlew.bat
similarity index 100%
rename from gradle/gradle-jacoco/gradlew.bat
rename to gradle-modules/gradle/gradle-jacoco/gradlew.bat
diff --git a/gradle/gradle-jacoco/lombok.config b/gradle-modules/gradle/gradle-jacoco/lombok.config
similarity index 100%
rename from gradle/gradle-jacoco/lombok.config
rename to gradle-modules/gradle/gradle-jacoco/lombok.config
diff --git a/gradle/gradle-jacoco/settings.gradle b/gradle-modules/gradle/gradle-jacoco/settings.gradle
similarity index 100%
rename from gradle/gradle-jacoco/settings.gradle
rename to gradle-modules/gradle/gradle-jacoco/settings.gradle
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/config/AppConfig.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/config/AppConfig.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/config/AppConfig.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/config/AppConfig.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/domain/Product.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/domain/Product.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/domain/Product.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/domain/Product.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ExcludedPOJO.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ExcludedPOJO.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ExcludedPOJO.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ExcludedPOJO.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ProductDTO.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ProductDTO.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ProductDTO.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/dto/ProductDTO.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Customer.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Customer.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Customer.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Customer.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Generated.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Generated.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Generated.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/generated/Generated.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/service/CustomerService.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/service/CustomerService.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/service/CustomerService.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/service/CustomerService.java
diff --git a/gradle/gradle-jacoco/src/main/java/com/baeldung/service/ProductService.java b/gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/service/ProductService.java
similarity index 100%
rename from gradle/gradle-jacoco/src/main/java/com/baeldung/service/ProductService.java
rename to gradle-modules/gradle/gradle-jacoco/src/main/java/com/baeldung/service/ProductService.java
diff --git a/gradle/gradle-jacoco/src/test/java/com/baeldung/service/CustomerServiceUnitTest.java b/gradle-modules/gradle/gradle-jacoco/src/test/java/com/baeldung/service/CustomerServiceUnitTest.java
similarity index 100%
rename from gradle/gradle-jacoco/src/test/java/com/baeldung/service/CustomerServiceUnitTest.java
rename to gradle-modules/gradle/gradle-jacoco/src/test/java/com/baeldung/service/CustomerServiceUnitTest.java
diff --git a/gradle/gradle-jacoco/src/test/java/com/baeldung/service/ProductServiceUnitTest.java b/gradle-modules/gradle/gradle-jacoco/src/test/java/com/baeldung/service/ProductServiceUnitTest.java
similarity index 100%
rename from gradle/gradle-jacoco/src/test/java/com/baeldung/service/ProductServiceUnitTest.java
rename to gradle-modules/gradle/gradle-jacoco/src/test/java/com/baeldung/service/ProductServiceUnitTest.java
diff --git a/gradle/gradle-jacoco/src/test/resources/features/account_credited.feature b/gradle-modules/gradle/gradle-jacoco/src/test/resources/features/account_credited.feature
similarity index 100%
rename from gradle/gradle-jacoco/src/test/resources/features/account_credited.feature
rename to gradle-modules/gradle/gradle-jacoco/src/test/resources/features/account_credited.feature
diff --git a/gradle/gradle-source-vs-target-compatibility/README.md b/gradle-modules/gradle/gradle-source-vs-target-compatibility/README.md
similarity index 100%
rename from gradle/gradle-source-vs-target-compatibility/README.md
rename to gradle-modules/gradle/gradle-source-vs-target-compatibility/README.md
diff --git a/gradle/gradle-source-vs-target-compatibility/build.gradle b/gradle-modules/gradle/gradle-source-vs-target-compatibility/build.gradle
similarity index 100%
rename from gradle/gradle-source-vs-target-compatibility/build.gradle
rename to gradle-modules/gradle/gradle-source-vs-target-compatibility/build.gradle
diff --git a/gradle/gradle-source-vs-target-compatibility/settings.gradle b/gradle-modules/gradle/gradle-source-vs-target-compatibility/settings.gradle
similarity index 100%
rename from gradle/gradle-source-vs-target-compatibility/settings.gradle
rename to gradle-modules/gradle/gradle-source-vs-target-compatibility/settings.gradle
diff --git a/gradle/gradle-source-vs-target-compatibility/src/main/java/com/baeldung/helloworld/HelloWorldApp.java b/gradle-modules/gradle/gradle-source-vs-target-compatibility/src/main/java/com/baeldung/helloworld/HelloWorldApp.java
similarity index 100%
rename from gradle/gradle-source-vs-target-compatibility/src/main/java/com/baeldung/helloworld/HelloWorldApp.java
rename to gradle-modules/gradle/gradle-source-vs-target-compatibility/src/main/java/com/baeldung/helloworld/HelloWorldApp.java
diff --git a/gradle/gradle-to-maven/README.md b/gradle-modules/gradle/gradle-to-maven/README.md
similarity index 100%
rename from gradle/gradle-to-maven/README.md
rename to gradle-modules/gradle/gradle-to-maven/README.md
diff --git a/gradle/gradle-to-maven/build.gradle b/gradle-modules/gradle/gradle-to-maven/build.gradle
similarity index 100%
rename from gradle/gradle-to-maven/build.gradle
rename to gradle-modules/gradle/gradle-to-maven/build.gradle
diff --git a/gradle/gradle-to-maven/settings.gradle b/gradle-modules/gradle/gradle-to-maven/settings.gradle
similarity index 100%
rename from gradle/gradle-to-maven/settings.gradle
rename to gradle-modules/gradle/gradle-to-maven/settings.gradle
diff --git a/gradle/gradle-wrapper/README.md b/gradle-modules/gradle/gradle-wrapper/README.md
similarity index 100%
rename from gradle/gradle-wrapper/README.md
rename to gradle-modules/gradle/gradle-wrapper/README.md
diff --git a/gradle/gradle-wrapper/gradle/wrapper/README.md b/gradle-modules/gradle/gradle-wrapper/gradle/wrapper/README.md
similarity index 100%
rename from gradle/gradle-wrapper/gradle/wrapper/README.md
rename to gradle-modules/gradle/gradle-wrapper/gradle/wrapper/README.md
diff --git a/gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle/gradle-wrapper/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle/gradle-wrapper/gradlew b/gradle-modules/gradle/gradle-wrapper/gradlew
similarity index 100%
rename from gradle/gradle-wrapper/gradlew
rename to gradle-modules/gradle/gradle-wrapper/gradlew
diff --git a/gradle/gradle-wrapper/gradlew.bat b/gradle-modules/gradle/gradle-wrapper/gradlew.bat
similarity index 100%
rename from gradle/gradle-wrapper/gradlew.bat
rename to gradle-modules/gradle/gradle-wrapper/gradlew.bat
diff --git a/gradle/gradle-wrapper/settings.gradle b/gradle-modules/gradle/gradle-wrapper/settings.gradle
similarity index 100%
rename from gradle/gradle-wrapper/settings.gradle
rename to gradle-modules/gradle/gradle-wrapper/settings.gradle
diff --git a/gradle/gradle/shipkit.gradle b/gradle-modules/gradle/gradle/shipkit.gradle
similarity index 100%
rename from gradle/gradle/shipkit.gradle
rename to gradle-modules/gradle/gradle/shipkit.gradle
diff --git a/gradle/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle/gradletaskdemo/aplugin.gradle b/gradle-modules/gradle/gradletaskdemo/aplugin.gradle
similarity index 100%
rename from gradle/gradletaskdemo/aplugin.gradle
rename to gradle-modules/gradle/gradletaskdemo/aplugin.gradle
diff --git a/gradle/gradletaskdemo/build.gradle b/gradle-modules/gradle/gradletaskdemo/build.gradle
similarity index 100%
rename from gradle/gradletaskdemo/build.gradle
rename to gradle-modules/gradle/gradletaskdemo/build.gradle
diff --git a/gradle/gradlew b/gradle-modules/gradle/gradlew
similarity index 100%
rename from gradle/gradlew
rename to gradle-modules/gradle/gradlew
diff --git a/gradle/gradlew.bat b/gradle-modules/gradle/gradlew.bat
similarity index 100%
rename from gradle/gradlew.bat
rename to gradle-modules/gradle/gradlew.bat
diff --git a/gradle/greeter/.gitignore b/gradle-modules/gradle/greeter/.gitignore
similarity index 100%
rename from gradle/greeter/.gitignore
rename to gradle-modules/gradle/greeter/.gitignore
diff --git a/gradle/greeter/build.gradle b/gradle-modules/gradle/greeter/build.gradle
similarity index 100%
rename from gradle/greeter/build.gradle
rename to gradle-modules/gradle/greeter/build.gradle
diff --git a/gradle/greeter/src/main/java/greeter/Greeter.java b/gradle-modules/gradle/greeter/src/main/java/greeter/Greeter.java
similarity index 100%
rename from gradle/greeter/src/main/java/greeter/Greeter.java
rename to gradle-modules/gradle/greeter/src/main/java/greeter/Greeter.java
diff --git a/gradle/greeter/src/test/java/greetertest/TestGreeting.java b/gradle-modules/gradle/greeter/src/test/java/greetertest/TestGreeting.java
similarity index 100%
rename from gradle/greeter/src/test/java/greetertest/TestGreeting.java
rename to gradle-modules/gradle/greeter/src/test/java/greetertest/TestGreeting.java
diff --git a/gradle/greeting-library-java/.gitignore b/gradle-modules/gradle/greeting-library-java/.gitignore
similarity index 100%
rename from gradle/greeting-library-java/.gitignore
rename to gradle-modules/gradle/greeting-library-java/.gitignore
diff --git a/gradle/greeting-library-java/build.gradle b/gradle-modules/gradle/greeting-library-java/build.gradle
similarity index 100%
rename from gradle/greeting-library-java/build.gradle
rename to gradle-modules/gradle/greeting-library-java/build.gradle
diff --git a/gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java b/gradle-modules/gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java
similarity index 100%
rename from gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java
rename to gradle-modules/gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java
diff --git a/gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java b/gradle-modules/gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java
similarity index 100%
rename from gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java
rename to gradle-modules/gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java
diff --git a/gradle/greeting-library/.gitignore b/gradle-modules/gradle/greeting-library/.gitignore
similarity index 100%
rename from gradle/greeting-library/.gitignore
rename to gradle-modules/gradle/greeting-library/.gitignore
diff --git a/gradle/greeting-library/bin/greeter/GreetingFormatter.groovy b/gradle-modules/gradle/greeting-library/bin/greeter/GreetingFormatter.groovy
similarity index 100%
rename from gradle/greeting-library/bin/greeter/GreetingFormatter.groovy
rename to gradle-modules/gradle/greeting-library/bin/greeter/GreetingFormatter.groovy
diff --git a/gradle/greeting-library/build.gradle b/gradle-modules/gradle/greeting-library/build.gradle
similarity index 100%
rename from gradle/greeting-library/build.gradle
rename to gradle-modules/gradle/greeting-library/build.gradle
diff --git a/gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy b/gradle-modules/gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy
similarity index 100%
rename from gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy
rename to gradle-modules/gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy
diff --git a/gradle/greeting-library/bin/greeter/GreetingFormatterSpec.groovy b/gradle-modules/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy
similarity index 100%
rename from gradle/greeting-library/bin/greeter/GreetingFormatterSpec.groovy
rename to gradle-modules/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy
diff --git a/gradle/junit5/README.md b/gradle-modules/gradle/junit5/README.md
similarity index 100%
rename from gradle/junit5/README.md
rename to gradle-modules/gradle/junit5/README.md
diff --git a/gradle/junit5/build.gradle b/gradle-modules/gradle/junit5/build.gradle
similarity index 100%
rename from gradle/junit5/build.gradle
rename to gradle-modules/gradle/junit5/build.gradle
diff --git a/gradle/junit5/settings.gradle b/gradle-modules/gradle/junit5/settings.gradle
similarity index 100%
rename from gradle/junit5/settings.gradle
rename to gradle-modules/gradle/junit5/settings.gradle
diff --git a/gradle/junit5/src/test/java/com/example/CalculatorJUnit4Test.java b/gradle-modules/gradle/junit5/src/test/java/com/example/CalculatorJUnit4Test.java
similarity index 100%
rename from gradle/junit5/src/test/java/com/example/CalculatorJUnit4Test.java
rename to gradle-modules/gradle/junit5/src/test/java/com/example/CalculatorJUnit4Test.java
diff --git a/gradle/junit5/src/test/java/com/example/CalculatorJUnit5Test.java b/gradle-modules/gradle/junit5/src/test/java/com/example/CalculatorJUnit5Test.java
similarity index 100%
rename from gradle/junit5/src/test/java/com/example/CalculatorJUnit5Test.java
rename to gradle-modules/gradle/junit5/src/test/java/com/example/CalculatorJUnit5Test.java
diff --git a/gradle/maven-to-gradle/README.md b/gradle-modules/gradle/maven-to-gradle/README.md
similarity index 100%
rename from gradle/maven-to-gradle/README.md
rename to gradle-modules/gradle/maven-to-gradle/README.md
diff --git a/gradle/maven-to-gradle/build.gradle b/gradle-modules/gradle/maven-to-gradle/build.gradle
similarity index 100%
rename from gradle/maven-to-gradle/build.gradle
rename to gradle-modules/gradle/maven-to-gradle/build.gradle
diff --git a/gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.jar b/gradle-modules/gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.jar
similarity index 100%
rename from gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.jar
rename to gradle-modules/gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.jar
diff --git a/gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.properties b/gradle-modules/gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.properties
similarity index 100%
rename from gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.properties
rename to gradle-modules/gradle/maven-to-gradle/gradle/wrapper/gradle-wrapper.properties
diff --git a/gradle/maven-to-gradle/gradlew b/gradle-modules/gradle/maven-to-gradle/gradlew
similarity index 100%
rename from gradle/maven-to-gradle/gradlew
rename to gradle-modules/gradle/maven-to-gradle/gradlew
diff --git a/gradle/maven-to-gradle/gradlew.bat b/gradle-modules/gradle/maven-to-gradle/gradlew.bat
similarity index 100%
rename from gradle/maven-to-gradle/gradlew.bat
rename to gradle-modules/gradle/maven-to-gradle/gradlew.bat
diff --git a/gradle/maven-to-gradle/pom.xml b/gradle-modules/gradle/maven-to-gradle/pom.xml
similarity index 100%
rename from gradle/maven-to-gradle/pom.xml
rename to gradle-modules/gradle/maven-to-gradle/pom.xml
diff --git a/gradle/maven-to-gradle/settings.gradle b/gradle-modules/gradle/maven-to-gradle/settings.gradle
similarity index 100%
rename from gradle/maven-to-gradle/settings.gradle
rename to gradle-modules/gradle/maven-to-gradle/settings.gradle
diff --git a/gradle/maven-to-gradle/src/main/java/com/sample/javacode/DisplayTime.java b/gradle-modules/gradle/maven-to-gradle/src/main/java/com/sample/javacode/DisplayTime.java
similarity index 100%
rename from gradle/maven-to-gradle/src/main/java/com/sample/javacode/DisplayTime.java
rename to gradle-modules/gradle/maven-to-gradle/src/main/java/com/sample/javacode/DisplayTime.java
diff --git a/gradle/plugin/build.gradle b/gradle-modules/gradle/plugin/build.gradle
similarity index 100%
rename from gradle/plugin/build.gradle
rename to gradle-modules/gradle/plugin/build.gradle
diff --git a/gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPlugin.java b/gradle-modules/gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPlugin.java
similarity index 100%
rename from gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPlugin.java
rename to gradle-modules/gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPlugin.java
diff --git a/gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPluginExtension.java b/gradle-modules/gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPluginExtension.java
similarity index 100%
rename from gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPluginExtension.java
rename to gradle-modules/gradle/plugin/buildSrc/src/main/java/com/baeldung/GreetingPluginExtension.java
diff --git a/gradle/settings.gradle b/gradle-modules/gradle/settings.gradle
similarity index 82%
rename from gradle/settings.gradle
rename to gradle-modules/gradle/settings.gradle
index ba255f25c2..c049dbc7e9 100644
--- a/gradle/settings.gradle
+++ b/gradle-modules/gradle/settings.gradle
@@ -1,4 +1,4 @@
-rootProject.name = 'gradletutorial'
+rootProject.name = 'gradle'
include 'greeting-library'
include 'greeting-library-java'
diff --git a/gradle/version.properties b/gradle-modules/gradle/version.properties
similarity index 100%
rename from gradle/version.properties
rename to gradle-modules/gradle/version.properties
diff --git a/gradle-modules/settings.gradle b/gradle-modules/settings.gradle
new file mode 100644
index 0000000000..f6e0614a10
--- /dev/null
+++ b/gradle-modules/settings.gradle
@@ -0,0 +1,4 @@
+rootProject.name = 'gradle-modules'
+include 'gradle'
+include 'gradle-5'
+include 'gradle-6'
diff --git a/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy b/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy
deleted file mode 100644
index f1c1211552..0000000000
--- a/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy
+++ /dev/null
@@ -1,13 +0,0 @@
-package greeter
-
-import spock.lang.Specification
-
-class GreetingFormatterSpec extends Specification {
-
- def 'Creating a greeting'() {
-
- expect: 'The greeeting to be correctly capitalized'
- GreetingFormatter.greeting('gradlephant') == 'Hello, Gradlephant'
-
- }
-}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/Application.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/Application.java
index ee819b844b..cee73f674e 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/Application.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/Application.java
@@ -1,5 +1,6 @@
package com.baeldung.libraries.opencsv;
+import com.baeldung.libraries.opencsv.beans.CsvBean;
import com.baeldung.libraries.opencsv.beans.NamedColumnBean;
import com.baeldung.libraries.opencsv.beans.SimplePositionBean;
import com.baeldung.libraries.opencsv.examples.sync.BeanExamples;
@@ -7,102 +8,60 @@ import com.baeldung.libraries.opencsv.examples.sync.CsvReaderExamples;
import com.baeldung.libraries.opencsv.examples.sync.CsvWriterExamples;
import com.baeldung.libraries.opencsv.helpers.Helpers;
-import java.io.Reader;
-import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.List;
public class Application {
- /*
- * Bean Examples.
- */
-
- public static String simpleSyncPositionBeanExample() {
- Path path = null;
- try {
- path = Helpers.twoColumnCsvPath();
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return BeanExamples.beanBuilderExample(path, SimplePositionBean.class).toString();
+ // CSV Reader Examples
+ public static List readLineByLineSyncExample() throws Exception {
+ Path path = Helpers.twoColumnCsvPath();
+ return CsvReaderExamples.readLineByLine(path);
}
- public static String namedSyncColumnBeanExample() {
- Path path = null;
- try {
- path = Helpers.namedColumnCsvPath();
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return BeanExamples.beanBuilderExample(path, NamedColumnBean.class).toString();
+ public static List readAllLinesSyncExample() throws Exception {
+ Path path = Helpers.twoColumnCsvPath();
+ return CsvReaderExamples.readAllLines(path);
}
- public static String writeSyncCsvFromBeanExample() {
- Path path = null;
- try {
- path = Helpers.fileOutBeanPath();
- } catch (Exception ex) {
- Helpers.err(ex);
- }
+ // CSV Writer Examples
+ public static String writeLineByLineSyncExample() throws Exception {
+ Path path = Helpers.fileOutOnePath();
+ return CsvWriterExamples.writeLineByLine(Helpers.fourColumnCsvString(), path);
+ }
+
+ public static String writeAllLinesSyncExample() throws Exception {
+ Path path = Helpers.fileOutAllPath();
+ return CsvWriterExamples.writeAllLines(Helpers.fourColumnCsvString(), path);
+ }
+
+ // Bean Examples
+ public static List simpleSyncPositionBeanExample() throws Exception {
+ Path path = Helpers.twoColumnCsvPath();
+ return BeanExamples.beanBuilderExample(path, SimplePositionBean.class);
+ }
+
+ public static List namedSyncColumnBeanExample() throws Exception {
+ Path path = Helpers.namedColumnCsvPath();
+ return BeanExamples.beanBuilderExample(path, NamedColumnBean.class);
+ }
+
+ public static String writeSyncCsvFromBeanExample() throws Exception {
+ Path path = Helpers.fileOutBeanPath();
return BeanExamples.writeCsvFromBean(path);
}
- /*
- * CSV Reader Examples.
- */
-
- public static String oneByOneSyncExample() {
- Reader reader = null;
- try {
- reader = Files.newBufferedReader(Helpers.twoColumnCsvPath());
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return CsvReaderExamples.oneByOne(reader).toString();
- }
-
- public static String readAllSyncExample() {
- Reader reader = null;
- try {
- reader = Files.newBufferedReader(Helpers.twoColumnCsvPath());
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return CsvReaderExamples.readAll(reader).toString();
- }
-
- /*
- * CSV Writer Examples.
- */
-
-
- public static String csvWriterSyncOneByOne() {
- Path path = null;
- try {
- path = Helpers.fileOutOnePath();
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return CsvWriterExamples.csvWriterOneByOne(Helpers.fourColumnCsvString(), path);
- }
-
- public static String csvWriterSyncAll() {
- Path path = null;
- try {
- path = Helpers.fileOutAllPath();
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return CsvWriterExamples.csvWriterAll(Helpers.fourColumnCsvString(), path);
- }
-
public static void main(String[] args) {
- simpleSyncPositionBeanExample();
- namedSyncColumnBeanExample();
- writeSyncCsvFromBeanExample();
- oneByOneSyncExample();
- readAllSyncExample();
- csvWriterSyncOneByOne();
- csvWriterSyncAll();
+ try {
+ simpleSyncPositionBeanExample();
+ namedSyncColumnBeanExample();
+ writeSyncCsvFromBeanExample();
+ readLineByLineSyncExample();
+ readAllLinesSyncExample();
+ writeLineByLineSyncExample();
+ writeAllLinesSyncExample();
+ } catch (Exception e) {
+ throw new RuntimeException("Error during csv processing", e);
+ }
}
}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/NamedColumnBean.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/NamedColumnBean.java
index 0021584e4f..f8c6537d3a 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/NamedColumnBean.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/NamedColumnBean.java
@@ -27,5 +27,10 @@ public class NamedColumnBean extends CsvBean {
this.age = age;
}
+ @Override
+ public String toString() {
+ return name + ',' + age;
+ }
+
}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/SimplePositionBean.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/SimplePositionBean.java
index c1710d784a..2306ccc560 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/SimplePositionBean.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/SimplePositionBean.java
@@ -26,4 +26,8 @@ public class SimplePositionBean extends CsvBean {
this.exampleColTwo = exampleColTwo;
}
+ @Override
+ public String toString() {
+ return exampleColOne + ',' + exampleColTwo;
+ }
}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/WriteExampleBean.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/WriteExampleBean.java
index f5e6466512..62b14dc321 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/WriteExampleBean.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/beans/WriteExampleBean.java
@@ -37,4 +37,9 @@ public class WriteExampleBean extends CsvBean {
public void setColC(String colC) {
this.colC = colC;
}
+
+ @Override
+ public String toString() {
+ return colA + ',' + colB + "," + colC;
+ }
}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/BeanExamples.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/BeanExamples.java
index f401c7c77c..b2a00be0ee 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/BeanExamples.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/BeanExamples.java
@@ -4,60 +4,49 @@ import com.baeldung.libraries.opencsv.beans.CsvBean;
import com.baeldung.libraries.opencsv.beans.WriteExampleBean;
import com.baeldung.libraries.opencsv.helpers.Helpers;
import com.baeldung.libraries.opencsv.pojos.CsvTransfer;
-import com.opencsv.CSVWriter;
-import com.opencsv.bean.*;
+import com.opencsv.bean.CsvToBean;
+import com.opencsv.bean.CsvToBeanBuilder;
+import com.opencsv.bean.StatefulBeanToCsv;
+import com.opencsv.bean.StatefulBeanToCsvBuilder;
import java.io.FileWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
public class BeanExamples {
- public static List beanBuilderExample(Path path, Class clazz) {
- ColumnPositionMappingStrategy ms = new ColumnPositionMappingStrategy();
- return beanBuilderExample(path, clazz, ms);
- }
-
- public static List beanBuilderExample(Path path, Class clazz, MappingStrategy ms) {
+ public static List beanBuilderExample(Path path, Class extends CsvBean> clazz) throws Exception {
CsvTransfer csvTransfer = new CsvTransfer();
- try {
- ms.setType(clazz);
-
- Reader reader = Files.newBufferedReader(path);
- CsvToBean cb = new CsvToBeanBuilder(reader).withType(clazz)
- .withMappingStrategy(ms)
- .build();
+ try (Reader reader = Files.newBufferedReader(path)) {
+ CsvToBean cb = new CsvToBeanBuilder(reader)
+ .withType(clazz)
+ .build();
csvTransfer.setCsvList(cb.parse());
- reader.close();
-
- } catch (Exception ex) {
- Helpers.err(ex);
}
+
return csvTransfer.getCsvList();
}
- public static String writeCsvFromBean(Path path) {
- try {
- Writer writer = new FileWriter(path.toString());
+ public static String writeCsvFromBean(Path path) throws Exception {
- StatefulBeanToCsv sbc = new StatefulBeanToCsvBuilder(writer).withSeparator(CSVWriter.DEFAULT_SEPARATOR)
- .build();
+ List sampleData = Arrays.asList(
+ new WriteExampleBean("Test1", "sample", "data"),
+ new WriteExampleBean("Test2", "ipso", "facto")
+ );
- List list = new ArrayList<>();
- list.add(new WriteExampleBean("Test1", "sfdsf", "fdfd"));
- list.add(new WriteExampleBean("Test2", "ipso", "facto"));
+ try (Writer writer = new FileWriter(path.toString())) {
+ StatefulBeanToCsv sbc = new StatefulBeanToCsvBuilder(writer)
+ .withQuotechar('\'')
+ .build();
- sbc.write(list);
- writer.close();
-
- } catch (Exception ex) {
- Helpers.err(ex);
+ sbc.write(sampleData);
}
+
return Helpers.readFile(path);
}
}
\ No newline at end of file
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvReaderExamples.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvReaderExamples.java
index 2f7d979b2f..2bafe0d764 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvReaderExamples.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvReaderExamples.java
@@ -1,61 +1,58 @@
package com.baeldung.libraries.opencsv.examples.sync;
-import com.baeldung.libraries.opencsv.helpers.Helpers;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import java.io.Reader;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class CsvReaderExamples {
- public static List readAll(Reader reader) {
+ public static List readAllLines(Path filePath) throws Exception {
CSVParser parser = new CSVParserBuilder()
- .withSeparator(',')
- .withIgnoreQuotations(true)
- .build();
+ .withSeparator(',')
+ .withIgnoreQuotations(true)
+ .build();
- CSVReader csvReader = new CSVReaderBuilder(reader)
- .withSkipLines(0)
- .withCSVParser(parser)
- .build();
+ try (Reader reader = Files.newBufferedReader(filePath)) {
+ CSVReaderBuilder csvReaderBuilder = new CSVReaderBuilder(reader)
+ .withSkipLines(0)
+ .withCSVParser(parser);
- List list = new ArrayList<>();
- try {
- list = csvReader.readAll();
- reader.close();
- csvReader.close();
- } catch (Exception ex) {
- Helpers.err(ex);
+ try (CSVReader csvReader = csvReaderBuilder.build()) {
+ return csvReader.readAll();
+ }
}
- return list;
+
}
- public static List oneByOne(Reader reader) {
+ public static List readLineByLine(Path filePath) throws Exception {
List list = new ArrayList<>();
- try {
- CSVParser parser = new CSVParserBuilder()
- .withSeparator(',')
- .withIgnoreQuotations(true)
- .build();
- CSVReader csvReader = new CSVReaderBuilder(reader)
- .withSkipLines(0)
- .withCSVParser(parser)
- .build();
+ CSVParser parser = new CSVParserBuilder()
+ .withSeparator(',')
+ .withIgnoreQuotations(true)
+ .build();
- String[] line;
- while ((line = csvReader.readNext()) != null) {
- list.add(line);
+ try (Reader reader = Files.newBufferedReader(filePath)) {
+
+ CSVReaderBuilder csvReaderBuilder = new CSVReaderBuilder(reader)
+ .withSkipLines(0)
+ .withCSVParser(parser);
+
+ try (CSVReader csvReader = csvReaderBuilder.build()) {
+ String[] line;
+ while ((line = csvReader.readNext()) != null) {
+ list.add(line);
+ }
}
- reader.close();
- csvReader.close();
- } catch (Exception ex) {
- Helpers.err(ex);
+
}
return list;
}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvWriterExamples.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvWriterExamples.java
index b5c23bd99d..7f14b2547f 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvWriterExamples.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/examples/sync/CsvWriterExamples.java
@@ -9,26 +9,21 @@ import java.util.List;
public class CsvWriterExamples {
- public static String csvWriterOneByOne(List stringArray, Path path) {
- try {
- CSVWriter writer = new CSVWriter(new FileWriter(path.toString()));
- for (String[] array : stringArray) {
- writer.writeNext(array);
+ public static String writeLineByLine(List lines, Path path) throws Exception {
+
+ try (CSVWriter writer = new CSVWriter(new FileWriter(path.toString()))) {
+ for (String[] line : lines) {
+ writer.writeNext(line);
}
- writer.close();
- } catch (Exception ex) {
- Helpers.err(ex);
}
+
return Helpers.readFile(path);
}
- public static String csvWriterAll(List stringArray, Path path) {
- try {
- CSVWriter writer = new CSVWriter(new FileWriter(path.toString()));
- writer.writeAll(stringArray);
- writer.close();
- } catch (Exception ex) {
- Helpers.err(ex);
+ public static String writeAllLines(List lines, Path path) throws Exception {
+
+ try (CSVWriter writer = new CSVWriter(new FileWriter(path.toString()))) {
+ writer.writeAll(lines);
}
return Helpers.readFile(path);
}
diff --git a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/helpers/Helpers.java b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/helpers/Helpers.java
index b703d0e82d..fd9e0ba386 100644
--- a/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/helpers/Helpers.java
+++ b/libraries-data-io/src/main/java/com/baeldung/libraries/opencsv/helpers/Helpers.java
@@ -1,9 +1,9 @@
package com.baeldung.libraries.opencsv.helpers;
import com.baeldung.libraries.opencsv.Constants;
+import org.apache.commons.io.IOUtils;
-import java.io.BufferedReader;
-import java.io.FileReader;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
@@ -13,9 +13,7 @@ import java.util.List;
public class Helpers {
- /**
- * Write Files
- */
+ // Write Files
public static Path fileOutAllPath() throws URISyntaxException {
URI uri = ClassLoader.getSystemResource(Constants.CSV_All).toURI();
@@ -32,9 +30,7 @@ public class Helpers {
return Paths.get(uri);
}
- /**
- * Read Files
- */
+ // Read Files
public static Path twoColumnCsvPath() throws URISyntaxException {
URI uri = ClassLoader.getSystemResource(Constants.TWO_COLUMN_CSV).toURI();
@@ -51,33 +47,12 @@ public class Helpers {
return Paths.get(uri);
}
- /**
- * Simple File Reader
- */
-
- public static String readFile(Path path) {
- String response = "";
- try {
- FileReader fr = new FileReader(path.toString());
- BufferedReader br = new BufferedReader(fr);
- String strLine;
- StringBuffer sb = new StringBuffer();
- while ((strLine = br.readLine()) != null) {
- sb.append(strLine);
- }
- response = sb.toString();
- System.out.println(response);
- fr.close();
- br.close();
- } catch (Exception ex) {
- Helpers.err(ex);
- }
- return response;
+ public static String readFile(Path path) throws IOException {
+ return IOUtils.toString(path.toUri());
}
- /**
- * Dummy Data for Writing.
- */
+
+ // Dummy Data for Writing
public static List twoColumnCsvString() {
List list = new ArrayList<>();
@@ -94,15 +69,4 @@ public class Helpers {
return list;
}
- /**
- * Message Helpers
- */
-
- public static void print(String msg) {
- System.out.println(msg);
- }
-
- public static void err(Exception ex) {
- System.out.println(Constants.GENERIC_EXCEPTION + " " + ex);
- }
}
diff --git a/libraries-data-io/src/main/resources/csv/twoColumn.csv b/libraries-data-io/src/main/resources/csv/twoColumn.csv
index 56d8fa1901..527e15af72 100644
--- a/libraries-data-io/src/main/resources/csv/twoColumn.csv
+++ b/libraries-data-io/src/main/resources/csv/twoColumn.csv
@@ -1,5 +1,5 @@
-colA, ColB
-A, B
-C, D
-G, G
-G, F
\ No newline at end of file
+colA,colB
+A,B
+C,D
+G,G
+G,F
\ No newline at end of file
diff --git a/libraries-data-io/src/test/java/com/baeldung/libraries/opencsv/OpenCsvIntegrationTest.java b/libraries-data-io/src/test/java/com/baeldung/libraries/opencsv/OpenCsvIntegrationTest.java
index b0db4309d9..7cfe8984e7 100644
--- a/libraries-data-io/src/test/java/com/baeldung/libraries/opencsv/OpenCsvIntegrationTest.java
+++ b/libraries-data-io/src/test/java/com/baeldung/libraries/opencsv/OpenCsvIntegrationTest.java
@@ -1,66 +1,107 @@
package com.baeldung.libraries.opencsv;
-import com.baeldung.libraries.opencsv.helpers.Helpers;
-import org.junit.After;
-import org.junit.Before;
+import com.baeldung.libraries.opencsv.beans.CsvBean;
import org.junit.Test;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
public class OpenCsvIntegrationTest {
- private Object testReadCsv(Object result) {
- assert (result != null);
- assert (result instanceof String);
- assert (!((String) result).isEmpty());
- System.out.println(result);
- return result;
- }
+ private static final String NEW_LINE = System.lineSeparator();
- private Object testWriteCsv(Object result) {
- assert (result instanceof String);
- assert (!((String) result).isEmpty());
- return result;
- }
+ @Test
+ public void givenSampleData_whenReadUsingPosition_thenContentsRead() throws Exception {
+ List values = Application.simpleSyncPositionBeanExample();
- @Before
- public void setup() {
+ assertThat(values)
+ .extracting(Object::toString)
+ .containsExactly(
+ "colA,colB",
+ "A,B",
+ "C,D",
+ "G,G",
+ "G,F"
+ );
}
@Test
- public void positionExampleTest() {
- testReadCsv(Application.simpleSyncPositionBeanExample());
+ public void givenSampleData_whenReadUsingNamedColumn_thenContentsRead() throws Exception {
+ List values = Application.namedSyncColumnBeanExample();
+
+ assertThat(values)
+ .extracting(Object::toString)
+ .containsExactly(
+ "Joe,27",
+ "Jane,32",
+ "Bob,53"
+ );
}
@Test
- public void namedColumnExampleTest() {
- testReadCsv(Application.namedSyncColumnBeanExample());
+ public void givenSampleData_whenReadLineByLine_thenContentsRead() throws Exception {
+ List lineByLineContents = Application.readLineByLineSyncExample();
+
+ assertThat(lineByLineContents)
+ .containsExactly(
+ new String[] {"colA", "colB"},
+ new String[] {"A", "B"},
+ new String[] {"C", "D"},
+ new String[] {"G", "G"},
+ new String[] {"G", "F"}
+ );
}
@Test
- public void writeCsvUsingBeanBuilderTest() {
- testWriteCsv(Application.writeSyncCsvFromBeanExample());
+ public void givenSampleData_whenReadAllLines_thenContentsRead() throws Exception {
+
+ List contents = Application.readAllLinesSyncExample();
+
+ assertThat(contents)
+ .containsExactly(
+ new String[] {"colA", "colB"},
+ new String[] {"A", "B"},
+ new String[] {"C", "D"},
+ new String[] {"G", "G"},
+ new String[] {"G", "F"}
+ );
}
@Test
- public void oneByOneExampleTest() {
- testReadCsv(Application.oneByOneSyncExample());
+ public void givenSampleData_whenWriteCsvUsingBean_thenContentsWritten() throws Exception {
+ String contents = Application.writeSyncCsvFromBeanExample();
+
+ assertThat(contents.split(NEW_LINE))
+ .containsExactly(
+ "'colA','colB','colC'",
+ "'Test1','sample','data'",
+ "'Test2','ipso','facto'"
+ );
}
@Test
- public void readAllExampleTest() {
- testReadCsv(Application.readAllSyncExample());
+ public void givenSampleData_whenWriteCsvLineByLine_thenContentsWritten() throws Exception {
+ String contents = Application.writeLineByLineSyncExample();
+
+ assertThat(contents.split(NEW_LINE))
+ .containsExactly(
+ "\"ColA\",\"ColB\",\"ColC\",\"ColD\"",
+ "\"A\",\"B\",\"A\",\"B\"",
+ "\"BB\",\"AB\",\"AA\",\"B\""
+ );
}
@Test
- public void csvWriterOneByOneTest() {
- testWriteCsv(Application.csvWriterSyncOneByOne());
+ public void givenSampleData_whenWriteCsvAllLines_thenContentsWritten() throws Exception {
+ String contents = Application.writeAllLinesSyncExample();
+
+ assertThat(contents.split(NEW_LINE))
+ .containsExactly(
+ "\"ColA\",\"ColB\",\"ColC\",\"ColD\"",
+ "\"A\",\"B\",\"A\",\"B\"",
+ "\"BB\",\"AB\",\"AA\",\"B\""
+ );
}
- @Test
- public void csvWriterAllTest() {
- testWriteCsv(Application.csvWriterSyncAll());
- }
-
- @After
- public void close() {
- }
}
\ No newline at end of file
diff --git a/libraries-http/src/main/java/com/baeldung/javalin/User/User.java b/libraries-http/src/main/java/com/baeldung/javalin/User/User.java
index 288c027c8b..ac96ece03e 100644
--- a/libraries-http/src/main/java/com/baeldung/javalin/User/User.java
+++ b/libraries-http/src/main/java/com/baeldung/javalin/User/User.java
@@ -1,5 +1,5 @@
package com.baeldung.javalin.User;
-import com.fasterxml.jackson.annotation.JsonProperty;
+
public class User {
public int id;
diff --git a/libraries-http/src/main/java/com/baeldung/javalin/User/UserController.java b/libraries-http/src/main/java/com/baeldung/javalin/User/UserController.java
index 685890c6d7..1b3cc950e8 100644
--- a/libraries-http/src/main/java/com/baeldung/javalin/User/UserController.java
+++ b/libraries-http/src/main/java/com/baeldung/javalin/User/UserController.java
@@ -3,6 +3,7 @@ package com.baeldung.javalin.User;
import io.javalin.Handler;
import java.util.Objects;
+import java.util.Optional;
public class UserController {
public static Handler fetchAllUsernames = ctx -> {
@@ -14,11 +15,11 @@ public class UserController {
public static Handler fetchById = ctx -> {
int id = Integer.parseInt(Objects.requireNonNull(ctx.param("id")));
UserDao dao = UserDao.instance();
- User user = dao.getUserById(id).get();
- if (user == null) {
- ctx.html("Not Found");
- } else {
+ Optional user = dao.getUserById(id);
+ if(user.isPresent()){
ctx.json(user);
+ } else {
+ ctx.html("User Not Found");
}
};
}
diff --git a/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java b/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java
index b82dcb6c5b..4e7dce2d72 100644
--- a/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java
+++ b/persistence-modules/java-mongodb-3/src/main/java/com/baeldung/mongo/find/FindWithObjectId.java
@@ -25,7 +25,7 @@ public class FindWithObjectId {
mongoClient = new MongoClient("localhost", 27017);
databaseName = "baeldung";
- collectionName = "employee";
+ collectionName = "vehicle";
database = mongoClient.getDatabase(databaseName);
collection = database.getCollection(collectionName);
diff --git a/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java b/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java
index 590758855c..b8a34c809b 100644
--- a/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java
+++ b/persistence-modules/java-mongodb-3/src/test/java/com/baeldung/mongo/find/FindWithObjectIdLiveTest.java
@@ -26,7 +26,7 @@ public class FindWithObjectIdLiveTest {
private static MongoClient mongoClient;
private static MongoDatabase database;
private static MongoCollection collection;
- private static final String DATASET_JSON = "/employee.json";
+ private static final String DATASET_JSON = "/vehicle.json";
@BeforeClass
public static void setUp() throws IOException {
@@ -34,7 +34,7 @@ public class FindWithObjectIdLiveTest {
mongoClient = new MongoClient("localhost", 27017);
database = mongoClient.getDatabase("baeldung");
- collection = database.getCollection("employee");
+ collection = database.getCollection("vehicle");
collection.drop();
@@ -47,10 +47,10 @@ public class FindWithObjectIdLiveTest {
}
@Test
- public void givenEmployeeCollection_whenFetchingDocumentsUsingObjectId_thenCheckingForDocuments() {
- Document employee = collection.find()
+ public void givenVehicleCollection_whenFetchingDocumentsUsingObjectId_thenCheckingForDocuments() {
+ Document vehicle = collection.find()
.first();
- ObjectId objectId = (ObjectId) employee.get(OBJECT_ID_FIELD);
+ ObjectId objectId = (ObjectId) vehicle.get(OBJECT_ID_FIELD);
FindIterable documents = collection.find(eq(OBJECT_ID_FIELD, objectId));
MongoCursor cursor = documents.iterator();
@@ -60,24 +60,24 @@ public class FindWithObjectIdLiveTest {
}
@Test
- public void givenEmployeeCollection_whenFetchingFirstDocumentUsingObjectId_thenCheckingForDocument() {
- Document employee = collection.find()
+ public void givenVehicleCollection_whenFetchingFirstDocumentUsingObjectId_thenCheckingForDocument() {
+ Document vehicle = collection.find()
.first();
- ObjectId objectId = (ObjectId) employee.get(OBJECT_ID_FIELD);
+ ObjectId objectId = (ObjectId) vehicle.get(OBJECT_ID_FIELD);
- Document queriedEmployee = collection.find(eq(OBJECT_ID_FIELD, objectId))
+ Document queriedVehicle = collection.find(eq(OBJECT_ID_FIELD, objectId))
.first();
- assertNotNull(queriedEmployee);
- assertEquals(employee.get(OBJECT_ID_FIELD), queriedEmployee.get(OBJECT_ID_FIELD));
+ assertNotNull(queriedVehicle);
+ assertEquals(vehicle.get(OBJECT_ID_FIELD), queriedVehicle.get(OBJECT_ID_FIELD));
}
@Test
- public void givenEmployeeCollection_whenFetchingUsingRandomObjectId_thenCheckingForDocument() {
- Document employee = collection.find(eq(OBJECT_ID_FIELD, new ObjectId()))
+ public void givenVehicleCollection_whenFetchingUsingRandomObjectId_thenCheckingForDocument() {
+ Document vehicle = collection.find(eq(OBJECT_ID_FIELD, new ObjectId()))
.first();
- assertNull(employee);
+ assertNull(vehicle);
}
@AfterClass
diff --git a/persistence-modules/java-mongodb-3/src/test/resources/vehicle.json b/persistence-modules/java-mongodb-3/src/test/resources/vehicle.json
new file mode 100644
index 0000000000..567aba647f
--- /dev/null
+++ b/persistence-modules/java-mongodb-3/src/test/resources/vehicle.json
@@ -0,0 +1,3 @@
+{"companyName":"Skoda","modelName":"Octavia","launchYear":2016,"type":"Sports","registeredNo":"SKO 1134"}
+{"companyName":"BMW","modelName":"X5","launchYear":2020,"type":"SUV","registeredNo":"BMW 3325"}
+{"companyName":"Mercedes","modelName":"Maybach","launchYear":2021,"type":"Luxury","registeredNo":"MER 9754"}
\ No newline at end of file
diff --git a/persistence-modules/java-mongodb-queries/README.md b/persistence-modules/java-mongodb-queries/README.md
index e69de29bb2..30649b0db1 100644
--- a/persistence-modules/java-mongodb-queries/README.md
+++ b/persistence-modules/java-mongodb-queries/README.md
@@ -0,0 +1,3 @@
+
+### Relevant Articles:
+- [Using Dates in CRUD Operations in MongoDB](https://www.baeldung.com/mongodb-java-date-operations)
diff --git a/persistence-modules/java-mongodb-queries/src/main/java/com.baeldung.mongo/crud/CrudClient.java b/persistence-modules/java-mongodb-queries/src/main/java/com/baeldung/mongo/crud/CrudClient.java
similarity index 100%
rename from persistence-modules/java-mongodb-queries/src/main/java/com.baeldung.mongo/crud/CrudClient.java
rename to persistence-modules/java-mongodb-queries/src/main/java/com/baeldung/mongo/crud/CrudClient.java
diff --git a/persistence-modules/java-mongodb-queries/src/main/java/com.baeldung.mongo/crud/model/Event.java b/persistence-modules/java-mongodb-queries/src/main/java/com/baeldung/mongo/crud/model/Event.java
similarity index 100%
rename from persistence-modules/java-mongodb-queries/src/main/java/com.baeldung.mongo/crud/model/Event.java
rename to persistence-modules/java-mongodb-queries/src/main/java/com/baeldung/mongo/crud/model/Event.java
diff --git a/persistence-modules/java-mongodb-queries/src/test/java/com.baeldung.mongo.crud/CrudClientLiveTest.java b/persistence-modules/java-mongodb-queries/src/test/java/com/baeldung/mongo/crud/CrudClientLiveTest.java
similarity index 83%
rename from persistence-modules/java-mongodb-queries/src/test/java/com.baeldung.mongo.crud/CrudClientLiveTest.java
rename to persistence-modules/java-mongodb-queries/src/test/java/com/baeldung/mongo/crud/CrudClientLiveTest.java
index db2f35f634..5b5004fd9f 100644
--- a/persistence-modules/java-mongodb-queries/src/test/java/com.baeldung.mongo.crud/CrudClientLiveTest.java
+++ b/persistence-modules/java-mongodb-queries/src/test/java/com/baeldung/mongo/crud/CrudClientLiveTest.java
@@ -31,6 +31,11 @@ public class CrudClientLiveTest {
@Order(2)
public void whenReadingEventsByDate_thenCheckForReturnedDocument() {
Assertions.assertNotNull(CrudClient.readEventsByDate(CrudClient.dateQuery));
+ Event event = CrudClient.readEventsByDate(CrudClient.dateQuery);
+ Assertions.assertNotNull(event);
+ Assertions.assertEquals("Soccer game", event.title);
+ Assertions.assertEquals("Bar Avenue", event.location);
+ Assertions.assertEquals(CrudClient.soccerGame.dateTime, event.dateTime);
}
@Test
@@ -39,6 +44,9 @@ public class CrudClientLiveTest {
List events = CrudClient.readEventsByDateRange(CrudClient.from, CrudClient.to);
Assertions.assertNotNull(events);
Assertions.assertEquals(1, events.size());
+ Assertions.assertEquals("Soccer game", events.get(0).title);
+ Assertions.assertEquals("Bar Avenue", events.get(0).location);
+ Assertions.assertEquals(CrudClient.soccerGame.dateTime, events.get(0).dateTime);
}
@Test
diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml
index 4bab0631bd..ee4807933a 100644
--- a/persistence-modules/pom.xml
+++ b/persistence-modules/pom.xml
@@ -45,6 +45,7 @@
java-mongodb
java-mongodb-2
java-mongodb-3
+ java-mongodb-queries
jnosql
jooq
jpa-hibernate-cascade-type
diff --git a/pom.xml b/pom.xml
index 046f59de53..6f727d0dd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,9 +7,6 @@
com.baeldung
parent-modules
1.0.0-SNAPSHOT
-
- persistence-modules/java-mongodb-queries
-
parent-modules
pom
@@ -262,7 +259,7 @@
-
+
@@ -281,7 +278,7 @@
-
+
@@ -400,9 +397,7 @@
geotools
google-cloud
google-web-toolkit
-
-
-
+
graphql-modules
grpc
@@ -508,7 +503,7 @@
protobuffer
quarkus-modules
-
+
rabbitmq
ratpack
@@ -624,7 +619,6 @@
spring-katharsis
spring-mobile
- spring-mockito
spring-native
spring-protobuf
spring-quartz
@@ -834,9 +828,7 @@
geotools
google-cloud
google-web-toolkit
-
-
-
+
graphql-modules
grpc
@@ -1053,7 +1045,6 @@
spring-katharsis
spring-mobile
- spring-mockito
spring-native
spring-protobuf
spring-quartz
@@ -1249,6 +1240,7 @@
core-java-modules/core-java-networking-3
core-java-modules/core-java-strings
core-java-modules/core-java-httpclient
+ spring-core-6
ddd-contexts
docker-modules
apache-httpclient-2
@@ -1331,6 +1323,7 @@
testing-modules/testing-assertions
persistence-modules/fauna
lightrun
+ spring-core-6
@@ -1365,7 +1358,7 @@
1.7.32
- 1.2.6
+ 1.2.7
2.22.2
@@ -1401,6 +1394,7 @@
1.18.20
1.4.200
31.0.1-jre
+ 3.2.2
-
+
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-testing-2/pom.xml b/spring-boot-modules/spring-boot-testing-2/pom.xml
index 556142b480..e4f3f122af 100644
--- a/spring-boot-modules/spring-boot-testing-2/pom.xml
+++ b/spring-boot-modules/spring-boot-testing-2/pom.xml
@@ -23,6 +23,10 @@
org.springframework.boot
spring-boot-starter-web-services
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
wsdl4j
wsdl4j
@@ -38,6 +42,12 @@
3.1.3
test
+
+ org.testcontainers
+ testcontainers
+ 1.17.2
+ test
+
diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/RedisTestcontainersApplication.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/RedisTestcontainersApplication.java
new file mode 100644
index 0000000000..50efd56751
--- /dev/null
+++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/RedisTestcontainersApplication.java
@@ -0,0 +1,13 @@
+package com.baeldung.redistestcontainers;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class RedisTestcontainersApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(RedisTestcontainersApplication.class, args);
+ }
+
+}
diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/hash/Product.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/hash/Product.java
new file mode 100644
index 0000000000..3345a17c79
--- /dev/null
+++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/hash/Product.java
@@ -0,0 +1,55 @@
+package com.baeldung.redistestcontainers.hash;
+
+import org.springframework.data.redis.core.RedisHash;
+
+import java.io.Serializable;
+
+@RedisHash("product")
+public class Product implements Serializable {
+ private String id;
+ private String name;
+ private double price;
+
+ // Constructor, getters and setters
+ public Product() {
+ }
+
+ public Product(String id, String name, double price) {
+ this.id = id;
+ this.name = name;
+ this.price = price;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ @Override
+ public String toString() {
+ return "Product{" +
+ "id='" + id + '\'' +
+ ", name='" + name + '\'' +
+ ", price=" + price +
+ '}';
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/repository/ProductRepository.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/repository/ProductRepository.java
new file mode 100644
index 0000000000..5851c282e0
--- /dev/null
+++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/repository/ProductRepository.java
@@ -0,0 +1,9 @@
+package com.baeldung.redistestcontainers.repository;
+
+import com.baeldung.redistestcontainers.hash.Product;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ProductRepository extends CrudRepository {
+}
diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/service/ProductService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/service/ProductService.java
new file mode 100644
index 0000000000..3eb0149ef1
--- /dev/null
+++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/redistestcontainers/service/ProductService.java
@@ -0,0 +1,31 @@
+package com.baeldung.redistestcontainers.service;
+
+import com.baeldung.redistestcontainers.hash.Product;
+import com.baeldung.redistestcontainers.repository.ProductRepository;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ProductService {
+
+ private final ProductRepository productRepository;
+
+ public ProductService(ProductRepository productRepository) {
+ this.productRepository = productRepository;
+ }
+
+ public Product getProduct(String id) {
+ return productRepository.findById(id).orElse(null);
+ }
+
+ void createProduct(Product product) {
+ productRepository.save(product);
+ }
+
+ void updateProduct(Product product) {
+ productRepository.save(product);
+ }
+
+ void deleteProduct(String id) {
+ productRepository.deleteById(id);
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceIntegrationTest.java
new file mode 100644
index 0000000000..519db1b335
--- /dev/null
+++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceIntegrationTest.java
@@ -0,0 +1,75 @@
+package com.baeldung.redistestcontainers.service;
+
+import com.baeldung.redistestcontainers.hash.Product;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.utility.DockerImageName;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@SpringBootTest
+public class ProductServiceIntegrationTest {
+
+ static {
+ GenericContainer> redis = new GenericContainer<>(DockerImageName.parse("redis:5.0.3-alpine"))
+ .withExposedPorts(6379);
+ redis.start();
+ System.setProperty("spring.redis.host", redis.getHost());
+ System.setProperty("spring.redis.port", redis.getMappedPort(6379).toString());
+ }
+
+ @Autowired
+ private ProductService productService;
+
+ @Test
+ void givenProductCreated_whenGettingProductById_thenProductExistsAndHasSameProperties() {
+ Product product = new Product("1", "Test Product", 10.0);
+ productService.createProduct(product);
+ Product productFromDb = productService.getProduct("1");
+ assertEquals("1", productFromDb.getId());
+ assertEquals("Test Product", productFromDb.getName());
+ assertEquals(10.0, productFromDb.getPrice());
+ }
+
+ @Test
+ void givenProductCreatedAndUpdated_whenGettingTheProduct_thenUpdatedProductReturned() {
+ Product product = new Product("1", "Test Product", 10.0);
+ productService.createProduct(product);
+ Product productFromDb = productService.getProduct("1");
+ assertEquals("1", productFromDb.getId());
+ assertEquals("Test Product", productFromDb.getName());
+ assertEquals(10.0, productFromDb.getPrice());
+ productFromDb.setName("Updated Product");
+ productFromDb.setPrice(20.0);
+ productService.updateProduct(productFromDb);
+ Product updatedProductFromDb = productService.getProduct("1");
+ assertEquals("Updated Product", updatedProductFromDb.getName());
+ assertEquals(20.0, updatedProductFromDb.getPrice());
+ }
+
+ @Test
+ void givenProductCreatedAndDeleted_whenGettingTheProduct_thenNoProductReturned() {
+ Product product = new Product("1", "Test Product", 10.0);
+ productService.createProduct(product);
+ Product productFromDb = productService.getProduct("1");
+ assertEquals("1", productFromDb.getId());
+ assertEquals("Test Product", productFromDb.getName());
+ assertEquals(10.0, productFromDb.getPrice());
+ productService.deleteProduct("1");
+ Product deletedProductFromDb = productService.getProduct("1");
+ assertNull(deletedProductFromDb);
+ }
+
+ @Test
+ void givenProductCreated_whenGettingProductById_thenSameProductReturned() {
+ Product product = new Product("1", "Test Product", 10.0);
+ productService.createProduct(product);
+ Product productFromDb = productService.getProduct("1");
+ assertEquals("1", productFromDb.getId());
+ assertEquals("Test Product", productFromDb.getName());
+ assertEquals(10.0, productFromDb.getPrice());
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/README.md b/spring-core-6/README.md
new file mode 100644
index 0000000000..e5d425aa74
--- /dev/null
+++ b/spring-core-6/README.md
@@ -0,0 +1,3 @@
+
+### Relevant Articles:
+- [Instantiating Multiple Beans of the Same Class with Spring Annotations](https://www.baeldung.com/spring-same-class-multiple-beans)
diff --git a/spring-core-6/pom.xml b/spring-core-6/pom.xml
new file mode 100644
index 0000000000..92cd343234
--- /dev/null
+++ b/spring-core-6/pom.xml
@@ -0,0 +1,76 @@
+
+
+ 4.0.0
+
+ com.baeldung
+ spring-core-6
+ 0.0.1-SNAPSHOT
+ spring-core-6
+ http://www.baeldung.com
+
+
+ UTF-8
+ 11
+ 11
+
+
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ 2.0.0.RELEASE
+
+
+
+
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+ maven-resources-plugin
+ 3.0.2
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ maven-surefire-plugin
+ 2.22.1
+
+
+ maven-jar-plugin
+ 3.0.2
+
+
+ maven-install-plugin
+ 2.5.2
+
+
+ maven-deploy-plugin
+ 2.8.2
+
+
+
+ maven-site-plugin
+ 3.7.1
+
+
+ maven-project-info-reports-plugin
+ 3.0.0
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/Person.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/Person.java
new file mode 100644
index 0000000000..04fa6577ac
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/Person.java
@@ -0,0 +1,17 @@
+package com.baeldung.multibeaninstantiation.solution1;
+
+public class Person {
+ private String firstName;
+ private String lastName;
+
+ public Person(String firstName, String secondName) {
+ super();
+ this.firstName = firstName;
+ this.lastName = secondName;
+ }
+
+ @Override
+ public String toString() {
+ return "Person [firstName=" + firstName + ", secondName=" + lastName + "]";
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/PersonConfig.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/PersonConfig.java
new file mode 100644
index 0000000000..ac05ffc0fa
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/PersonConfig.java
@@ -0,0 +1,17 @@
+package com.baeldung.multibeaninstantiation.solution1;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class PersonConfig {
+ @Bean
+ public Person personOne() {
+ return new Person("Harold", "Finch");
+ }
+
+ @Bean
+ public Person personTwo() {
+ return new Person("John", "Reese");
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/SpringApp1.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/SpringApp1.java
new file mode 100644
index 0000000000..c2bc70f3ba
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution1/SpringApp1.java
@@ -0,0 +1,11 @@
+package com.baeldung.multibeaninstantiation.solution1;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringApp1 {
+ public static void main(String[] args) {
+ SpringApplication.run(SpringApp1.class, args);
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/Person.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/Person.java
new file mode 100644
index 0000000000..a1801d1fd2
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/Person.java
@@ -0,0 +1,17 @@
+package com.baeldung.multibeaninstantiation.solution2;
+
+public class Person {
+ private String firstName;
+ private String lastName;
+
+ public Person(String firstName, String secondName) {
+ super();
+ this.firstName = firstName;
+ this.lastName = secondName;
+ }
+
+ @Override
+ public String toString() {
+ return "Person [firstName=" + firstName + ", secondName=" + lastName + "]";
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonConfig.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonConfig.java
new file mode 100644
index 0000000000..da97314579
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonConfig.java
@@ -0,0 +1,10 @@
+package com.baeldung.multibeaninstantiation.solution2;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ComponentScan("com.baeldung.multibeaninstantiation.solution2")
+public class PersonConfig {
+
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonOne.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonOne.java
new file mode 100644
index 0000000000..5d56082f71
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonOne.java
@@ -0,0 +1,13 @@
+package com.baeldung.multibeaninstantiation.solution2;
+
+import org.springframework.stereotype.Component;
+
+import com.baeldung.multibeaninstantiation.solution2.Person;
+
+@Component
+public class PersonOne extends Person {
+
+ public PersonOne() {
+ super("Harold", "Finch");
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonTwo.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonTwo.java
new file mode 100644
index 0000000000..436bd0e96e
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/PersonTwo.java
@@ -0,0 +1,13 @@
+package com.baeldung.multibeaninstantiation.solution2;
+
+import org.springframework.stereotype.Component;
+
+import com.baeldung.multibeaninstantiation.solution2.Person;
+
+@Component
+public class PersonTwo extends Person {
+
+ public PersonTwo() {
+ super("John", "Reese");
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/SpringApp2.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/SpringApp2.java
new file mode 100644
index 0000000000..328ba32777
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution2/SpringApp2.java
@@ -0,0 +1,11 @@
+package com.baeldung.multibeaninstantiation.solution2;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringApp2 {
+ public static void main(String[] args) {
+ SpringApplication.run(SpringApp2.class, args);
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/Human.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/Human.java
new file mode 100644
index 0000000000..d73bd9dfdc
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/Human.java
@@ -0,0 +1,33 @@
+package com.baeldung.multibeaninstantiation.solution3;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.Assert;
+
+public class Human implements InitializingBean {
+
+ private Person personOne;
+
+ private Person personTwo;
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ Assert.notNull(personOne, "Harold is alive!");
+ Assert.notNull(personTwo, "John is alive!");
+ }
+
+ /* Setter injection */
+ @Autowired
+ public void setPersonOne(Person personOne) {
+ this.personOne = personOne;
+ this.personOne.setFirstName("Harold");
+ this.personOne.setSecondName("Finch");
+ }
+
+ @Autowired
+ public void setPersonTwo(Person personTwo) {
+ this.personTwo = personTwo;
+ this.personTwo.setFirstName("John");
+ this.personTwo.setSecondName("Reese");
+ }
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/MultiBeanFactory.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/MultiBeanFactory.java
new file mode 100644
index 0000000000..1753d28d7e
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/MultiBeanFactory.java
@@ -0,0 +1,9 @@
+package com.baeldung.multibeaninstantiation.solution3;
+
+import java.util.List;
+
+public interface MultiBeanFactory {
+ List getObject(String name) throws Exception;
+
+ Class> getObjectType();
+}
\ No newline at end of file
diff --git a/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/Person.java b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/Person.java
new file mode 100644
index 0000000000..a26aee121f
--- /dev/null
+++ b/spring-core-6/src/main/java/com/baeldung/multibeaninstantiation/solution3/Person.java
@@ -0,0 +1,49 @@
+package com.baeldung.multibeaninstantiation.solution3;
+
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.annotation.Qualifier;
+
+@Qualifier(value = "personOne, personTwo")
+public class Person implements FactoryBean