diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml
index 27768d60fc..e0855155bc 100644
--- a/apache-spark/pom.xml
+++ b/apache-spark/pom.xml
@@ -74,6 +74,7 @@
maven-assembly-plugin
+ 3.3.0
package
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
index f529e219a6..0b70516146 100644
--- a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
+++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
@@ -10,5 +10,6 @@ public class CopyListServiceUnitTest {
@Test(expected = UnsupportedOperationException.class)
public void whenModifyCopyOfList_thenThrowsException() {
List copyList = List.copyOf(Arrays.asList(1, 2, 3, 4));
+ copyList.add(4);
}
}
diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExampleCE.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExampleCE.java
new file mode 100644
index 0000000000..7c81142949
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExampleCE.java
@@ -0,0 +1,11 @@
+package com.baeldung.array.arraystoreexception;
+
+public class ArrayStoreExampleCE {
+
+ public static void main(String[] args) {
+
+ //String array[] = new String[5]; //This will lead to compile-time error at line-8 when uncommented
+ //array[0] = 2;
+ }
+
+}
diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExceptionExample.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExceptionExample.java
new file mode 100644
index 0000000000..ce63fd6605
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExceptionExample.java
@@ -0,0 +1,16 @@
+package com.baeldung.array.arraystoreexception;
+
+public class ArrayStoreExceptionExample {
+
+ public static void main(String[] args) {
+
+ try {
+ Object array[] = new String[5];
+ array[0] = 2;
+ } catch (ArrayStoreException e) {
+ // handle the exception
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-io-2/src/main/resources/logback.xml b/core-java-modules/core-java-io-2/src/main/resources/logback.xml
new file mode 100644
index 0000000000..f46a64b3cb
--- /dev/null
+++ b/core-java-modules/core-java-io-2/src/main/resources/logback.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n
+
+
+
+
+
+
+
diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java
new file mode 100644
index 0000000000..ca6b25b3e7
--- /dev/null
+++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java
@@ -0,0 +1,60 @@
+package com.baeldung.algorithms.largestpowerof2;
+
+import org.nd4j.linalg.io.Assert;
+
+public class LargestPowerOf2 {
+ public long findLargestPowerOf2LessThanTheGivenNumber(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+
+ long firstPowerOf2 = 1;
+ long nextPowerOf2 = 2;
+
+ while (nextPowerOf2 < input) {
+ firstPowerOf2 = nextPowerOf2;
+ nextPowerOf2 = nextPowerOf2 * 2;
+ }
+ return firstPowerOf2;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingLogBase2(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+
+ long temp = input;
+ if (input % 2 == 0) {
+ temp = input - 1;
+ }
+
+ // Find log base 2 of a given number
+ long power = (long) (Math.log(temp) / Math.log(2));
+ long result = (long) Math.pow(2, power);
+
+ return result;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingBitwiseAnd(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+ long result = 1;
+ for (long i = input - 1; i > 1; i--) {
+ if ((i & (i - 1)) == 0) {
+ result = i;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingBitShiftApproach(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+ long result = 1;
+ long powerOf2;
+
+ for (long i = 0; i < Long.BYTES * 8; i++) {
+ powerOf2 = 1 << i;
+ if (powerOf2 >= input) {
+ break;
+ }
+ result = powerOf2;
+ }
+ return result;
+ }
+}
diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java
new file mode 100644
index 0000000000..63f7b03cf7
--- /dev/null
+++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java
@@ -0,0 +1,67 @@
+package com.baeldung.algorithms.largestpowerof2;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class LargestPowerOf2UnitTest {
+ private long input;
+ private long expectedResult;
+
+ public LargestPowerOf2UnitTest(long input, long expectedResult) {
+ this.input = input;
+ this.expectedResult = expectedResult;
+ }
+
+ @Parameterized.Parameters(name = "{index}: verifyLargestPowerOf2LessThanTheGivenNumber({0}) = {1}")
+ public static Collection
diff --git a/spring-ejb/ejb-beans/src/test/resources/logging.properties b/spring-ejb/ejb-beans/src/test/resources/logging.properties
new file mode 100644
index 0000000000..0a0ecef337
--- /dev/null
+++ b/spring-ejb/ejb-beans/src/test/resources/logging.properties
@@ -0,0 +1,2 @@
+handlers = java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level = SEVERE
\ No newline at end of file
diff --git a/spring-jooq/pom.xml b/spring-jooq/pom.xml
index c07d6278cb..95418645fa 100644
--- a/spring-jooq/pom.xml
+++ b/spring-jooq/pom.xml
@@ -30,6 +30,7 @@
org.jooq
jooq
+ ${org.jooq.version}
@@ -201,7 +202,7 @@
- 3.11.7
+ 3.12.4
1.0.0
1.5
1.0.0
diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml
index 3aeaa973af..674d9a2a14 100644
--- a/spring-katharsis/pom.xml
+++ b/spring-katharsis/pom.xml
@@ -10,9 +10,9 @@
com.baeldung
- parent-boot-1
+ parent-boot-2
0.0.1-SNAPSHOT
- ../parent-boot-1
+ ../parent-boot-2
diff --git a/spring-katharsis/src/main/java/com/baeldung/Application.java b/spring-katharsis/src/main/java/com/baeldung/Application.java
index 6c4f047b26..738afa039e 100644
--- a/spring-katharsis/src/main/java/com/baeldung/Application.java
+++ b/spring-katharsis/src/main/java/com/baeldung/Application.java
@@ -4,7 +4,7 @@ import io.katharsis.spring.boot.v3.KatharsisConfigV3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;
@SpringBootApplication
diff --git a/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/RoleResourceRepository.java b/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/RoleResourceRepository.java
index c5e6326075..a249def128 100644
--- a/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/RoleResourceRepository.java
+++ b/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/RoleResourceRepository.java
@@ -7,6 +7,9 @@ import io.katharsis.repository.ResourceRepositoryV2;
import io.katharsis.resource.list.ResourceList;
import com.baeldung.persistence.model.Role;
+
+import java.util.Optional;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,7 +20,8 @@ public class RoleResourceRepository implements ResourceRepositoryV2
@Override
public Role findOne(Long id, QuerySpec querySpec) {
- return roleRepository.findOne(id);
+ Optional role = roleRepository.findById(id);
+ return role.isPresent()? role.get() : null;
}
@Override
@@ -27,7 +31,7 @@ public class RoleResourceRepository implements ResourceRepositoryV2
@Override
public ResourceList findAll(Iterable ids, QuerySpec querySpec) {
- return querySpec.apply(roleRepository.findAll(ids));
+ return querySpec.apply(roleRepository.findAllById(ids));
}
@Override
@@ -37,7 +41,7 @@ public class RoleResourceRepository implements ResourceRepositoryV2
@Override
public void delete(Long id) {
- roleRepository.delete(id);
+ roleRepository.deleteById(id);
}
@Override
diff --git a/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserResourceRepository.java b/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserResourceRepository.java
index 616431f3f0..af71da4727 100644
--- a/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserResourceRepository.java
+++ b/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserResourceRepository.java
@@ -6,6 +6,8 @@ import io.katharsis.queryspec.QuerySpec;
import io.katharsis.repository.ResourceRepositoryV2;
import io.katharsis.resource.list.ResourceList;
+import java.util.Optional;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,7 +19,8 @@ public class UserResourceRepository implements ResourceRepositoryV2
@Override
public User findOne(Long id, QuerySpec querySpec) {
- return userRepository.findOne(id);
+ Optional user = userRepository.findById(id);
+ return user.isPresent()? user.get() : null;
}
@Override
@@ -27,7 +30,7 @@ public class UserResourceRepository implements ResourceRepositoryV2
@Override
public ResourceList findAll(Iterable ids, QuerySpec querySpec) {
- return querySpec.apply(userRepository.findAll(ids));
+ return querySpec.apply(userRepository.findAllById(ids));
}
@Override
@@ -37,7 +40,7 @@ public class UserResourceRepository implements ResourceRepositoryV2
@Override
public void delete(Long id) {
- userRepository.delete(id);
+ userRepository.deleteById(id);
}
@Override
diff --git a/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java b/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java
index 066292c00f..d0b4a464c9 100644
--- a/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java
+++ b/spring-katharsis/src/main/java/com/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java
@@ -8,6 +8,7 @@ import io.katharsis.repository.RelationshipRepositoryV2;
import io.katharsis.resource.list.ResourceList;
import java.util.HashSet;
+import java.util.Optional;
import java.util.Set;
import com.baeldung.persistence.model.Role;
@@ -31,7 +32,7 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public void setRelations(User user, Iterable roleIds, String fieldName) {
final Set roles = new HashSet();
- roles.addAll(roleRepository.findAll(roleIds));
+ roles.addAll(roleRepository.findAllById(roleIds));
user.setRoles(roles);
userRepository.save(user);
}
@@ -39,7 +40,7 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public void addRelations(User user, Iterable roleIds, String fieldName) {
final Set roles = user.getRoles();
- roles.addAll(roleRepository.findAll(roleIds));
+ roles.addAll(roleRepository.findAllById(roleIds));
user.setRoles(roles);
userRepository.save(user);
}
@@ -47,7 +48,7 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public void removeRelations(User user, Iterable roleIds, String fieldName) {
final Set roles = user.getRoles();
- roles.removeAll(roleRepository.findAll(roleIds));
+ roles.removeAll(roleRepository.findAllById(roleIds));
user.setRoles(roles);
userRepository.save(user);
}
@@ -60,7 +61,8 @@ public class UserToRoleRelationshipRepository implements RelationshipRepositoryV
@Override
public ResourceList findManyTargets(Long sourceId, String fieldName, QuerySpec querySpec) {
- final User user = userRepository.findOne(sourceId);
+ final Optional userOptional = userRepository.findById(sourceId);
+ User user = userOptional.isPresent() ? userOptional.get() : new User();
return querySpec.apply(user.getRoles());
}
diff --git a/spring-katharsis/src/main/resources/application.properties b/spring-katharsis/src/main/resources/application.properties
index 120b3c62ee..415ec1723b 100644
--- a/spring-katharsis/src/main/resources/application.properties
+++ b/spring-katharsis/src/main/resources/application.properties
@@ -6,7 +6,7 @@ spring.jpa.hibernate.ddl-auto = create-drop
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
server.port=8082
-server.context-path=/spring-katharsis
+server.servlet.context-path=/spring-katharsis
katharsis.domainName=http://localhost:8082/spring-katharsis
katharsis.pathPrefix=/
\ No newline at end of file
diff --git a/spring-remoting/remoting-hessian-burlap/pom.xml b/spring-remoting/remoting-hessian-burlap/pom.xml
index fac6e1cb2e..67e3e3eab4 100644
--- a/spring-remoting/remoting-hessian-burlap/pom.xml
+++ b/spring-remoting/remoting-hessian-burlap/pom.xml
@@ -9,6 +9,7 @@
pom
+
com.baeldung
parent-boot-1
0.0.1-SNAPSHOT
diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java
new file mode 100644
index 0000000000..dfcfdc1117
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogController.java
@@ -0,0 +1,23 @@
+package com.baeldung.thymeleaf.blog;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.util.Random;
+
+@Controller
+public class BlogController {
+
+ @GetMapping("/blog/new")
+ public String newBlogPost(Model model) {
+ // Set a random ID so we can see it in the HTML form
+ BlogDTO blog = new BlogDTO();
+ blog.setBlogId(Math.abs(new Random().nextLong() % 1000000));
+
+ model.addAttribute("blog", blog);
+
+ return "blog/blog-new";
+ }
+
+}
diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java
new file mode 100644
index 0000000000..44c77be5ce
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/blog/BlogDTO.java
@@ -0,0 +1,66 @@
+package com.baeldung.thymeleaf.blog;
+
+import java.util.Date;
+
+public class BlogDTO {
+
+ private long blogId;
+
+ private String title;
+
+ private String body;
+
+ private String author;
+
+ private String category;
+
+ private Date publishedDate;
+
+ public long getBlogId() {
+ return blogId;
+ }
+
+ public void setBlogId(long blogId) {
+ this.blogId = blogId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(String body) {
+ this.body = body;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public Date getPublishedDate() {
+ return publishedDate;
+ }
+
+ public void setPublishedDate(Date publishedDate) {
+ this.publishedDate = publishedDate;
+ }
+}
diff --git a/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html b/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html
new file mode 100644
index 0000000000..10747b4b07
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/templates/blog/blog-new.html
@@ -0,0 +1,36 @@
+
+
+
+
+ Hidden Input Examples
+
+
+
+Hidden Input Example 1
+
+
+Hidden Input Example 2
+
+
+Hidden Input Example 3
+
+
+
\ No newline at end of file
diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml
index b467b3c503..f1d30cd7a1 100644
--- a/testing-modules/pom.xml
+++ b/testing-modules/pom.xml
@@ -31,7 +31,8 @@
rest-assured
rest-testing
selenium-junit-testng
- spring-testing
+ spring-testing
+ spring-testing-2
test-containers
testing-assertions
testng
diff --git a/testing-modules/spring-testing-2/.gitignore b/testing-modules/spring-testing-2/.gitignore
new file mode 100644
index 0000000000..ffc5bf3bad
--- /dev/null
+++ b/testing-modules/spring-testing-2/.gitignore
@@ -0,0 +1,3 @@
+.idea/**
+target/**
+*.iml
\ No newline at end of file
diff --git a/testing-modules/spring-testing-2/README.md b/testing-modules/spring-testing-2/README.md
new file mode 100644
index 0000000000..729105e3fd
--- /dev/null
+++ b/testing-modules/spring-testing-2/README.md
@@ -0,0 +1 @@
+## Relevant Articles:
diff --git a/testing-modules/spring-testing-2/pom.xml b/testing-modules/spring-testing-2/pom.xml
new file mode 100644
index 0000000000..c7ca2804fb
--- /dev/null
+++ b/testing-modules/spring-testing-2/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ 4.0.0
+ spring-testing-2
+ 0.1-SNAPSHOT
+ spring-testing-2
+
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+ org.postgresql
+ postgresql
+ runtime
+
+
+
+
+ org.testcontainers
+ postgresql
+ ${testcontainers.version}
+ test
+
+
+ org.testcontainers
+ junit-jupiter
+ ${testcontainers.version}
+ test
+
+
+
+
+
+ 2.1.9.RELEASE
+ 2.1.9.RELEASE
+ 1.12.2
+
+
\ No newline at end of file
diff --git a/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/Article.java b/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/Article.java
new file mode 100644
index 0000000000..6b6bfb7bd6
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/Article.java
@@ -0,0 +1,45 @@
+package com.baeldung.dynamicproperties;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import static javax.persistence.GenerationType.IDENTITY;
+
+@Entity
+@Table(name = "articles")
+public class Article {
+
+ @Id
+ @GeneratedValue(strategy = IDENTITY)
+ private Long id;
+
+ private String title;
+
+ private String content;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+}
diff --git a/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/ArticleRepository.java b/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/ArticleRepository.java
new file mode 100644
index 0000000000..3f3731f6dc
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/ArticleRepository.java
@@ -0,0 +1,6 @@
+package com.baeldung.dynamicproperties;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface ArticleRepository extends JpaRepository {
+}
diff --git a/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/DynamicPropertiesApplication.java b/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/DynamicPropertiesApplication.java
new file mode 100644
index 0000000000..d64bd965fc
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/main/java/com/baeldung/dynamicproperties/DynamicPropertiesApplication.java
@@ -0,0 +1,12 @@
+package com.baeldung.dynamicproperties;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class DynamicPropertiesApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(DynamicPropertiesApplication.class, args);
+ }
+}
diff --git a/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleLiveTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleLiveTest.java
new file mode 100644
index 0000000000..74c31229bd
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleLiveTest.java
@@ -0,0 +1,50 @@
+package com.baeldung.dynamicproperties;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.DynamicPropertyRegistry;
+import org.springframework.test.context.DynamicPropertySource;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SpringBootTest
+@Testcontainers
+@ActiveProfiles("pg")
+public class ArticleLiveTest {
+
+ @Container
+ static PostgreSQLContainer> postgres = new PostgreSQLContainer<>("postgres:11")
+ .withDatabaseName("prop")
+ .withUsername("postgres")
+ .withPassword("pass")
+ .withExposedPorts(5432);
+
+ @Autowired
+ private ArticleRepository articleRepository;
+
+ @DynamicPropertySource
+ static void registerPgProperties(DynamicPropertyRegistry registry) {
+ registry.add("spring.datasource.url",
+ () -> String.format("jdbc:postgresql://localhost:%d/prop", postgres.getFirstMappedPort()));
+ registry.add("spring.datasource.username", () -> "postgres");
+ registry.add("spring.datasource.password", () -> "pass");
+ }
+
+ @Test
+ void givenAnArticle_whenPersisted_thenCanBeFoundInTheDb() {
+ Article article = new Article();
+ article.setTitle("A Guide to @DynamicPropertySource in Spring");
+ article.setContent("Today's applications...");
+
+ articleRepository.save(article);
+ Article persisted = articleRepository.findAll().get(0);
+ assertThat(persisted.getId()).isNotNull();
+ assertThat(persisted.getTitle()).isEqualTo("A Guide to @DynamicPropertySource in Spring");
+ assertThat(persisted.getContent()).isEqualTo("Today's applications...");
+ }
+}
diff --git a/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleTestFixtureLiveTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleTestFixtureLiveTest.java
new file mode 100644
index 0000000000..bb3ad28365
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleTestFixtureLiveTest.java
@@ -0,0 +1,31 @@
+package com.baeldung.dynamicproperties;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SpringBootTest
+@ActiveProfiles("pg")
+@ExtendWith(PostgreSQLExtension.class)
+public class ArticleTestFixtureLiveTest {
+
+ @Autowired
+ private ArticleRepository articleRepository;
+
+ @Test
+ void givenAnArticle_whenPersisted_thenShouldBeAbleToReadIt() {
+ Article article = new Article();
+ article.setTitle("A Guide to @DynamicPropertySource in Spring");
+ article.setContent("Today's applications...");
+
+ articleRepository.save(article);
+ Article persisted = articleRepository.findAll().get(0);
+ assertThat(persisted.getId()).isNotNull();
+ assertThat(persisted.getTitle()).isEqualTo("A Guide to @DynamicPropertySource in Spring");
+ assertThat(persisted.getContent()).isEqualTo("Today's applications...");
+ }
+}
diff --git a/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleTraditionalLiveTest.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleTraditionalLiveTest.java
new file mode 100644
index 0000000000..87234505a9
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/ArticleTraditionalLiveTest.java
@@ -0,0 +1,57 @@
+package com.baeldung.dynamicproperties;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.util.TestPropertyValues;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SpringBootTest
+@Testcontainers
+@ActiveProfiles("pg")
+@ContextConfiguration(initializers = ArticleTraditionalLiveTest.EnvInitializer.class)
+class ArticleTraditionalLiveTest {
+
+ @Container
+ static PostgreSQLContainer> postgres = new PostgreSQLContainer<>("postgres:11")
+ .withDatabaseName("prop")
+ .withUsername("postgres")
+ .withPassword("pass")
+ .withExposedPorts(5432);
+
+ static class EnvInitializer implements ApplicationContextInitializer {
+
+ @Override
+ public void initialize(ConfigurableApplicationContext applicationContext) {
+ TestPropertyValues.of(
+ String.format("spring.datasource.url=jdbc:postgresql://localhost:%d/prop", postgres.getFirstMappedPort()),
+ "spring.datasource.username=postgres",
+ "spring.datasource.password=pass"
+ ).applyTo(applicationContext);
+ }
+ }
+
+ @Autowired
+ private ArticleRepository articleRepository;
+
+ @Test
+ void givenAnArticle_whenPersisted_thenShouldBeAbleToReadIt() {
+ Article article = new Article();
+ article.setTitle("A Guide to @DynamicPropertySource in Spring");
+ article.setContent("Today's applications...");
+
+ articleRepository.save(article);
+ Article persisted = articleRepository.findAll().get(0);
+ assertThat(persisted.getId()).isNotNull();
+ assertThat(persisted.getTitle()).isEqualTo("A Guide to @DynamicPropertySource in Spring");
+ assertThat(persisted.getContent()).isEqualTo("Today's applications...");
+ }
+}
diff --git a/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/PostgreSQLExtension.java b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/PostgreSQLExtension.java
new file mode 100644
index 0000000000..8c08ad67d7
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/PostgreSQLExtension.java
@@ -0,0 +1,31 @@
+package com.baeldung.dynamicproperties;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.testcontainers.containers.PostgreSQLContainer;
+
+public class PostgreSQLExtension implements BeforeAllCallback, AfterAllCallback {
+
+ private PostgreSQLContainer> postgres;
+
+ @Override
+ public void beforeAll(ExtensionContext context) {
+ postgres = new PostgreSQLContainer<>("postgres:11")
+ .withDatabaseName("prop")
+ .withUsername("postgres")
+ .withPassword("pass")
+ .withExposedPorts(5432);
+
+ postgres.start();
+ String jdbcUrl = String.format("jdbc:postgresql://localhost:%d/prop", postgres.getFirstMappedPort());
+ System.setProperty("spring.datasource.url", jdbcUrl);
+ System.setProperty("spring.datasource.username", "postgres");
+ System.setProperty("spring.datasource.password", "pass");
+ }
+
+ @Override
+ public void afterAll(ExtensionContext context) {
+ postgres.stop();
+ }
+}
diff --git a/testing-modules/spring-testing-2/src/test/resources/application-pg.properties b/testing-modules/spring-testing-2/src/test/resources/application-pg.properties
new file mode 100644
index 0000000000..cb7bff1889
--- /dev/null
+++ b/testing-modules/spring-testing-2/src/test/resources/application-pg.properties
@@ -0,0 +1,2 @@
+spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
+spring.jpa.hibernate.ddl-auto=create-drop
\ No newline at end of file
diff --git a/testing-modules/testing-assertions/pom.xml b/testing-modules/testing-assertions/pom.xml
index 0a7c4b0860..fa0f666c7f 100644
--- a/testing-modules/testing-assertions/pom.xml
+++ b/testing-modules/testing-assertions/pom.xml
@@ -18,11 +18,45 @@
logback-classic
1.2.3
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.6.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.6.2
+ test
+
org.assertj
assertj-core
- 3.15.0
+ 3.16.1
+ test
+
+
+ org.hamcrest
+ hamcrest-all
+ 1.3
+ test
+
+
+ org.apache.commons
+ commons-collections4
+ 4.4
test
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.1
+
+
+
diff --git a/testing-modules/testing-assertions/src/test/java/com/baeldung/listassert/OrderAgnosticListComparisonUnitTest.java b/testing-modules/testing-assertions/src/test/java/com/baeldung/listassert/OrderAgnosticListComparisonUnitTest.java
new file mode 100644
index 0000000000..bf278cea90
--- /dev/null
+++ b/testing-modules/testing-assertions/src/test/java/com/baeldung/listassert/OrderAgnosticListComparisonUnitTest.java
@@ -0,0 +1,54 @@
+package com.baeldung.listassert;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class OrderAgnosticListComparisonUnitTest {
+
+ private final List first = Arrays.asList(1, 3, 4, 6, 8);
+ private final List second = Arrays.asList(8, 1, 6, 3, 4);
+ private final List third = Arrays.asList(1, 3, 3, 6, 6);
+
+ @Test
+ public void whenTestingForOrderAgnosticEquality_ShouldBeTrue() {
+ assertTrue(first.size() == second.size() && first.containsAll(second) && second.containsAll(first));
+ }
+
+ @Test
+ public void whenTestingForOrderAgnosticEquality_ShouldBeFalse() {
+ assertFalse(first.size() == third.size() && first.containsAll(third) && third.containsAll(first));
+ }
+
+ @Test
+ public void whenTestingForOrderAgnosticEquality_ShouldBeEqual() {
+ MatcherAssert.assertThat(first, Matchers.containsInAnyOrder(second.toArray()));
+ }
+
+ @Test
+ public void whenTestingForOrderAgnosticEquality_ShouldBeTrueIfEqualOtherwiseFalse() {
+ assertTrue(CollectionUtils.isEqualCollection(first, second));
+ assertFalse(CollectionUtils.isEqualCollection(first, third));
+ }
+
+ @Test
+ void whenTestingForOrderAgnosticEqualityBothList_ShouldBeEqual() {
+ assertThat(first).hasSameElementsAs(second);
+ }
+
+ @Test
+ void whenTestingForOrderAgnosticEqualityBothList_ShouldNotBeEqual() {
+ List a = Arrays.asList("a", "a", "b", "c");
+ List b = Arrays.asList("a", "b", "c");
+
+ assertThat(a).hasSameElementsAs(b);
+ }
+}