From 50712e1ab2051f91cefb28a301a00fd440eb5a17 Mon Sep 17 00:00:00 2001 From: sharifi Date: Mon, 1 Nov 2021 11:01:44 +0330 Subject: [PATCH 01/78] bael-4604: add main class --- .../main/java/com/baeldung/hmac/HMACUtil.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 core-java-modules/core-java-security-3/src/main/java/com/baeldung/hmac/HMACUtil.java diff --git a/core-java-modules/core-java-security-3/src/main/java/com/baeldung/hmac/HMACUtil.java b/core-java-modules/core-java-security-3/src/main/java/com/baeldung/hmac/HMACUtil.java new file mode 100644 index 0000000000..3b504d9338 --- /dev/null +++ b/core-java-modules/core-java-security-3/src/main/java/com/baeldung/hmac/HMACUtil.java @@ -0,0 +1,68 @@ +package com.baeldung.hmac; + +import org.apache.commons.codec.digest.HmacUtils; +import org.bouncycastle.crypto.Digest; +import org.bouncycastle.crypto.digests.MD5Digest; +import org.bouncycastle.crypto.digests.SHA256Digest; +import org.bouncycastle.crypto.digests.SHA384Digest; +import org.bouncycastle.crypto.digests.SHA512Digest; +import org.bouncycastle.crypto.macs.HMac; +import org.bouncycastle.crypto.params.KeyParameter; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + + +public class HMACUtil { + + public static String hmacWithJava(String algorithm, String data, String key) + throws NoSuchAlgorithmException, InvalidKeyException { + SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), algorithm); + Mac mac = Mac.getInstance(algorithm); + mac.init(secretKeySpec); + return bytesToHex(mac.doFinal(data.getBytes())); + } + + public static String hmacWithApacheCommons(String algorithm, String data, String key) { + String hmac = new HmacUtils(algorithm, key).hmacHex(data); + return hmac; + } + + public static String hmacWithBouncyCastle(String algorithm, String data, String key) { + Digest digest = getHashDigest(algorithm); + HMac hMac = new HMac(digest); + hMac.init(new KeyParameter(key.getBytes())); + byte[] hmacIn = data.getBytes(); + hMac.update(hmacIn, 0, hmacIn.length); + byte[] hmacOut = new byte[hMac.getMacSize()]; + hMac.doFinal(hmacOut, 0); + return bytesToHex(hmacOut); + } + + private static Digest getHashDigest(String algorithm) { + switch (algorithm) { + case "HmacMD5": + return new MD5Digest(); + case "HmacSHA256": + return new SHA256Digest(); + case "HmacSHA384": + return new SHA384Digest(); + case "HmacSHA512": + return new SHA512Digest(); + } + return new SHA256Digest(); + } + + public static String bytesToHex(byte[] hash) { + StringBuilder hexString = new StringBuilder(2 * hash.length); + for (byte h : hash) { + String hex = Integer.toHexString(0xff & h); + if (hex.length() == 1) + hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } +} From 371eda2fc1a94e8044c6449335883a1a01217a14 Mon Sep 17 00:00:00 2001 From: sharifi Date: Mon, 1 Nov 2021 11:01:53 +0330 Subject: [PATCH 02/78] bael-4604: add test class --- .../com/baeldung/hmac/HMACUtilUnitTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java diff --git a/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java b/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java new file mode 100644 index 0000000000..86e81f5895 --- /dev/null +++ b/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java @@ -0,0 +1,50 @@ +package com.baeldung.hmac; + +import org.junit.Test; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import static org.junit.Assert.assertEquals; + +public class HMACUtilUnitTest { + + private static String hmacSHA256Value = "5b50d80c7dc7ae8bb1b1433cc0b99ecd2ac8397a555c6f75cb8a619ae35a0c35"; + private static String hmacMD5Value = "621dc816b3bf670212e0c261dc9bcdb6"; + private static String hmacSHA512Value = "b313a21908df55c9e322e3c65a4b0b7561ab1594ca806b3affbc0d769a1290c1922aa6622587bea3c0c4d871470a6d06f54dbd20dbda84250e2741eb01f08e33"; + + //given + String hmacSHA256Algorithm = "HmacSHA256"; + String hmacSHA512Algorithm = "HmacSHA512"; + String hmacMD5Algorithm = "HmacMD5"; + String data = "baeldung"; + String key = "123456"; + + @Test + public void givenDataAndKeyAndAlgorithm_whenHmacWithJava_thenSuccess() + throws NoSuchAlgorithmException, InvalidKeyException { + //when + String result = HMACUtil.hmacWithJava(hmacSHA256Algorithm, data, key); + + //then + assertEquals(hmacSHA256Value, result); + } + + @Test + public void givenDataAndKeyAndAlgorithm_whenHmacWithApacheCommons_thenSuccess() { + //when + String result = HMACUtil.hmacWithApacheCommons(hmacMD5Algorithm, data, key); + + //then + assertEquals(hmacMD5Value, result); + } + + @Test + public void givenDataAndKeyAndAlgorithm_whenHmacWithBouncyCastle_thenSuccess() { + //when + String result = HMACUtil.hmacWithBouncyCastle(hmacSHA512Algorithm, data, key); + + //then + assertEquals(hmacSHA512Value, result); + } +} From b846f1039e7055f73bd4f4524d76d7aac210fc49 Mon Sep 17 00:00:00 2001 From: Azhwani Date: Tue, 2 Nov 2021 20:25:06 +0100 Subject: [PATCH 03/78] conflits resolution --- testing-modules/junit-5/pom.xml | 3 ++ .../order/AlphanumericOrderUnitTest.java | 14 ++++---- .../junit5/order/DefaultOrderUnitTest.java | 36 +++++++++++++++++++ .../junit5/order/RandomOrderUnitTest.java | 35 ++++++++++++++++++ .../test/resources/junit-platform.properties | 2 ++ 5 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/DefaultOrderUnitTest.java create mode 100644 testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/RandomOrderUnitTest.java create mode 100644 testing-modules/junit-5/src/test/resources/junit-platform.properties diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 148abecb0f..9b2518d10b 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -137,7 +137,10 @@ + 5.8.1 2.23.0 + 1.8.1 + 5.8.1 2.8.2 2.0.0 2.22.0 diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/AlphanumericOrderUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/AlphanumericOrderUnitTest.java index d62ca0c666..873df30400 100644 --- a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/AlphanumericOrderUnitTest.java +++ b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/AlphanumericOrderUnitTest.java @@ -3,29 +3,29 @@ package com.baeldung.junit5.order; import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.MethodOrderer.Alphanumeric; +import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -@TestMethodOrder(Alphanumeric.class) +@TestMethodOrder(MethodOrderer.MethodName.class) public class AlphanumericOrderUnitTest { private static StringBuilder output = new StringBuilder(""); - + @Test public void myATest() { output.append("A"); } - + @Test public void myBTest() { - output.append("B"); + output.append("B"); } - + @Test public void myaTest() { output.append("a"); } - + @AfterAll public static void assertOutput() { assertEquals(output.toString(), "ABa"); diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/DefaultOrderUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/DefaultOrderUnitTest.java new file mode 100644 index 0000000000..65cee3e987 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/DefaultOrderUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.junit5.order; + +import static org.junit.Assert.assertEquals; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class DefaultOrderUnitTest { + + private static StringBuilder output = new StringBuilder(""); + + @Test + @DisplayName("Test A") + public void myATest() { + output.append("A"); + } + + @Test + @DisplayName("Test B") + public void myBTest() { + output.append("B"); + } + + @Test + @DisplayName("Test C") + public void myCTest() { + output.append("C"); + } + + @AfterAll + public static void assertOutput() { + assertEquals(output.toString(), "ABC"); + } + +} diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/RandomOrderUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/RandomOrderUnitTest.java new file mode 100644 index 0000000000..0f64f5bb31 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/junit5/order/RandomOrderUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.junit5.order; + +import static org.junit.Assert.assertEquals; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +@TestMethodOrder(MethodOrderer.Random.class) +public class RandomOrderUnitTest { + + private static StringBuilder output = new StringBuilder(""); + + @Test + public void myATest() { + output.append("A"); + } + + @Test + public void myBTest() { + output.append("B"); + } + + @Test + public void myCTest() { + output.append("C"); + } + + @AfterAll + public static void assertOutput() { + assertEquals(output.toString(), "ACB"); + } + +} diff --git a/testing-modules/junit-5/src/test/resources/junit-platform.properties b/testing-modules/junit-5/src/test/resources/junit-platform.properties new file mode 100644 index 0000000000..d25e866b43 --- /dev/null +++ b/testing-modules/junit-5/src/test/resources/junit-platform.properties @@ -0,0 +1,2 @@ +junit.jupiter.execution.order.random.seed=100 +junit.jupiter.testmethod.order.default = org.junit.jupiter.api.MethodOrderer$DisplayName \ No newline at end of file From 910e6945dc9c54b1e177a030074370d519b2fe56 Mon Sep 17 00:00:00 2001 From: Azhwani Date: Tue, 2 Nov 2021 19:58:44 +0100 Subject: [PATCH 04/78] init commit --- .../junit-5/src/test/resources/junit-platform.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/junit-5/src/test/resources/junit-platform.properties b/testing-modules/junit-5/src/test/resources/junit-platform.properties index d25e866b43..a02be290e0 100644 --- a/testing-modules/junit-5/src/test/resources/junit-platform.properties +++ b/testing-modules/junit-5/src/test/resources/junit-platform.properties @@ -1,2 +1,2 @@ junit.jupiter.execution.order.random.seed=100 -junit.jupiter.testmethod.order.default = org.junit.jupiter.api.MethodOrderer$DisplayName \ No newline at end of file +junit.jupiter.testmethod.order.default = org.junit.jupiter.api.MethodOrderer$DisplayName From f6ef8e6dc3388f4932c8482cbd5ed2e662b9ac66 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Thu, 4 Nov 2021 18:15:45 +0000 Subject: [PATCH 05/78] BAEL-5209 example with JUnit5, Hamcrest and AssertJ --- .../com/baeldung/object/type/Deciduous.java | 15 ++++++++++ .../com/baeldung/object/type/Evergreen.java | 16 +++++++++++ .../java/com/baeldung/object/type/Tree.java | 6 ++++ .../com/baeldung/object/type/TreeSorter.java | 19 +++++++++++++ .../type/TreeSorterAssertJUnitTest.java | 22 +++++++++++++++ .../type/TreeSorterHamcrestUnitTest.java | 28 +++++++++++++++++++ 6 files changed, 106 insertions(+) create mode 100644 testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Deciduous.java create mode 100644 testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Evergreen.java create mode 100644 testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Tree.java create mode 100644 testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/TreeSorter.java create mode 100644 testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterAssertJUnitTest.java create mode 100644 testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterHamcrestUnitTest.java diff --git a/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Deciduous.java b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Deciduous.java new file mode 100644 index 0000000000..ae96446a63 --- /dev/null +++ b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Deciduous.java @@ -0,0 +1,15 @@ +package com.baeldung.object.type; + +public class Deciduous implements Tree { + + private String name; + + public Deciduous(String name) { + this.name = name; + } + + @Override + public boolean isEvergreen() { + return false; + } +} diff --git a/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Evergreen.java b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Evergreen.java new file mode 100644 index 0000000000..56cda60d22 --- /dev/null +++ b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Evergreen.java @@ -0,0 +1,16 @@ +package com.baeldung.object.type; + +public class Evergreen implements Tree { + + private String name; + + public Evergreen(String name) { + this.name = name; + } + + + @Override + public boolean isEvergreen() { + return true; + } +} diff --git a/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Tree.java b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Tree.java new file mode 100644 index 0000000000..0230c61e38 --- /dev/null +++ b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/Tree.java @@ -0,0 +1,6 @@ +package com.baeldung.object.type; + +public interface Tree { + + public boolean isEvergreen(); +} diff --git a/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/TreeSorter.java b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/TreeSorter.java new file mode 100644 index 0000000000..af4a6e5ef8 --- /dev/null +++ b/testing-modules/testing-assertions/src/main/java/com/baeldung/object/type/TreeSorter.java @@ -0,0 +1,19 @@ +package com.baeldung.object.type; + +import java.util.List; + +public class TreeSorter { + protected Tree sortTree(String name) { + + final List deciduous = List.of("Beech", "Birch", "Ash", "Whitebeam", "Hornbeam", "Hazel & Willow"); + final List evergreen = List.of("Cedar", "Holly", "Laurel", "Olive", "Pine"); + + if (deciduous.contains(name)) { + return new Deciduous(name); + } else if (evergreen.contains(name)) { + return new Evergreen(name); + } else { + throw new RuntimeException("Tree could not be classified"); + } + } +} diff --git a/testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterAssertJUnitTest.java b/testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterAssertJUnitTest.java new file mode 100644 index 0000000000..74b0eec4d9 --- /dev/null +++ b/testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterAssertJUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.object.type; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class TreeSorterAssertJUnitTest { + private final TreeSorter tested = new TreeSorter(); + + @Test + public void sortTreeShouldReturnEvergreen_WhenPineIsPassed() { + Tree tree = tested.sortTree("Pine"); + assertThat(tree).isExactlyInstanceOf(Evergreen.class); + } + + @Test + public void sortTreeShouldReturnDecidious_WhenBirchIsPassed() { + Tree tree = tested.sortTree("Birch"); + assertThat(tree).hasSameClassAs(new Deciduous("Birch")); + } + +} \ No newline at end of file diff --git a/testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterHamcrestUnitTest.java b/testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterHamcrestUnitTest.java new file mode 100644 index 0000000000..7d35d5c0d0 --- /dev/null +++ b/testing-modules/testing-assertions/src/test/java/com/baeldung/object/type/TreeSorterHamcrestUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.object.type; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class TreeSorterHamcrestUnitTest { + private final TreeSorter tested = new TreeSorter(); + + @Test + public void sortTreeShouldReturnEvergreen_WhenPineIsPassed() { + Tree tree = tested.sortTree("Pine"); + //with JUnit assertEquals: + assertEquals(tree.getClass(), Evergreen.class); + //with Hamcrest instanceOf: + assertThat(tree, instanceOf(Evergreen.class)); + + } + + @Test + public void sortTreeShouldReturnDecidious_WhenBirchIsPassed() { + Tree tree = tested.sortTree("Birch"); + assertThat(tree, instanceOf(Deciduous.class)); + } + +} \ No newline at end of file From c5f676c6ccc9fb78245193555a0a024640e9aeb4 Mon Sep 17 00:00:00 2001 From: Mladen Savic Date: Mon, 8 Nov 2021 17:06:17 +0100 Subject: [PATCH 06/78] Spring Webflux and @Cacheable Annotation --- pom.xml | 3 + spring-webflux-caching/pom.xml | 67 +++++++++++++ .../main/java/com/baeldung/caching/Item.java | 50 ++++++++++ .../com/baeldung/caching/ItemRepository.java | 8 ++ .../com/baeldung/caching/ItemService.java | 42 ++++++++ .../SpringWebfluxCachingApplication.java | 16 ++++ .../src/main/resources/application.properties | 2 + .../MonoFluxResultCachingLiveTest.java | 95 +++++++++++++++++++ 8 files changed, 283 insertions(+) create mode 100644 spring-webflux-caching/pom.xml create mode 100644 spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java create mode 100644 spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java create mode 100644 spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java create mode 100644 spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java create mode 100644 spring-webflux-caching/src/main/resources/application.properties create mode 100644 spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java diff --git a/pom.xml b/pom.xml index f2a53f38b7..9a34ed0afe 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,9 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + + spring-webflux-caching + parent-modules pom diff --git a/spring-webflux-caching/pom.xml b/spring-webflux-caching/pom.xml new file mode 100644 index 0000000000..ed9800bce9 --- /dev/null +++ b/spring-webflux-caching/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + com.baeldung.spring + spring-webflux-caching + 1.0.0-SNAPSHOT + spring-webflux-caching + jar + Spring WebFlux Caching Sample + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-webflux + + + io.reactivex.rxjava2 + rxjava + 2.2.19 + + + io.projectreactor.addons + reactor-extra + 3.4.5 + + + com.github.ben-manes.caffeine + caffeine + 3.0.4 + + + org.springframework.boot + spring-boot-starter-data-mongodb-reactive + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + org.testcontainers + mongodb + 1.16.2 + test + + + + \ No newline at end of file diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java b/spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java new file mode 100644 index 0000000000..127975b0e7 --- /dev/null +++ b/spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java @@ -0,0 +1,50 @@ +package com.baeldung.caching; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document +public class Item { + + @Id + private String _id; + private String name; + private double price; + + public Item(String name, double price) { + this.name = name; + this.price = price; + } + + public Item() { + } + + public String get_id() { + return _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 "Item{" + + "id='" + _id + '\'' + + ", name='" + name + '\'' + + ", price=" + price + + '}'; + } +} diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java b/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java new file mode 100644 index 0000000000..a76489623e --- /dev/null +++ b/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.caching; + +import org.springframework.data.mongodb.repository.ReactiveMongoRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ItemRepository extends ReactiveMongoRepository { +} diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java b/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java new file mode 100644 index 0000000000..9dc9ba1642 --- /dev/null +++ b/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java @@ -0,0 +1,42 @@ +package com.baeldung.caching; + +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; +import reactor.cache.CacheMono; +import reactor.core.publisher.Mono; + +@Service +public class ItemService { + + private final ItemRepository repository; + private final LoadingCache cache; + + public ItemService(ItemRepository repository) { + this.repository = repository; + this.cache = Caffeine.newBuilder() + .build(this::getItem_withAddons); + } + + @Cacheable("items") + public Mono getItem(String id) { + return repository.findById(id); + } + + public Mono save(Item item) { + return repository.save(item); + } + + @Cacheable("items") + public Mono getItem_withCache(String id) { + return repository.findById(id).cache(); + } + + @Cacheable("items") + public Mono getItem_withAddons(String id) { + return CacheMono.lookup(cache.asMap(), id) + .onCacheMissResume(() -> repository.findById(id).cast(Object.class)).cast(Item.class); + } + +} diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java b/spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java new file mode 100644 index 0000000000..7331576bd5 --- /dev/null +++ b/spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java @@ -0,0 +1,16 @@ +package com.baeldung.caching; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; + +@SpringBootApplication +@EnableMongoRepositories +@EnableCaching +public class SpringWebfluxCachingApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringWebfluxCachingApplication.class, args); + } +} diff --git a/spring-webflux-caching/src/main/resources/application.properties b/spring-webflux-caching/src/main/resources/application.properties new file mode 100644 index 0000000000..23414da2dd --- /dev/null +++ b/spring-webflux-caching/src/main/resources/application.properties @@ -0,0 +1,2 @@ +logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG +logging.level.org.springframework.cache=TRACE \ No newline at end of file diff --git a/spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java b/spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java new file mode 100644 index 0000000000..bf96b35dcb --- /dev/null +++ b/spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java @@ -0,0 +1,95 @@ +package com.baeldung.caching; + + +import org.assertj.core.api.Assertions; +import org.junit.ClassRule; +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.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.utility.DockerImageName; +import reactor.core.publisher.Mono; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +public class MonoFluxResultCachingLiveTest { + + + @Autowired + ItemService itemService; + + final static MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")); + + @DynamicPropertySource + static void mongoDbProperties(DynamicPropertyRegistry registry) { + mongoDBContainer.start(); + registry.add("spring.data.mongodb.uri", mongoDBContainer::getReplicaSetUrl); + } + +@Test +public void givenItem_whenGetItemIsCalled_thenMonoIsCached() { + Mono glass = itemService.save(new Item("glass", 1.00)); + + String id = glass.block().get_id(); + + Mono mono = itemService.getItem(id); + Item item = mono.block(); + + assertThat(item).isNotNull(); + assertThat(item.getName()).isEqualTo("glass"); + assertThat(item.getPrice()).isEqualTo(1.00); + + Mono mono2 = itemService.getItem(id); + Item item2 = mono2.block(); + + assertThat(item2).isNotNull(); + assertThat(item2.getName()).isEqualTo("glass"); + assertThat(item2.getPrice()).isEqualTo(1.00); +} + + @Test + public void givenItem_whenGetItemWithCacheIsCalled_thenMonoResultIsCached() { + Mono glass = itemService.save(new Item("glass", 1.00)); + + String id = glass.block().get_id(); + + Mono mono = itemService.getItem_withCache(id); + Item item = mono.block(); + + assertThat(item).isNotNull(); + assertThat(item.getName()).isEqualTo("glass"); + assertThat(item.getPrice()).isEqualTo(1.00); + + Mono mono2 = itemService.getItem_withCache(id); + Item item2 = mono2.block(); + + assertThat(item2).isNotNull(); + assertThat(item2.getName()).isEqualTo("glass"); + assertThat(item2.getPrice()).isEqualTo(1.00); + } + + @Test + public void givenItem_whenGetItemWithAddonsIsCalled_thenMonoResultIsCached() { + Mono glass = itemService.save(new Item("glass", 1.00)); + + String id = glass.block().get_id(); + + Mono mono = itemService.getItem_withAddons(id); + Item item = mono.block(); + + assertThat(item).isNotNull(); + assertThat(item.getName()).isEqualTo("glass"); + assertThat(item.getPrice()).isEqualTo(1.00); + + Mono mono2 = itemService.getItem_withAddons(id); + Item item2 = mono2.block(); + + assertThat(item2).isNotNull(); + assertThat(item2.getName()).isEqualTo("glass"); + assertThat(item2.getPrice()).isEqualTo(1.00); + } + +} From 7aedcf0e3aa8cf032cec7e8e4b626d761dc37a0f Mon Sep 17 00:00:00 2001 From: sharifi Date: Tue, 9 Nov 2021 09:33:27 +0330 Subject: [PATCH 07/78] bael-4604: add data, key, algorithm, and hash value as local variable in each method --- .../com/baeldung/hmac/HMACUtilUnitTest.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java b/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java index 86e81f5895..0d7f97a094 100644 --- a/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java +++ b/core-java-modules/core-java-security-3/src/test/java/com/baeldung/hmac/HMACUtilUnitTest.java @@ -9,20 +9,16 @@ import static org.junit.Assert.assertEquals; public class HMACUtilUnitTest { - private static String hmacSHA256Value = "5b50d80c7dc7ae8bb1b1433cc0b99ecd2ac8397a555c6f75cb8a619ae35a0c35"; - private static String hmacMD5Value = "621dc816b3bf670212e0c261dc9bcdb6"; - private static String hmacSHA512Value = "b313a21908df55c9e322e3c65a4b0b7561ab1594ca806b3affbc0d769a1290c1922aa6622587bea3c0c4d871470a6d06f54dbd20dbda84250e2741eb01f08e33"; - - //given - String hmacSHA256Algorithm = "HmacSHA256"; - String hmacSHA512Algorithm = "HmacSHA512"; - String hmacMD5Algorithm = "HmacMD5"; - String data = "baeldung"; - String key = "123456"; - @Test public void givenDataAndKeyAndAlgorithm_whenHmacWithJava_thenSuccess() throws NoSuchAlgorithmException, InvalidKeyException { + + //given + String hmacSHA256Value = "5b50d80c7dc7ae8bb1b1433cc0b99ecd2ac8397a555c6f75cb8a619ae35a0c35"; + String hmacSHA256Algorithm = "HmacSHA256"; + String data = "baeldung"; + String key = "123456"; + //when String result = HMACUtil.hmacWithJava(hmacSHA256Algorithm, data, key); @@ -32,6 +28,13 @@ public class HMACUtilUnitTest { @Test public void givenDataAndKeyAndAlgorithm_whenHmacWithApacheCommons_thenSuccess() { + + //given + String hmacMD5Value = "621dc816b3bf670212e0c261dc9bcdb6"; + String hmacMD5Algorithm = "HmacMD5"; + String data = "baeldung"; + String key = "123456"; + //when String result = HMACUtil.hmacWithApacheCommons(hmacMD5Algorithm, data, key); @@ -41,6 +44,14 @@ public class HMACUtilUnitTest { @Test public void givenDataAndKeyAndAlgorithm_whenHmacWithBouncyCastle_thenSuccess() { + + //given + String hmacSHA512Value = "b313a21908df55c9e322e3c65a4b0b7561ab1594ca806b3affbc0d769a1" + + "290c1922aa6622587bea3c0c4d871470a6d06f54dbd20dbda84250e2741eb01f08e33"; + String hmacSHA512Algorithm = "HmacSHA512"; + String data = "baeldung"; + String key = "123456"; + //when String result = HMACUtil.hmacWithBouncyCastle(hmacSHA512Algorithm, data, key); From 124385e95225f64bf8edca3dc424c1800d99568c Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Mon, 8 Nov 2021 17:52:38 +0000 Subject: [PATCH 08/78] BAEL-5209 add to modules sdk9 and above --- pom.xml | 2 ++ testing-modules/pom.xml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f2a53f38b7..3b396bd2c5 100644 --- a/pom.xml +++ b/pom.xml @@ -1310,6 +1310,7 @@ persistence-modules/sirix quarkus-vs-springboot spring-boot-modules/spring-boot-cassandre + testing-modules/testing-assertions @@ -1362,6 +1363,7 @@ persistence-modules/sirix quarkus-vs-springboot spring-boot-modules/spring-boot-cassandre + testing-modules/testing-assertions diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index 079c7fa792..1e4ff246f9 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -42,7 +42,6 @@ spring-testing-2 spring-testing test-containers - testing-assertions testing-libraries-2 testing-libraries testng From f824a02eafbd03a8d203c29a88f940e7d6c7afc1 Mon Sep 17 00:00:00 2001 From: Mladen Savic Date: Thu, 11 Nov 2021 15:47:37 +0100 Subject: [PATCH 09/78] Spring Webflux and @Cacheable Annotation - moved to different module --- pom.xml | 3 - spring-5-webflux/pom.xml | 20 ++++++ .../com/baeldung/spring}/caching/Item.java | 2 +- .../spring}/caching/ItemRepository.java | 2 +- .../baeldung/spring}/caching/ItemService.java | 2 +- .../SpringWebfluxCachingApplication.java | 2 +- .../resources/application-cache.properties | 0 .../MonoFluxResultCachingLiveTest.java | 6 +- spring-webflux-caching/pom.xml | 67 ------------------- 9 files changed, 27 insertions(+), 77 deletions(-) rename {spring-webflux-caching/src/main/java/com/baeldung => spring-5-webflux/src/main/java/com/baeldung/spring}/caching/Item.java (96%) rename {spring-webflux-caching/src/main/java/com/baeldung => spring-5-webflux/src/main/java/com/baeldung/spring}/caching/ItemRepository.java (85%) rename {spring-webflux-caching/src/main/java/com/baeldung => spring-5-webflux/src/main/java/com/baeldung/spring}/caching/ItemService.java (96%) rename {spring-webflux-caching/src/main/java/com/baeldung => spring-5-webflux/src/main/java/com/baeldung/spring}/caching/SpringWebfluxCachingApplication.java (93%) rename spring-webflux-caching/src/main/resources/application.properties => spring-5-webflux/src/main/resources/application-cache.properties (100%) rename {spring-webflux-caching/src/test/java/com/baeldung => spring-5-webflux/src/test/java/com/baeldung/spring}/caching/MonoFluxResultCachingLiveTest.java (96%) delete mode 100644 spring-webflux-caching/pom.xml diff --git a/pom.xml b/pom.xml index 9a34ed0afe..f2a53f38b7 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - - spring-webflux-caching - parent-modules pom diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml index 69de83c227..cd3564d404 100644 --- a/spring-5-webflux/pom.xml +++ b/spring-5-webflux/pom.xml @@ -66,11 +66,31 @@ + + io.projectreactor.addons + reactor-extra + 3.4.5 + + + com.github.ben-manes.caffeine + caffeine + 3.0.4 + + + org.springframework.boot + spring-boot-starter-data-mongodb-reactive + io.projectreactor reactor-test test + + org.testcontainers + mongodb + 1.16.2 + test + com.squareup.okhttp3 mockwebserver diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/Item.java similarity index 96% rename from spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java rename to spring-5-webflux/src/main/java/com/baeldung/spring/caching/Item.java index 127975b0e7..7b79ff7503 100644 --- a/spring-webflux-caching/src/main/java/com/baeldung/caching/Item.java +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/Item.java @@ -1,4 +1,4 @@ -package com.baeldung.caching; +package com.baeldung.spring.caching; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/ItemRepository.java similarity index 85% rename from spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java rename to spring-5-webflux/src/main/java/com/baeldung/spring/caching/ItemRepository.java index a76489623e..27c97de36a 100644 --- a/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemRepository.java +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/ItemRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.caching; +package com.baeldung.spring.caching; import org.springframework.data.mongodb.repository.ReactiveMongoRepository; import org.springframework.stereotype.Repository; diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/ItemService.java similarity index 96% rename from spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java rename to spring-5-webflux/src/main/java/com/baeldung/spring/caching/ItemService.java index 9dc9ba1642..b24b54521e 100644 --- a/spring-webflux-caching/src/main/java/com/baeldung/caching/ItemService.java +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/ItemService.java @@ -1,4 +1,4 @@ -package com.baeldung.caching; +package com.baeldung.spring.caching; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; diff --git a/spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/SpringWebfluxCachingApplication.java similarity index 93% rename from spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java rename to spring-5-webflux/src/main/java/com/baeldung/spring/caching/SpringWebfluxCachingApplication.java index 7331576bd5..5266e33775 100644 --- a/spring-webflux-caching/src/main/java/com/baeldung/caching/SpringWebfluxCachingApplication.java +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/caching/SpringWebfluxCachingApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.caching; +package com.baeldung.spring.caching; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-webflux-caching/src/main/resources/application.properties b/spring-5-webflux/src/main/resources/application-cache.properties similarity index 100% rename from spring-webflux-caching/src/main/resources/application.properties rename to spring-5-webflux/src/main/resources/application-cache.properties diff --git a/spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/caching/MonoFluxResultCachingLiveTest.java similarity index 96% rename from spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java rename to spring-5-webflux/src/test/java/com/baeldung/spring/caching/MonoFluxResultCachingLiveTest.java index bf96b35dcb..322b3c5aa5 100644 --- a/spring-webflux-caching/src/test/java/com/baeldung/caching/MonoFluxResultCachingLiveTest.java +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/caching/MonoFluxResultCachingLiveTest.java @@ -1,11 +1,10 @@ -package com.baeldung.caching; +package com.baeldung.spring.caching; -import org.assertj.core.api.Assertions; -import org.junit.ClassRule; 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.MongoDBContainer; @@ -15,6 +14,7 @@ import reactor.core.publisher.Mono; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest +@ActiveProfiles("cache") public class MonoFluxResultCachingLiveTest { diff --git a/spring-webflux-caching/pom.xml b/spring-webflux-caching/pom.xml deleted file mode 100644 index ed9800bce9..0000000000 --- a/spring-webflux-caching/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - 4.0.0 - com.baeldung.spring - spring-webflux-caching - 1.0.0-SNAPSHOT - spring-webflux-caching - jar - Spring WebFlux Caching Sample - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - - - org.springframework.boot - spring-boot-starter-webflux - - - io.reactivex.rxjava2 - rxjava - 2.2.19 - - - io.projectreactor.addons - reactor-extra - 3.4.5 - - - com.github.ben-manes.caffeine - caffeine - 3.0.4 - - - org.springframework.boot - spring-boot-starter-data-mongodb-reactive - - - com.fasterxml.jackson.core - jackson-databind - - - org.springframework.boot - spring-boot-starter-test - test - - - io.projectreactor - reactor-test - test - - - org.testcontainers - mongodb - 1.16.2 - test - - - - \ No newline at end of file From 6367e31787a612de7e48cb39f1b8a0bc524214b7 Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 13 Nov 2021 21:22:34 +0100 Subject: [PATCH 10/78] JAVA-8279 Split or move core java module --- .../core-java-serialization/README.md | 9 + .../core-java-serialization/pom.xml | 194 ++++++++++++++++++ .../deserialization/AppleProduct.java | 0 .../deserialization/DefaultSerial.java | 0 .../DeserializationUtility.java | 0 .../deserialization/SerializationUtility.java | 0 .../baeldung/externalizable/Community.java | 0 .../com/baeldung/externalizable/Country.java | 0 .../com/baeldung/externalizable/Region.java | 0 .../com/baeldung/serialization/Address.java | 0 .../com/baeldung/serialization/Employee.java | 0 .../com/baeldung/serialization/Person.java | 0 .../baeldung/util/MySerializationUtils.java | 0 .../src/main/resources/log4j.properties | 6 + .../src/main/resources/log4j2.xml | 13 ++ .../resources/log4jstructuraldp.properties | 9 + .../src/main/resources/logback.xml | 19 ++ .../DeserializationUnitTest.java | 5 +- .../serialization/PersonUnitTest.java | 0 .../serialization/SerializationUnitTest.java | 0 .../src/test/resources/log4j.properties | 6 + .../src/test/resources/log4j2.xml | 13 ++ .../resources/log4jstructuraldp.properties | 9 + .../src/test/resources/logback.xml | 19 ++ core-java-modules/core-java-uuid/README.md | 5 + core-java-modules/core-java-uuid/pom.xml | 156 ++++++++++++++ .../java/com/baeldung/uuid/UUIDGenerator.java | 0 .../src/main/resources/log4j.properties | 6 + .../src/main/resources/log4j2.xml | 13 ++ .../resources/log4jstructuraldp.properties | 9 + .../src/main/resources/logback.xml | 19 ++ .../baeldung/uuid/UUIDGeneratorUnitTest.java | 0 .../src/test/resources/log4j.properties | 6 + .../src/test/resources/log4j2.xml | 13 ++ .../resources/log4jstructuraldp.properties | 9 + .../src/test/resources/logback.xml | 19 ++ core-java-modules/core-java/README.md | 7 - .../ExternalizableUnitTest.java | 71 ------- core-java-modules/pom.xml | 2 + pom.xml | 3 + 40 files changed, 560 insertions(+), 80 deletions(-) create mode 100644 core-java-modules/core-java-serialization/README.md create mode 100644 core-java-modules/core-java-serialization/pom.xml rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/deserialization/AppleProduct.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/deserialization/DefaultSerial.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/deserialization/DeserializationUtility.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/deserialization/SerializationUtility.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/externalizable/Community.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/externalizable/Country.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/externalizable/Region.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/serialization/Address.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/serialization/Employee.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/serialization/Person.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/main/java/com/baeldung/util/MySerializationUtils.java (100%) create mode 100644 core-java-modules/core-java-serialization/src/main/resources/log4j.properties create mode 100644 core-java-modules/core-java-serialization/src/main/resources/log4j2.xml create mode 100644 core-java-modules/core-java-serialization/src/main/resources/log4jstructuraldp.properties create mode 100644 core-java-modules/core-java-serialization/src/main/resources/logback.xml rename core-java-modules/{core-java => core-java-serialization}/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java (92%) rename core-java-modules/{core-java => core-java-serialization}/src/test/java/com/baeldung/serialization/PersonUnitTest.java (100%) rename core-java-modules/{core-java => core-java-serialization}/src/test/java/com/baeldung/serialization/SerializationUnitTest.java (100%) create mode 100644 core-java-modules/core-java-serialization/src/test/resources/log4j.properties create mode 100644 core-java-modules/core-java-serialization/src/test/resources/log4j2.xml create mode 100644 core-java-modules/core-java-serialization/src/test/resources/log4jstructuraldp.properties create mode 100644 core-java-modules/core-java-serialization/src/test/resources/logback.xml create mode 100644 core-java-modules/core-java-uuid/README.md create mode 100644 core-java-modules/core-java-uuid/pom.xml rename core-java-modules/{core-java => core-java-uuid}/src/main/java/com/baeldung/uuid/UUIDGenerator.java (100%) create mode 100644 core-java-modules/core-java-uuid/src/main/resources/log4j.properties create mode 100644 core-java-modules/core-java-uuid/src/main/resources/log4j2.xml create mode 100644 core-java-modules/core-java-uuid/src/main/resources/log4jstructuraldp.properties create mode 100644 core-java-modules/core-java-uuid/src/main/resources/logback.xml rename core-java-modules/{core-java => core-java-uuid}/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java (100%) create mode 100644 core-java-modules/core-java-uuid/src/test/resources/log4j.properties create mode 100644 core-java-modules/core-java-uuid/src/test/resources/log4j2.xml create mode 100644 core-java-modules/core-java-uuid/src/test/resources/log4jstructuraldp.properties create mode 100644 core-java-modules/core-java-uuid/src/test/resources/logback.xml delete mode 100644 core-java-modules/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java diff --git a/core-java-modules/core-java-serialization/README.md b/core-java-modules/core-java-serialization/README.md new file mode 100644 index 0000000000..fc6cfcf134 --- /dev/null +++ b/core-java-modules/core-java-serialization/README.md @@ -0,0 +1,9 @@ +## Core Java Serialization + +### Relevant Articles: + +- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) +- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) +- [Deserialization Vulnerabilities in Java](https://www.baeldung.com/java-deserialization-vulnerabilities) +- [Serialization Validation in Java](https://www.baeldung.com/java-validate-serializable) +- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml new file mode 100644 index 0000000000..74a78e8b48 --- /dev/null +++ b/core-java-modules/core-java-serialization/pom.xml @@ -0,0 +1,194 @@ + + + 4.0.0 + core-java-serialization + 0.1.0-SNAPSHOT + core-java-serialization + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + org.unix4j + unix4j-command + ${unix4j.version} + + + com.googlecode.grep4j + grep4j + ${grep4j.version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + org.springframework + spring-core + ${spring.core.version} + + + org.springframework + spring-core + 4.3.20.RELEASE + test + + + + + core-java + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + + + org.codehaus.mojo + exec-maven-plugin + + java + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + -Xmx300m + -XX:+UseParallelGC + -classpath + + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + ${source.version} + ${target.version} + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + + + + + org.codehaus.mojo + exec-maven-plugin + + + run-benchmarks + + none + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + + + + + + + + + + + + + 0.4 + 1.8.7 + + 3.10.0 + + 1.1 + 3.0.0-M1 + 1.8 + 1.8 + 4.3.20.RELEASE + + + \ No newline at end of file diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/AppleProduct.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/AppleProduct.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/deserialization/AppleProduct.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/AppleProduct.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/DefaultSerial.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/DefaultSerial.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DeserializationUtility.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/DeserializationUtility.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DeserializationUtility.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/DeserializationUtility.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/SerializationUtility.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/SerializationUtility.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/deserialization/SerializationUtility.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/deserialization/SerializationUtility.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Community.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/externalizable/Community.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Community.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/externalizable/Community.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Country.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/externalizable/Country.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Country.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/externalizable/Country.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Region.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/externalizable/Region.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/externalizable/Region.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/externalizable/Region.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/serialization/Address.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/serialization/Address.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/serialization/Address.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/serialization/Address.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/serialization/Employee.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/serialization/Employee.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/serialization/Employee.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/serialization/Employee.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/serialization/Person.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/serialization/Person.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/serialization/Person.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/serialization/Person.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/util/MySerializationUtils.java b/core-java-modules/core-java-serialization/src/main/java/com/baeldung/util/MySerializationUtils.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/util/MySerializationUtils.java rename to core-java-modules/core-java-serialization/src/main/java/com/baeldung/util/MySerializationUtils.java diff --git a/core-java-modules/core-java-serialization/src/main/resources/log4j.properties b/core-java-modules/core-java-serialization/src/main/resources/log4j.properties new file mode 100644 index 0000000000..621cf01735 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/main/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=DEBUG, A1 + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/src/main/resources/log4j2.xml b/core-java-modules/core-java-serialization/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..a824bef9b0 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/src/main/resources/log4jstructuraldp.properties b/core-java-modules/core-java-serialization/src/main/resources/log4jstructuraldp.properties new file mode 100644 index 0000000000..5bc2bfe4b9 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/main/resources/log4jstructuraldp.properties @@ -0,0 +1,9 @@ + +# Root logger +log4j.rootLogger=INFO, file, stdout + +# Write to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/src/main/resources/logback.xml b/core-java-modules/core-java-serialization/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/core-java-modules/core-java-serialization/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java similarity index 92% rename from core-java-modules/core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java rename to core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java index d7c1ee17d4..cc45cbc8e0 100644 --- a/core-java-modules/core-java/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java +++ b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InvalidClassException; +import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -24,7 +25,7 @@ public class DeserializationUnitTest { @Test public void testDeserializeObj_compatible() throws IOException, ClassNotFoundException { - assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); + Assert.assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); AppleProduct macBook = new AppleProduct(); macBook.headphonePort = "headphonePort2020"; @@ -60,7 +61,7 @@ public class DeserializationUnitTest { @Test(expected = InvalidClassException.class) public void testDeserializeObj_incompatible() throws ClassNotFoundException, IOException { - assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); + Assert.assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); // attempts to deserialize the "AppleProduct" object DeserializationUtility.deSerializeObjectFromString(serializedObj); } diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/serialization/PersonUnitTest.java b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/serialization/PersonUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/serialization/PersonUnitTest.java rename to core-java-modules/core-java-serialization/src/test/java/com/baeldung/serialization/PersonUnitTest.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/serialization/SerializationUnitTest.java b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/serialization/SerializationUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/serialization/SerializationUnitTest.java rename to core-java-modules/core-java-serialization/src/test/java/com/baeldung/serialization/SerializationUnitTest.java diff --git a/core-java-modules/core-java-serialization/src/test/resources/log4j.properties b/core-java-modules/core-java-serialization/src/test/resources/log4j.properties new file mode 100644 index 0000000000..621cf01735 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/test/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=DEBUG, A1 + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/src/test/resources/log4j2.xml b/core-java-modules/core-java-serialization/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..a824bef9b0 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/src/test/resources/log4jstructuraldp.properties b/core-java-modules/core-java-serialization/src/test/resources/log4jstructuraldp.properties new file mode 100644 index 0000000000..5bc2bfe4b9 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/test/resources/log4jstructuraldp.properties @@ -0,0 +1,9 @@ + +# Root logger +log4j.rootLogger=INFO, file, stdout + +# Write to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/src/test/resources/logback.xml b/core-java-modules/core-java-serialization/src/test/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/core-java-modules/core-java-serialization/src/test/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/README.md b/core-java-modules/core-java-uuid/README.md new file mode 100644 index 0000000000..836552d798 --- /dev/null +++ b/core-java-modules/core-java-uuid/README.md @@ -0,0 +1,5 @@ +## Core Java UUID + +### Relevant Articles: +- [Generating Alphanumeric UUID String in Java](https://www.baeldung.com/java-generate-alphanumeric-uuid) +- [Guide to UUID in Java](http://www.baeldung.com/java-uuid) diff --git a/core-java-modules/core-java-uuid/pom.xml b/core-java-modules/core-java-uuid/pom.xml new file mode 100644 index 0000000000..fba36ada8e --- /dev/null +++ b/core-java-modules/core-java-uuid/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + core-java-uuid + 0.1.0-SNAPSHOT + core-java-uuid + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + log4j + log4j + ${log4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + + + core-java-uuid + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + + + org.codehaus.mojo + exec-maven-plugin + + java + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + -Xmx300m + -XX:+UseParallelGC + -classpath + + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + ${source.version} + ${target.version} + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + + + + + org.codehaus.mojo + exec-maven-plugin + + + run-benchmarks + + none + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + + + + + + + + + + + + 3.10.0 + 3.0.0-M1 + 1.8 + 1.8 + + + \ No newline at end of file diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java b/core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDGenerator.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java rename to core-java-modules/core-java-uuid/src/main/java/com/baeldung/uuid/UUIDGenerator.java diff --git a/core-java-modules/core-java-uuid/src/main/resources/log4j.properties b/core-java-modules/core-java-uuid/src/main/resources/log4j.properties new file mode 100644 index 0000000000..621cf01735 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/main/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=DEBUG, A1 + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/src/main/resources/log4j2.xml b/core-java-modules/core-java-uuid/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..a824bef9b0 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/src/main/resources/log4jstructuraldp.properties b/core-java-modules/core-java-uuid/src/main/resources/log4jstructuraldp.properties new file mode 100644 index 0000000000..5bc2bfe4b9 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/main/resources/log4jstructuraldp.properties @@ -0,0 +1,9 @@ + +# Root logger +log4j.rootLogger=INFO, file, stdout + +# Write to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/src/main/resources/logback.xml b/core-java-modules/core-java-uuid/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/core-java-modules/core-java-uuid/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java rename to core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java diff --git a/core-java-modules/core-java-uuid/src/test/resources/log4j.properties b/core-java-modules/core-java-uuid/src/test/resources/log4j.properties new file mode 100644 index 0000000000..621cf01735 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/test/resources/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=DEBUG, A1 + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/src/test/resources/log4j2.xml b/core-java-modules/core-java-uuid/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..a824bef9b0 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/src/test/resources/log4jstructuraldp.properties b/core-java-modules/core-java-uuid/src/test/resources/log4jstructuraldp.properties new file mode 100644 index 0000000000..5bc2bfe4b9 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/test/resources/log4jstructuraldp.properties @@ -0,0 +1,9 @@ + +# Root logger +log4j.rootLogger=INFO, file, stdout + +# Write to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/core-java-modules/core-java-uuid/src/test/resources/logback.xml b/core-java-modules/core-java-uuid/src/test/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/core-java-modules/core-java-uuid/src/test/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java/README.md b/core-java-modules/core-java/README.md index 3285a7e663..a75805e0c2 100644 --- a/core-java-modules/core-java/README.md +++ b/core-java-modules/core-java/README.md @@ -3,14 +3,7 @@ ### Relevant Articles: - [Getting Started with Java Properties](http://www.baeldung.com/java-properties) - [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) -- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) -- [Guide to UUID in Java](http://www.baeldung.com/java-uuid) - [Compiling Java *.class Files with javac](http://www.baeldung.com/javac) - [Introduction to Javadoc](http://www.baeldung.com/javadoc) -- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) -- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) - [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) - [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) -- [Deserialization Vulnerabilities in Java](https://www.baeldung.com/java-deserialization-vulnerabilities) -- [Generating Alphanumeric UUID String in Java](https://www.baeldung.com/java-generate-alphanumeric-uuid) -- [Serialization Validation in Java](https://www.baeldung.com/java-validate-serializable) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java deleted file mode 100644 index 651364fb13..0000000000 --- a/core-java-modules/core-java/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.externalizable; - -import org.junit.Test; - -import java.io.*; - -import static org.junit.Assert.assertTrue; - -public class ExternalizableUnitTest { - - private final static String OUTPUT_FILE = "externalizable.txt"; - - @Test - public void whenSerializing_thenUseExternalizable() throws IOException, ClassNotFoundException { - - Country c = new Country(); - c.setCapital("Yerevan"); - c.setCode(374); - c.setName("Armenia"); - - FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE); - ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); - c.writeExternal(objectOutputStream); - - objectOutputStream.flush(); - objectOutputStream.close(); - fileOutputStream.close(); - - FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE); - ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); - - Country c2 = new Country(); - c2.readExternal(objectInputStream); - - objectInputStream.close(); - fileInputStream.close(); - - assertTrue(c2.getCode() == c.getCode()); - assertTrue(c2.getName().equals(c.getName())); - } - - @Test - public void whenInheritanceSerialization_then_UseExternalizable() throws IOException, ClassNotFoundException { - - Region r = new Region(); - r.setCapital("Yerevan"); - r.setCode(374); - r.setName("Armenia"); - r.setClimate("Mediterranean"); - r.setPopulation(120.000); - - FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE); - ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); - r.writeExternal(objectOutputStream); - - objectOutputStream.flush(); - objectOutputStream.close(); - fileOutputStream.close(); - - FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE); - ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); - - Region r2 = new Region(); - r2.readExternal(objectInputStream); - - objectInputStream.close(); - fileInputStream.close(); - - assertTrue(r2.getPopulation() == null); - } -} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index c3d17e7637..d8191e74d0 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -100,6 +100,7 @@ core-java-security core-java-security-2 core-java-security-3 + core-java-serialization core-java-streams core-java-streams-2 core-java-streams-3 @@ -115,6 +116,7 @@ core-java-sun core-java-regex core-java-regex-2 + core-java-uuid pre-jpms diff --git a/pom.xml b/pom.xml index 372bc5a9f3..4af2e422f4 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,9 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + + core-java-uuid + parent-modules pom From adce68ae25a0cb677cf7b99a2270331a8d420cbe Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 13 Nov 2021 21:31:25 +0100 Subject: [PATCH 11/78] JAVA-8279 Split or move core java module (remove wrong module in main pom) --- pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4af2e422f4..372bc5a9f3 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - - core-java-uuid - parent-modules pom From 9798b291430a42f0980ea1d045e9cf4cdad9ba8e Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 14 Nov 2021 11:08:17 +0100 Subject: [PATCH 12/78] JAVA-8286 Split or move spring boot runtime module --- spring-boot-modules/spring-boot-runtime-2/README.md | 2 ++ spring-boot-modules/spring-boot-runtime-2/pom.xml | 4 ++++ .../src/main/java/com/baeldung/cors/Account.java | 0 .../src/main/java/com/baeldung/cors/AccountController.java | 0 .../src/main/java/com/baeldung/cors/config/WebConfig.java | 0 .../maxhttpheadersize/MaxHttpHeaderSizeApplication.java | 0 .../maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java | 0 .../controller/MaxHttpHeaderSizeController.java | 0 .../MaxHttpHeaderSizeControllerIntegrationTest.java | 0 .../controller/MaxHttpHeaderSizeControllerLiveTest.java | 0 spring-boot-modules/spring-boot-runtime/README.md | 2 -- 11 files changed, 6 insertions(+), 2 deletions(-) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/main/java/com/baeldung/cors/Account.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/main/java/com/baeldung/cors/AccountController.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/main/java/com/baeldung/cors/config/WebConfig.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java (100%) rename spring-boot-modules/{spring-boot-runtime => spring-boot-runtime-2}/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java (100%) diff --git a/spring-boot-modules/spring-boot-runtime-2/README.md b/spring-boot-modules/spring-boot-runtime-2/README.md index 9f0d814d8d..f439b0d0bd 100644 --- a/spring-boot-modules/spring-boot-runtime-2/README.md +++ b/spring-boot-modules/spring-boot-runtime-2/README.md @@ -4,3 +4,5 @@ This module contains articles about administering a Spring Boot runtime ### Relevant Articles: - [Configure the Heap Size When Starting a Spring Boot Application](https://www.baeldung.com/spring-boot-heap-size) + - [CORS with Spring](https://www.baeldung.com/spring-cors) + - [Max-HTTP-Header-Size in Spring Boot 2](https://www.baeldung.com/spring-boot-max-http-header-size) diff --git a/spring-boot-modules/spring-boot-runtime-2/pom.xml b/spring-boot-modules/spring-boot-runtime-2/pom.xml index c177529a41..62c43d20f0 100644 --- a/spring-boot-modules/spring-boot-runtime-2/pom.xml +++ b/spring-boot-modules/spring-boot-runtime-2/pom.xml @@ -25,6 +25,10 @@ spring-boot-starter-test test + + org.springframework.security + spring-security-test + diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/cors/Account.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/cors/Account.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/cors/Account.java rename to spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/cors/Account.java diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/cors/AccountController.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/cors/AccountController.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/cors/AccountController.java rename to spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/cors/AccountController.java diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/cors/config/WebConfig.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/cors/config/WebConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/cors/config/WebConfig.java rename to spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/cors/config/WebConfig.java diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java rename to spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/maxhttpheadersize/MaxHttpHeaderSizeApplication.java diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java rename to spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/maxhttpheadersize/config/MaxHTTPHeaderSizeConfig.java diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java b/spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java rename to spring-boot-modules/spring-boot-runtime-2/src/main/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeController.java diff --git a/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java b/spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java rename to spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java b/spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java similarity index 100% rename from spring-boot-modules/spring-boot-runtime/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java rename to spring-boot-modules/spring-boot-runtime-2/src/test/java/com/baeldung/maxhttpheadersize/controller/MaxHttpHeaderSizeControllerLiveTest.java diff --git a/spring-boot-modules/spring-boot-runtime/README.md b/spring-boot-modules/spring-boot-runtime/README.md index 072bd16a78..6f21efe793 100644 --- a/spring-boot-modules/spring-boot-runtime/README.md +++ b/spring-boot-modules/spring-boot-runtime/README.md @@ -8,7 +8,5 @@ This module contains articles about administering a Spring Boot runtime - [Logging HTTP Requests with Spring Boot Actuator HTTP Tracing](https://www.baeldung.com/spring-boot-actuator-http) - [Spring Boot Embedded Tomcat Logs](https://www.baeldung.com/spring-boot-embedded-tomcat-logs) - [Project Configuration with Spring](https://www.baeldung.com/project-configuration-with-spring) - - [CORS with Spring](https://www.baeldung.com/spring-cors) - [Spring – Log Incoming Requests](https://www.baeldung.com/spring-http-logging) - [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat) - - [Max-HTTP-Header-Size in Spring Boot 2](https://www.baeldung.com/spring-boot-max-http-header-size) From 508dff5f69474b40a8bbaa2caa0c94714b31077b Mon Sep 17 00:00:00 2001 From: Mladen Savic Date: Sun, 14 Nov 2021 14:13:47 +0100 Subject: [PATCH 13/78] Spring Webflux and @Cacheable Annotation - reverted to older version of caffeine for jdk compatibility --- spring-5-webflux/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml index cd3564d404..d6afb686fc 100644 --- a/spring-5-webflux/pom.xml +++ b/spring-5-webflux/pom.xml @@ -74,7 +74,7 @@ com.github.ben-manes.caffeine caffeine - 3.0.4 + 2.9.2 org.springframework.boot From 26d1bf5d5890013c9c92bbcd1dcdf447a606a85c Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 14 Nov 2021 22:51:58 +0100 Subject: [PATCH 14/78] JAVA-8293 Split or move spring boot module --- spring-boot-modules/spring-boot-1/README.md | 5 ++++ spring-boot-modules/spring-boot-1/pom.xml | 23 +++++++++++++++++++ .../dynamicvalidation/ContactInfo.java | 0 .../ContactInfoValidator.java | 0 .../DynamicValidationApp.java | 0 .../config/CustomerController.java | 0 .../config/PersistenceConfig.java | 0 .../dao/ContactInfoExpressionRepository.java | 0 .../model/ContactInfoExpression.java | 0 .../dynamicvalidation/model/Customer.java | 0 .../WarInitializerApplication.java | 3 ++- .../ShutdownHookApplication.java | 0 .../baeldung/shutdownhooks/beans/Bean1.java | 0 .../baeldung/shutdownhooks/beans/Bean2.java | 0 .../baeldung/shutdownhooks/beans/Bean3.java | 0 .../config/ExampleServletContextListener.java | 0 .../config/ShutdownHookConfiguration.java | 0 ...InitializerApplicationIntegrationTest.java | 0 .../src/test/resources/application.properties | 20 ++++++++++++++++ spring-boot-modules/spring-boot/README.md | 7 ++---- 20 files changed, 52 insertions(+), 6 deletions(-) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/ContactInfo.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/dao/ContactInfoExpressionRepository.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/model/ContactInfoExpression.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java (88%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java (100%) rename spring-boot-modules/{spring-boot => spring-boot-1}/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java (100%) create mode 100644 spring-boot-modules/spring-boot-1/src/test/resources/application.properties diff --git a/spring-boot-modules/spring-boot-1/README.md b/spring-boot-modules/spring-boot-1/README.md index a818f60fb5..8e5214c69a 100644 --- a/spring-boot-modules/spring-boot-1/README.md +++ b/spring-boot-modules/spring-boot-1/README.md @@ -4,3 +4,8 @@ This module contains articles about Spring Boot Actuator in Spring Boot version ## Relevant articles: - [Spring Boot Actuator](https://www.baeldung.com/spring-boot-actuators) +- [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) +- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) +- [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation) + + diff --git a/spring-boot-modules/spring-boot-1/pom.xml b/spring-boot-modules/spring-boot-1/pom.xml index 9f91cc8f2e..82a1a38397 100644 --- a/spring-boot-modules/spring-boot-1/pom.xml +++ b/spring-boot-modules/spring-boot-1/pom.xml @@ -20,14 +20,36 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-thymeleaf + org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-tomcat + org.springframework.boot spring-boot-starter-actuator + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.apache.logging.log4j + log4j-core + 2.14.1 + + + com.h2database + h2 + test + org.springframework.boot spring-boot-starter-test @@ -40,6 +62,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot.version} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfo.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/ContactInfo.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfo.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/ContactInfo.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/dao/ContactInfoExpressionRepository.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/dao/ContactInfoExpressionRepository.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/dao/ContactInfoExpressionRepository.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/dao/ContactInfoExpressionRepository.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/ContactInfoExpression.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/model/ContactInfoExpression.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/ContactInfoExpression.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/model/ContactInfoExpression.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java similarity index 88% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java index 5b9ce1271e..3b360b4adc 100644 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java +++ b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java @@ -5,7 +5,8 @@ import java.time.LocalDateTime; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +//import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java similarity index 100% rename from spring-boot-modules/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java rename to spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java rename to spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-1/src/test/resources/application.properties b/spring-boot-modules/spring-boot-1/src/test/resources/application.properties new file mode 100644 index 0000000000..b14abfcc81 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/resources/application.properties @@ -0,0 +1,20 @@ +spring.mail.host=localhost +spring.mail.port=8025 +spring.mail.properties.mail.smtp.auth=false + +# spring.datasource.x +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +spring.datasource.username=sa +spring.datasource.password=sa + +# hibernate.X +spring.jpa.hibernate.dialect=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.show_sql=true +spring.jpa.hibernate.hbm2ddl.auto=create-drop +spring.jpa.hibernate.cache.use_second_level_cache=true +spring.jpa.hibernate.cache.use_query_cache=true +spring.jpa.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory + +management.security.enabled=false \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/README.md b/spring-boot-modules/spring-boot/README.md index 5a45502fd8..fdc8093806 100644 --- a/spring-boot-modules/spring-boot/README.md +++ b/spring-boot-modules/spring-boot/README.md @@ -8,12 +8,9 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [A Guide to Spring in Eclipse STS](https://www.baeldung.com/eclipse-sts-spring) -- [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) -- [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) -- [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation) - [Guide to Spring Type Conversions](https://www.baeldung.com/spring-type-conversions) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) -- [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) -- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) - [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) +- [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) +- [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) From 1027a6d76db60f3dce31334cfb07a9f2a45f446f Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 14 Nov 2021 23:02:03 +0100 Subject: [PATCH 15/78] JAVA-8279 Split or move Java core module (fix review comments) --- .../core-java-serialization/pom.xml | 5 +- .../DeserializationUnitTest.java | 4 +- .../ExternalizableUnitTest.java | 71 +++++++++++++++++++ core-java-modules/core-java-uuid/pom.xml | 2 - 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 core-java-modules/core-java-serialization/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml index 74a78e8b48..8fcebca356 100644 --- a/core-java-modules/core-java-serialization/pom.xml +++ b/core-java-modules/core-java-serialization/pom.xml @@ -12,7 +12,6 @@ com.baeldung.core-java-modules core-java-modules 0.0.1-SNAPSHOT - ../ @@ -186,8 +185,8 @@ 1.1 3.0.0-M1 - 1.8 - 1.8 + + 4.3.20.RELEASE diff --git a/core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java index cc45cbc8e0..89a603a298 100644 --- a/core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java +++ b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java @@ -25,7 +25,7 @@ public class DeserializationUnitTest { @Test public void testDeserializeObj_compatible() throws IOException, ClassNotFoundException { - Assert.assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); + assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); AppleProduct macBook = new AppleProduct(); macBook.headphonePort = "headphonePort2020"; @@ -61,7 +61,7 @@ public class DeserializationUnitTest { @Test(expected = InvalidClassException.class) public void testDeserializeObj_incompatible() throws ClassNotFoundException, IOException { - Assert.assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); + assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID()); // attempts to deserialize the "AppleProduct" object DeserializationUtility.deSerializeObjectFromString(serializedObj); } diff --git a/core-java-modules/core-java-serialization/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java new file mode 100644 index 0000000000..651364fb13 --- /dev/null +++ b/core-java-modules/core-java-serialization/src/test/java/com/baeldung/externalizable/ExternalizableUnitTest.java @@ -0,0 +1,71 @@ +package com.baeldung.externalizable; + +import org.junit.Test; + +import java.io.*; + +import static org.junit.Assert.assertTrue; + +public class ExternalizableUnitTest { + + private final static String OUTPUT_FILE = "externalizable.txt"; + + @Test + public void whenSerializing_thenUseExternalizable() throws IOException, ClassNotFoundException { + + Country c = new Country(); + c.setCapital("Yerevan"); + c.setCode(374); + c.setName("Armenia"); + + FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); + c.writeExternal(objectOutputStream); + + objectOutputStream.flush(); + objectOutputStream.close(); + fileOutputStream.close(); + + FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE); + ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); + + Country c2 = new Country(); + c2.readExternal(objectInputStream); + + objectInputStream.close(); + fileInputStream.close(); + + assertTrue(c2.getCode() == c.getCode()); + assertTrue(c2.getName().equals(c.getName())); + } + + @Test + public void whenInheritanceSerialization_then_UseExternalizable() throws IOException, ClassNotFoundException { + + Region r = new Region(); + r.setCapital("Yerevan"); + r.setCode(374); + r.setName("Armenia"); + r.setClimate("Mediterranean"); + r.setPopulation(120.000); + + FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); + r.writeExternal(objectOutputStream); + + objectOutputStream.flush(); + objectOutputStream.close(); + fileOutputStream.close(); + + FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE); + ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); + + Region r2 = new Region(); + r2.readExternal(objectInputStream); + + objectInputStream.close(); + fileInputStream.close(); + + assertTrue(r2.getPopulation() == null); + } +} diff --git a/core-java-modules/core-java-uuid/pom.xml b/core-java-modules/core-java-uuid/pom.xml index fba36ada8e..a38306f269 100644 --- a/core-java-modules/core-java-uuid/pom.xml +++ b/core-java-modules/core-java-uuid/pom.xml @@ -149,8 +149,6 @@ 3.10.0 3.0.0-M1 - 1.8 - 1.8 \ No newline at end of file From c05d21519cd5ef5c9ddd0407ad2099e5bec72d89 Mon Sep 17 00:00:00 2001 From: Willian Nalepa Oizumi Date: Mon, 15 Nov 2021 10:15:35 -0300 Subject: [PATCH 16/78] BAEL-5196 - Split a comma-separated string while ignoring commas in quotes (#11432) * Creating the module 'core-java-string-operations-4' for new string related code samples. Implemented code samples for the article BAEL-5196 * including new module 'core-java-string-operations-4 in the parent project * fixing spacing in the pom file * fixing the maven configuration for our new project core-java-string-operations-4 --- .../core-java-string-operations-4/README.md | 3 + .../core-java-string-operations-4/pom.xml | 58 ++++++++++++++++ .../SplitCommaSeparatedString.java | 66 +++++++++++++++++++ .../SplitCommaSeparatedStringUnitTest.java | 44 +++++++++++++ pom.xml | 1 + 5 files changed, 172 insertions(+) create mode 100644 core-java-modules/core-java-string-operations-4/README.md create mode 100644 core-java-modules/core-java-string-operations-4/pom.xml create mode 100644 core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedString.java create mode 100644 core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedStringUnitTest.java diff --git a/core-java-modules/core-java-string-operations-4/README.md b/core-java-modules/core-java-string-operations-4/README.md new file mode 100644 index 0000000000..88d562204b --- /dev/null +++ b/core-java-modules/core-java-string-operations-4/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + + diff --git a/core-java-modules/core-java-string-operations-4/pom.xml b/core-java-modules/core-java-string-operations-4/pom.xml new file mode 100644 index 0000000000..ea6bdcd849 --- /dev/null +++ b/core-java-modules/core-java-string-operations-4/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + core-java-string-operations-4 + 0.1.0-SNAPSHOT + core-java-string-operations-4 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + org.assertj + assertj-core + ${assertj.version} + test + + + com.google.guava + guava + ${guava.version} + + + com.opencsv + opencsv + ${opencsv.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + 11 + 11 + 3.6.1 + 31.0.1-jre + 4.1 + + + diff --git a/core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedString.java b/core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedString.java new file mode 100644 index 0000000000..c3bbdb4dfb --- /dev/null +++ b/core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedString.java @@ -0,0 +1,66 @@ +package com.baeldung.commaseparatedstring; + +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import com.google.common.base.Splitter; +import com.opencsv.CSVParser; +import com.opencsv.CSVParserBuilder; +import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; + +public class SplitCommaSeparatedString { + + public static List splitWithParser(String input) { + + List tokens = new ArrayList(); + int startPosition = 0; + boolean isInQuotes = false; + for (int currentPosition = 0; currentPosition < input.length(); currentPosition++) { + if (input.charAt(currentPosition) == '\"') { + isInQuotes = !isInQuotes; + } else if (input.charAt(currentPosition) == ',' && !isInQuotes) { + tokens.add(input.substring(startPosition, currentPosition)); + startPosition = currentPosition + 1; + } + } + + String lastToken = input.substring(startPosition); + if (lastToken.equals(",")) { + tokens.add(""); + } else { + tokens.add(lastToken); + } + + return tokens; + } + + public static List splitWithRegex(String input) { + String[] tokens = input.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1); + return Arrays.asList(tokens); + } + + public static List splitWithGuava(String input) { + Pattern pattern = Pattern.compile(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + Splitter splitter = Splitter.on(pattern); + return splitter.splitToList(input); + } + + public static List splitMultiLineWithOpenCSV(String input) throws IOException { + CSVParser parser = new CSVParserBuilder().withSeparator(',') + .build(); + + CSVReader reader = new CSVReaderBuilder(new StringReader(input)).withCSVParser(parser) + .build(); + + List list = new ArrayList<>(); + list = reader.readAll(); + reader.close(); + + return list; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedStringUnitTest.java b/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedStringUnitTest.java new file mode 100644 index 0000000000..ca34430099 --- /dev/null +++ b/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/commaseparatedstring/SplitCommaSeparatedStringUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.commaseparatedstring; + +import static com.baeldung.commaseparatedstring.SplitCommaSeparatedString.splitMultiLineWithOpenCSV; +import static com.baeldung.commaseparatedstring.SplitCommaSeparatedString.splitWithGuava; +import static com.baeldung.commaseparatedstring.SplitCommaSeparatedString.splitWithParser; +import static com.baeldung.commaseparatedstring.SplitCommaSeparatedString.splitWithRegex; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertArrayEquals; + +import java.io.IOException; +import java.util.List; + +import org.junit.Test; + +public class SplitCommaSeparatedStringUnitTest { + + @Test + public void givenSingleLineInput_whenParsing_shouldIgnoreCommasInsideDoubleQuotes() { + String input = "baeldung,tutorial,splitting,text,\"ignoring this comma,\""; + + var matcher = contains("baeldung", "tutorial", "splitting", "text", "\"ignoring this comma,\""); + assertThat(splitWithParser(input), matcher); + assertThat(splitWithRegex(input), matcher); + assertThat(splitWithGuava(input), matcher); + } + + @Test + public void givenMultiLineInput_whenParsing_shouldIgnoreCommasInsideDoubleQuotes() throws IOException { + String input = "baeldung,tutorial,splitting,text,\"ignoring this comma,\"" + System.lineSeparator() + + "splitting,a,regular,line,no double quotes"; + + String[] firstLine = new String[]{"baeldung", "tutorial", "splitting", "text", "ignoring this comma,"}; + String[] secondLine = new String[]{"splitting", "a", "regular", "line", "no double quotes"}; + + List result = splitMultiLineWithOpenCSV(input); + + assertThat(result, hasSize(2)); + assertArrayEquals(firstLine, result.get(0)); + assertArrayEquals(secondLine, result.get(1)); + } + +} diff --git a/pom.xml b/pom.xml index 372bc5a9f3..2672706f6b 100644 --- a/pom.xml +++ b/pom.xml @@ -1304,6 +1304,7 @@ core-java-modules/core-java-jpms core-java-modules/core-java-os core-java-modules/core-java-string-operations-3 + core-java-modules/core-java-string-operations-4 core-java-modules/core-java-time-measurements core-java-modules/multimodulemavenproject persistence-modules/sirix From 4da6f38cbd617ad9190f4851dad6c71aedb6fab5 Mon Sep 17 00:00:00 2001 From: mikr Date: Mon, 15 Nov 2021 21:37:22 +0100 Subject: [PATCH 17/78] JAVA-8293 Split or move Spring Boot module (fix review comments) --- spring-boot-modules/spring-boot-1/pom.xml | 6 +++++- .../servletinitializer/WarInitializerApplication.java | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-1/pom.xml b/spring-boot-modules/spring-boot-1/pom.xml index 82a1a38397..b6e3717f7c 100644 --- a/spring-boot-modules/spring-boot-1/pom.xml +++ b/spring-boot-modules/spring-boot-1/pom.xml @@ -43,7 +43,7 @@ org.apache.logging.log4j log4j-core - 2.14.1 + ${log4j2.version} com.h2database @@ -67,4 +67,8 @@ + + 2.14.1 + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java index 3b360b4adc..0aa0f0ae0b 100644 --- a/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java +++ b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java @@ -5,7 +5,6 @@ import java.time.LocalDateTime; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -//import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; From 15a50b8fe2cb60f2e67f0e53c81576fc0667cd66 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 16 Nov 2021 11:25:14 +0100 Subject: [PATCH 18/78] JAVA-7783: POM properties cleanup --- spring-web-modules/spring-5-mvc/pom.xml | 6 --- spring-web-modules/spring-rest-shell/pom.xml | 9 ---- .../spring-resttemplate-2/pom.xml | 9 ---- .../spring-resttemplate-3/pom.xml | 1 - spring-web-modules/spring-thymeleaf-2/pom.xml | 2 - testing-modules/gatling/pom.xml | 8 +-- testing-modules/junit-5/pom.xml | 1 - .../load-testing-comparison/pom.xml | 54 ++----------------- xml/pom.xml | 3 -- 9 files changed, 8 insertions(+), 85 deletions(-) diff --git a/spring-web-modules/spring-5-mvc/pom.xml b/spring-web-modules/spring-5-mvc/pom.xml index 79a4f73ace..23bcb00801 100644 --- a/spring-web-modules/spring-5-mvc/pom.xml +++ b/spring-web-modules/spring-5-mvc/pom.xml @@ -81,12 +81,6 @@ ${project.basedir}/src/test/kotlin - - - org.springframework.boot - spring-boot-maven-plugin - - diff --git a/spring-web-modules/spring-rest-shell/pom.xml b/spring-web-modules/spring-rest-shell/pom.xml index b83a0b6002..992092f43f 100644 --- a/spring-web-modules/spring-rest-shell/pom.xml +++ b/spring-web-modules/spring-rest-shell/pom.xml @@ -37,13 +37,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-2/pom.xml b/spring-web-modules/spring-resttemplate-2/pom.xml index d0191b970e..b87b245da9 100644 --- a/spring-web-modules/spring-resttemplate-2/pom.xml +++ b/spring-web-modules/spring-resttemplate-2/pom.xml @@ -66,13 +66,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-3/pom.xml b/spring-web-modules/spring-resttemplate-3/pom.xml index 8e313ccf39..b036a5ffcb 100644 --- a/spring-web-modules/spring-resttemplate-3/pom.xml +++ b/spring-web-modules/spring-resttemplate-3/pom.xml @@ -16,7 +16,6 @@ - org.springframework.boot spring-boot-starter-web diff --git a/spring-web-modules/spring-thymeleaf-2/pom.xml b/spring-web-modules/spring-thymeleaf-2/pom.xml index b2b893ecd5..14e4de668b 100644 --- a/spring-web-modules/spring-thymeleaf-2/pom.xml +++ b/spring-web-modules/spring-thymeleaf-2/pom.xml @@ -65,8 +65,6 @@ - 1.8 - 1.8 2.2 diff --git a/testing-modules/gatling/pom.xml b/testing-modules/gatling/pom.xml index c702b576c5..f1c9906581 100644 --- a/testing-modules/gatling/pom.xml +++ b/testing-modules/gatling/pom.xml @@ -109,10 +109,10 @@ 1.8 1.8 UTF-8 - 2.12.6 - 3.3.1 - 4.3.0 - 3.0.4 + 2.12.6 + 3.3.1 + 4.3.0 + 3.0.4 \ No newline at end of file diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index ef6e92faa4..7a511dfe7a 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -28,7 +28,6 @@ ${junit-platform.version} test - org.junit.platform junit-platform-console-standalone diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml index 63f2d9ce2f..d5a389d311 100644 --- a/testing-modules/load-testing-comparison/pom.xml +++ b/testing-modules/load-testing-comparison/pom.xml @@ -57,57 +57,11 @@ - - - - - - - - - - org.springframework.boot spring-boot-maven-plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -115,10 +69,10 @@ 1.8 1.8 UTF-8 - 2.12.12 - 3.4.0 - 4.4.0 - 3.1.0 + 2.12.12 + 3.4.0 + 4.4.0 + 3.1.0 5.0 diff --git a/xml/pom.xml b/xml/pom.xml index d05f2401e3..9acaecbd22 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -372,11 +372,8 @@ 2.6.3 2.3.29 0.9.6 - - 2.4 1.3.1 - 3.8.0 1.14.3 2.25 3.4 From 0ab9e2e4f2772a6eac2e1e75c1920a448f51df02 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 16 Nov 2021 15:10:49 +0100 Subject: [PATCH 19/78] JAVA-7783: POM properties cleanup --- core-java-modules/core-java-11-2/pom.xml | 1 - core-java-modules/core-java-12/pom.xml | 2 +- core-java-modules/core-java-16/pom.xml | 3 +-- core-java-modules/core-java-17/pom.xml | 1 - core-java-modules/core-java-9/pom.xml | 1 - core-java-modules/core-java-annotations/pom.xml | 8 ++++---- core-java-modules/core-java-arrays-guides/pom.xml | 6 +++++- .../core-java-date-operations-1/pom.xml | 3 ++- .../core-java-datetime-string/pom.xml | 3 ++- core-java-modules/core-java-exceptions-2/pom.xml | 3 +-- core-java-modules/core-java-exceptions-3/pom.xml | 3 ++- core-java-modules/core-java-exceptions/pom.xml | 3 +-- core-java-modules/core-java-jndi/pom.xml | 3 ++- core-java-modules/core-java-jpms/pom.xml | 3 +-- .../core-java-lang-oop-methods/pom.xml | 1 - core-java-modules/core-java-networking-3/pom.xml | 3 ++- core-java-modules/core-java-nio-2/pom.xml | 6 +++++- core-java-modules/core-java-reflection-2/pom.xml | 7 ++++--- core-java-modules/core-java-reflection/pom.xml | 1 - core-java-modules/core-java-serialization/pom.xml | 2 +- core-java-modules/core-java-streams-3/pom.xml | 3 +-- .../core-java-string-conversions-2/pom.xml | 14 +++++++------- .../spring-security-web-mvc-custom/pom.xml | 6 ------ .../spring-security-web-persistent-login/pom.xml | 6 ------ .../spring-security-web-rest-basic-auth/pom.xml | 11 ----------- .../spring-security-web-thymeleaf/pom.xml | 9 --------- spring-vertx/pom.xml | 9 --------- spring-webflux-amqp/pom.xml | 9 --------- spring-webflux-threads/pom.xml | 9 --------- 29 files changed, 42 insertions(+), 97 deletions(-) diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml index 863c9b0717..2b7b042c61 100644 --- a/core-java-modules/core-java-11-2/pom.xml +++ b/core-java-modules/core-java-11-2/pom.xml @@ -89,7 +89,6 @@ 29.0-jre 3.17.2 5.11.1 - 3.12.0 3.0.0 3.0.0 2.3.1 diff --git a/core-java-modules/core-java-12/pom.xml b/core-java-modules/core-java-12/pom.xml index 26b7d0c14d..516f28fc3a 100644 --- a/core-java-modules/core-java-12/pom.xml +++ b/core-java-modules/core-java-12/pom.xml @@ -25,7 +25,7 @@ commons-io commons-io - 2.11.0 + ${commons-io.version} diff --git a/core-java-modules/core-java-16/pom.xml b/core-java-modules/core-java-16/pom.xml index 14f15cdd92..99952a73d9 100644 --- a/core-java-modules/core-java-16/pom.xml +++ b/core-java-modules/core-java-16/pom.xml @@ -26,7 +26,7 @@ org.apache.commons commons-lang3 - 3.12.0 + ${commons-lang3.version} @@ -66,7 +66,6 @@ 16 16 16 - 3.8.1 3.0.0-M5 3.17.2 diff --git a/core-java-modules/core-java-17/pom.xml b/core-java-modules/core-java-17/pom.xml index 3cee27b276..677454a64b 100644 --- a/core-java-modules/core-java-17/pom.xml +++ b/core-java-modules/core-java-17/pom.xml @@ -62,7 +62,6 @@ 17 17 17 - 3.8.1 3.0.0-M5 3.17.2 diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index 1bd650f7d2..d4d58085c8 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -85,7 +85,6 @@ 1.9 25.1-jre 4.1 - 3.2.2 \ No newline at end of file diff --git a/core-java-modules/core-java-annotations/pom.xml b/core-java-modules/core-java-annotations/pom.xml index 19d02aa2ac..7e87678159 100644 --- a/core-java-modules/core-java-annotations/pom.xml +++ b/core-java-modules/core-java-annotations/pom.xml @@ -23,10 +23,6 @@ - - 3.10.0 - - core-java-annotations @@ -36,5 +32,9 @@ + + + 3.10.0 + \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml index 3dba2dc05f..0c8b680c1b 100644 --- a/core-java-modules/core-java-arrays-guides/pom.xml +++ b/core-java-modules/core-java-arrays-guides/pom.xml @@ -27,9 +27,13 @@ org.assertj assertj-core - 3.19.0 + ${assertj.version} test + + 3.19.0 + + \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index 854d6ed916..8a13163ba4 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -34,7 +34,7 @@ com.darwinsys hirondelle-date4j - RELEASE + ${hirondelle-date4j.version} test @@ -64,6 +64,7 @@ 2.10 3.6.1 + RELEASE 1.9 1.9 diff --git a/core-java-modules/core-java-datetime-string/pom.xml b/core-java-modules/core-java-datetime-string/pom.xml index 8bc7b60126..a65659be71 100644 --- a/core-java-modules/core-java-datetime-string/pom.xml +++ b/core-java-modules/core-java-datetime-string/pom.xml @@ -46,7 +46,7 @@ com.darwinsys hirondelle-date4j - RELEASE + ${hirondelle-date4j.version} test @@ -75,6 +75,7 @@ 1.6 2.10.10 + RELEASE 3.6.1 1.9 diff --git a/core-java-modules/core-java-exceptions-2/pom.xml b/core-java-modules/core-java-exceptions-2/pom.xml index af7a778b23..d952683a64 100644 --- a/core-java-modules/core-java-exceptions-2/pom.xml +++ b/core-java-modules/core-java-exceptions-2/pom.xml @@ -25,12 +25,11 @@ org.apache.commons commons-lang3 - ${commons.lang3.version} + ${commons-lang3.version} - 3.10 3.10.0 diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml index bdee998e8d..ffc21799ce 100644 --- a/core-java-modules/core-java-exceptions-3/pom.xml +++ b/core-java-modules/core-java-exceptions-3/pom.xml @@ -19,7 +19,7 @@ com.h2database h2 - 1.4.191 + ${h2.version} test @@ -34,6 +34,7 @@ 3.10.0 + 1.4.191 \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions/pom.xml b/core-java-modules/core-java-exceptions/pom.xml index 1f15dabe36..d5581279b5 100644 --- a/core-java-modules/core-java-exceptions/pom.xml +++ b/core-java-modules/core-java-exceptions/pom.xml @@ -30,7 +30,7 @@ org.apache.commons commons-lang3 - ${commons.lang3.version} + ${commons-lang3.version} @@ -43,7 +43,6 @@ 1.5.0-b01 - 3.10 3.10.0 diff --git a/core-java-modules/core-java-jndi/pom.xml b/core-java-modules/core-java-jndi/pom.xml index 6b7c4e1359..f971623bc2 100644 --- a/core-java-modules/core-java-jndi/pom.xml +++ b/core-java-modules/core-java-jndi/pom.xml @@ -50,7 +50,7 @@ org.assertj assertj-core - 3.21.0 + ${assertj-core.version} test @@ -71,6 +71,7 @@ 5.0.9.RELEASE 1.4.199 + 3.21.0 2.0.0.AM26 1.8 1.8 diff --git a/core-java-modules/core-java-jpms/pom.xml b/core-java-modules/core-java-jpms/pom.xml index 65f5afad47..62aa49f299 100644 --- a/core-java-modules/core-java-jpms/pom.xml +++ b/core-java-modules/core-java-jpms/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugins maven-compiler-plugin - ${compiler.plugin.version} + ${maven-compiler-plugin.version} ${source.version} ${target.version} @@ -36,7 +36,6 @@ - 3.8.0 11 11 diff --git a/core-java-modules/core-java-lang-oop-methods/pom.xml b/core-java-modules/core-java-lang-oop-methods/pom.xml index e493f716ec..938b457872 100644 --- a/core-java-modules/core-java-lang-oop-methods/pom.xml +++ b/core-java-modules/core-java-lang-oop-methods/pom.xml @@ -40,7 +40,6 @@ 1.18.12 - 2.6 3.10.0 3.0.3 diff --git a/core-java-modules/core-java-networking-3/pom.xml b/core-java-modules/core-java-networking-3/pom.xml index 1579418b54..2fd97ef831 100644 --- a/core-java-modules/core-java-networking-3/pom.xml +++ b/core-java-modules/core-java-networking-3/pom.xml @@ -38,7 +38,7 @@ com.sun.mail javax.mail - 1.6.2 + ${javax.mail.version} @@ -80,6 +80,7 @@ 5.3.3 1.32 0.17 + 1.6.2 \ No newline at end of file diff --git a/core-java-modules/core-java-nio-2/pom.xml b/core-java-modules/core-java-nio-2/pom.xml index f9cf1f3060..9d5e267b46 100644 --- a/core-java-modules/core-java-nio-2/pom.xml +++ b/core-java-modules/core-java-nio-2/pom.xml @@ -18,9 +18,13 @@ org.assertj assertj-core - 3.6.1 + ${assertj.version} test + + 3.6.1 + + \ No newline at end of file diff --git a/core-java-modules/core-java-reflection-2/pom.xml b/core-java-modules/core-java-reflection-2/pom.xml index 75168936a7..06ac745f17 100644 --- a/core-java-modules/core-java-reflection-2/pom.xml +++ b/core-java-modules/core-java-reflection-2/pom.xml @@ -24,12 +24,12 @@ org.reflections reflections - 0.9.12 + ${reflections.version} com.google.guava guava - 30.1.1-jre + ${guava.version} @@ -56,7 +56,8 @@ - 3.8.0 + 0.9.12 + 30.1.1-jre 1.8 1.8 5.3.4 diff --git a/core-java-modules/core-java-reflection/pom.xml b/core-java-modules/core-java-reflection/pom.xml index b28ecccb80..32777e228f 100644 --- a/core-java-modules/core-java-reflection/pom.xml +++ b/core-java-modules/core-java-reflection/pom.xml @@ -45,7 +45,6 @@ - 3.8.0 3.10.0 1.8 1.8 diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml index 8fcebca356..754dcd434b 100644 --- a/core-java-modules/core-java-serialization/pom.xml +++ b/core-java-modules/core-java-serialization/pom.xml @@ -58,7 +58,7 @@ org.springframework spring-core - 4.3.20.RELEASE + ${spring.core.version} test diff --git a/core-java-modules/core-java-streams-3/pom.xml b/core-java-modules/core-java-streams-3/pom.xml index b384ef7e0e..eb440430f6 100644 --- a/core-java-modules/core-java-streams-3/pom.xml +++ b/core-java-modules/core-java-streams-3/pom.xml @@ -65,7 +65,7 @@ org.openjdk.jmh jmh-generator-annprocess - ${jmh.version} + ${jmh-generator.version} @@ -77,7 +77,6 @@ 1.18.20 3.6.1 - 1.29 \ No newline at end of file diff --git a/core-java-modules/core-java-string-conversions-2/pom.xml b/core-java-modules/core-java-string-conversions-2/pom.xml index 68be7d2c08..3e03f4c016 100644 --- a/core-java-modules/core-java-string-conversions-2/pom.xml +++ b/core-java-modules/core-java-string-conversions-2/pom.xml @@ -49,13 +49,6 @@ - - 64.2 - 3.12.2 - 1.9 - 30.1.1-jre - - core-java-string-conversions-2 @@ -65,5 +58,12 @@ + + + 64.2 + 3.12.2 + 1.9 + 30.1.1-jre + \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-mvc-custom/pom.xml b/spring-security-modules/spring-security-web-mvc-custom/pom.xml index 533a1bf83d..ba6b50a7bc 100644 --- a/spring-security-modules/spring-security-web-mvc-custom/pom.xml +++ b/spring-security-modules/spring-security-web-mvc-custom/pom.xml @@ -97,12 +97,6 @@ ${jstl.version} runtime - - - - - - com.fasterxml.jackson.core diff --git a/spring-security-modules/spring-security-web-persistent-login/pom.xml b/spring-security-modules/spring-security-web-persistent-login/pom.xml index 2d931c416c..8a61868172 100644 --- a/spring-security-modules/spring-security-web-persistent-login/pom.xml +++ b/spring-security-modules/spring-security-web-persistent-login/pom.xml @@ -127,12 +127,6 @@ ${spring-boot.version} test - - - - - - diff --git a/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml b/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml index de28df1933..a717339082 100644 --- a/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml +++ b/spring-security-modules/spring-security-web-rest-basic-auth/pom.xml @@ -91,17 +91,6 @@ ${jackson.version} - - - - - - - - - - - org.apache.httpcomponents httpcore diff --git a/spring-security-modules/spring-security-web-thymeleaf/pom.xml b/spring-security-modules/spring-security-web-thymeleaf/pom.xml index 3a240f4129..c13aa6a471 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/pom.xml +++ b/spring-security-modules/spring-security-web-thymeleaf/pom.xml @@ -45,13 +45,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-vertx/pom.xml b/spring-vertx/pom.xml index bd2dfa6cf6..e24bb3f1ee 100644 --- a/spring-vertx/pom.xml +++ b/spring-vertx/pom.xml @@ -47,15 +47,6 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - 3.4.1 diff --git a/spring-webflux-amqp/pom.xml b/spring-webflux-amqp/pom.xml index 498556da2d..3ceb33dc3b 100755 --- a/spring-webflux-amqp/pom.xml +++ b/spring-webflux-amqp/pom.xml @@ -61,13 +61,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-webflux-threads/pom.xml b/spring-webflux-threads/pom.xml index bc5050b660..fedfaa6967 100644 --- a/spring-webflux-threads/pom.xml +++ b/spring-webflux-threads/pom.xml @@ -62,13 +62,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file From 6f913e1d2c2d260916337f8dd80a2befa1afe54f Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 16 Nov 2021 15:19:52 +0100 Subject: [PATCH 20/78] JAVA-7783: Fix jmh dependencies --- .../core-java-arrays-operations-advanced/pom.xml | 13 ++++++------- core-java-modules/core-java-streams-3/pom.xml | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced/pom.xml b/core-java-modules/core-java-arrays-operations-advanced/pom.xml index d122e3330c..50830eba2a 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml +++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml @@ -28,20 +28,15 @@ org.openjdk.jmh jmh-core - ${jmh.version} + ${jmh-core.version} org.openjdk.jmh jmh-generator-annprocess - ${jmh.version} + ${jmh-generator.version} - - 3.10.0 - 1.33 - - @@ -69,4 +64,8 @@ + + 3.10.0 + + \ No newline at end of file diff --git a/core-java-modules/core-java-streams-3/pom.xml b/core-java-modules/core-java-streams-3/pom.xml index eb440430f6..6ace96fc4d 100644 --- a/core-java-modules/core-java-streams-3/pom.xml +++ b/core-java-modules/core-java-streams-3/pom.xml @@ -29,12 +29,12 @@ org.openjdk.jmh jmh-core - ${jmh.version} + ${jmh-core.version} org.openjdk.jmh jmh-generator-annprocess - ${jmh.version} + ${jmh-generator.version} test From a8f340a5b7c14bdeae37932ab12314f1ccd427da Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 16 Nov 2021 20:45:27 +0100 Subject: [PATCH 21/78] JAVA-8376 Split or move spring-boot-properties-2 module --- spring-boot-modules/spring-boot-properties-2/README.md | 1 - spring-boot-modules/spring-boot-properties-3/README.md | 1 + .../properties/json/ConfigPropertiesDemoApplication.java | 0 .../java/com/baeldung/properties/json/CustomJsonProperties.java | 0 .../main/java/com/baeldung/properties/json/JsonProperties.java | 0 .../baeldung/properties/json/JsonPropertyContextInitializer.java | 0 .../properties/json/factory/JsonPropertySourceFactory.java | 0 .../src/main/resources/configprops.json | 0 .../baeldung/properties/json/JsonPropertiesIntegrationTest.java | 0 9 files changed, 1 insertion(+), 1 deletion(-) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/main/java/com/baeldung/properties/json/ConfigPropertiesDemoApplication.java (100%) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/main/java/com/baeldung/properties/json/CustomJsonProperties.java (100%) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/main/java/com/baeldung/properties/json/JsonProperties.java (100%) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/main/java/com/baeldung/properties/json/JsonPropertyContextInitializer.java (100%) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/main/java/com/baeldung/properties/json/factory/JsonPropertySourceFactory.java (100%) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/main/resources/configprops.json (100%) rename spring-boot-modules/{spring-boot-properties-2 => spring-boot-properties-3}/src/test/java/com/baeldung/properties/json/JsonPropertiesIntegrationTest.java (100%) diff --git a/spring-boot-modules/spring-boot-properties-2/README.md b/spring-boot-modules/spring-boot-properties-2/README.md index c81ad50e40..501beed092 100644 --- a/spring-boot-modules/spring-boot-properties-2/README.md +++ b/spring-boot-modules/spring-boot-properties-2/README.md @@ -3,7 +3,6 @@ This module contains articles about Properties in Spring Boot. ### Relevant Articles: -- [Load Spring Boot Properties From a JSON File](https://www.baeldung.com/spring-boot-json-properties) - [A Quick Guide to Spring @Value](https://www.baeldung.com/spring-value-annotation) - [Using Spring @Value with Defaults](https://www.baeldung.com/spring-value-defaults) - [How to Inject a Property Value Into a Class Not Managed by Spring?](https://www.baeldung.com/inject-properties-value-non-spring-class) diff --git a/spring-boot-modules/spring-boot-properties-3/README.md b/spring-boot-modules/spring-boot-properties-3/README.md index df272be7f4..a682ae0ac8 100644 --- a/spring-boot-modules/spring-boot-properties-3/README.md +++ b/spring-boot-modules/spring-boot-properties-3/README.md @@ -7,3 +7,4 @@ - [How to Define a Map in YAML for a POJO?](https://www.baeldung.com/yaml-map-pojo) - [Using application.yml vs application.properties in Spring Boot](https://www.baeldung.com/spring-boot-yaml-vs-properties) +- [Load Spring Boot Properties From a JSON File](https://www.baeldung.com/spring-boot-json-properties) \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/ConfigPropertiesDemoApplication.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/ConfigPropertiesDemoApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/ConfigPropertiesDemoApplication.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/ConfigPropertiesDemoApplication.java diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/CustomJsonProperties.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/CustomJsonProperties.java similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/CustomJsonProperties.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/CustomJsonProperties.java diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/JsonProperties.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/JsonProperties.java similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/JsonProperties.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/JsonProperties.java diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/JsonPropertyContextInitializer.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/JsonPropertyContextInitializer.java similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/JsonPropertyContextInitializer.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/JsonPropertyContextInitializer.java diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/factory/JsonPropertySourceFactory.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/factory/JsonPropertySourceFactory.java similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/json/factory/JsonPropertySourceFactory.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/properties/json/factory/JsonPropertySourceFactory.java diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/resources/configprops.json b/spring-boot-modules/spring-boot-properties-3/src/main/resources/configprops.json similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/resources/configprops.json rename to spring-boot-modules/spring-boot-properties-3/src/main/resources/configprops.json diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/json/JsonPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/properties/json/JsonPropertiesIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/json/JsonPropertiesIntegrationTest.java rename to spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/properties/json/JsonPropertiesIntegrationTest.java From 789382cd0e2e4cdf51e7d2a11dd23e6d0e63d867 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Tue, 16 Nov 2021 20:44:48 +0000 Subject: [PATCH 22/78] [JAVA-6455] Update H2 code with latest Spring Boot changes --- .../springboot/SpringBootH2Application.java | 2 + .../springboot/daos/CountryRepository.java | 7 +++ .../h2db/springboot/daos/UserRepository.java | 10 ---- .../h2db/springboot/models/Country.java | 21 ++++++++ .../baeldung/h2db/springboot/models/User.java | 54 ------------------- .../main/resources/application-h2.properties | 1 + .../src/main/resources/data-h2.sql | 5 ++ .../src/main/resources/data-trans.sql | 14 ----- .../baeldung/SpringBootH2IntegrationTest.java | 36 +++---------- 9 files changed, 43 insertions(+), 107 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/CountryRepository.java delete mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java delete mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/resources/application-h2.properties create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/resources/data-h2.sql diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java index 378093cfa9..d6d7a20f55 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java @@ -2,8 +2,10 @@ package com.baeldung.h2db.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; @SpringBootApplication +@PropertySource("classpath:application-h2.properties") public class SpringBootH2Application { public static void main(String... args) { diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/CountryRepository.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/CountryRepository.java new file mode 100644 index 0000000000..d576be9098 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/CountryRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.h2db.springboot.daos; + +import com.baeldung.h2db.springboot.models.Country; +import org.springframework.data.repository.CrudRepository; + +public interface CountryRepository extends CrudRepository { +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java deleted file mode 100644 index 35e496e910..0000000000 --- a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.h2db.springboot.daos; - - - - -import com.baeldung.h2db.springboot.models.User; -import org.springframework.data.repository.CrudRepository; - -public interface UserRepository extends CrudRepository { -} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java new file mode 100644 index 0000000000..f0f02c41d3 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java @@ -0,0 +1,21 @@ +package com.baeldung.h2db.springboot.models; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Table(name = "countries") +@Entity +@Data +public class Country { + + @Id + @GeneratedValue + private int id; + + private String name; + +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java deleted file mode 100644 index fa3c01c035..0000000000 --- a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.h2db.springboot.models; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -@Table(name = "users") -@Entity -public class User { - - @Id - @GeneratedValue - private int id; - - private String firstName; - - private String lastName; - - public User() { } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @Override - public String toString() { - return "User{" + - "id=" + id + - ", firstName='" + firstName + '\'' + - ", lastName='" + lastName + '\'' + - '}'; - } -} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-h2.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-h2.properties new file mode 100644 index 0000000000..6fb436f520 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-h2.properties @@ -0,0 +1 @@ +spring.sql.init.data-locations=data-h2.sql diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-h2.sql b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-h2.sql new file mode 100644 index 0000000000..3d04b578d2 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-h2.sql @@ -0,0 +1,5 @@ +INSERT INTO countries (id, name) VALUES (1, 'USA'); +INSERT INTO countries (id, name) VALUES (2, 'France'); +INSERT INTO countries (id, name) VALUES (3, 'Brazil'); +INSERT INTO countries (id, name) VALUES (4, 'Italy'); +INSERT INTO countries (id, name) VALUES (5, 'Canada'); \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-trans.sql b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-trans.sql index b8835e70cb..e4fda99437 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-trans.sql +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data-trans.sql @@ -1,17 +1,3 @@ -DROP TABLE IF EXISTS billionaires; - -CREATE TABLE billionaires ( - id INT AUTO_INCREMENT PRIMARY KEY, - first_name VARCHAR(250) NOT NULL, - last_name VARCHAR(250) NOT NULL, - career VARCHAR(250) DEFAULT NULL -); - -INSERT INTO billionaires (first_name, last_name, career) VALUES -('Aliko', 'Dangote', 'Billionaire Industrialist'), -('Bill', 'Gates', 'Billionaire Tech Entrepreneur'), -('Folrunsho', 'Alakija', 'Billionaire Oil Magnate'); - insert into USER values (101, 'user1', 'comment1'); insert into USER values (102, 'user2', 'comment2'); insert into USER values (103, 'user3', 'comment3'); diff --git a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java index aecc63c599..abdbd76c19 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java @@ -1,50 +1,28 @@ package com.baeldung; import com.baeldung.h2db.springboot.SpringBootH2Application; -import com.baeldung.h2db.springboot.daos.UserRepository; -import com.baeldung.h2db.springboot.models.User; +import com.baeldung.h2db.springboot.daos.CountryRepository; +import com.baeldung.h2db.springboot.models.Country; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import java.util.List; - -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringBootH2Application.class) public class SpringBootH2IntegrationTest { @Autowired - private UserRepository userRepository; + private CountryRepository countryRepository; @Test - public void contextLoads() { } + public void givenInitData_whenApplicationStarts_thenDataIsLoaded() { + Iterable users = countryRepository.findAll(); - @Test - public void givenUserProfile_whenAddUser_thenCreateNewUser() { - User user = new User(); - user.setFirstName("John"); - user.setLastName("Doe"); - userRepository.save(user); - List users = (List) userRepository.findAll(); - assertFalse(users.isEmpty()); - - String firstName = "Aliko"; - String lastName = "Dangote"; - User user1 = userRepository.findById(users.get(0).getId()).get(); - user1.setLastName(lastName); - user1.setFirstName(firstName); - userRepository.save(user1); - - user = userRepository.findById(user.getId()).get(); - assertEquals(user.getFirstName(), firstName); - assertEquals(user.getLastName(), lastName); - - userRepository.deleteById(user.getId()); - assertTrue( ((List) userRepository.findAll()).isEmpty()); + assertThat(users).hasSize(5); } } From 8a7d540c8d05c296098739b6d64df7751422a5b1 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 17 Nov 2021 08:39:05 +0100 Subject: [PATCH 23/78] JAVA-8374 Split or move spring-boot-libraries module --- spring-boot-modules/spring-boot-libraries-2/README.md | 2 ++ .../src/main/java/com/baeldung/kong/QueryController.java | 0 .../src/main/java/com/baeldung/kong/StockApp.java | 0 .../src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java | 0 .../test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java | 0 .../src/test/java/com/baeldung/kong/domain/APIObject.java | 0 .../src/test/java/com/baeldung/kong/domain/ConsumerObject.java | 0 .../src/test/java/com/baeldung/kong/domain/KeyAuthObject.java | 0 .../src/test/java/com/baeldung/kong/domain/PluginObject.java | 0 .../src/test/java/com/baeldung/kong/domain/TargetObject.java | 0 .../src/test/java/com/baeldung/kong/domain/UpstreamObject.java | 0 spring-boot-modules/spring-boot-libraries/README.md | 2 +- 12 files changed, 3 insertions(+), 1 deletion(-) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/main/java/com/baeldung/kong/QueryController.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/main/java/com/baeldung/kong/StockApp.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/domain/APIObject.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/domain/ConsumerObject.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/domain/PluginObject.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/domain/TargetObject.java (100%) rename spring-boot-modules/{spring-boot-libraries => spring-boot-libraries-2}/src/test/java/com/baeldung/kong/domain/UpstreamObject.java (100%) diff --git a/spring-boot-modules/spring-boot-libraries-2/README.md b/spring-boot-modules/spring-boot-libraries-2/README.md index 7bf51b5424..cf07279258 100644 --- a/spring-boot-modules/spring-boot-libraries-2/README.md +++ b/spring-boot-modules/spring-boot-libraries-2/README.md @@ -6,3 +6,5 @@ This module contains articles about various Spring Boot libraries - [Background Jobs in Spring with JobRunr](https://www.baeldung.com/java-jobrunr-spring) - [Open API Server Implementation Using OpenAPI Generator](https://www.baeldung.com/java-openapi-generator-server) +- [An Introduction to Kong](https://www.baeldung.com/kong) + More articles: [[prev -->]](/spring-boot-modules/spring-boot-libraries) diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/kong/QueryController.java b/spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/kong/QueryController.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/kong/QueryController.java rename to spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/kong/QueryController.java diff --git a/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/kong/StockApp.java b/spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/kong/StockApp.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/kong/StockApp.java rename to spring-boot-modules/spring-boot-libraries-2/src/main/java/com/baeldung/kong/StockApp.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/APIObject.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/APIObject.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/APIObject.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/APIObject.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/ConsumerObject.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/ConsumerObject.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/ConsumerObject.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/ConsumerObject.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/PluginObject.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/PluginObject.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/PluginObject.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/PluginObject.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/TargetObject.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/TargetObject.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/TargetObject.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/TargetObject.java diff --git a/spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/UpstreamObject.java b/spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/UpstreamObject.java similarity index 100% rename from spring-boot-modules/spring-boot-libraries/src/test/java/com/baeldung/kong/domain/UpstreamObject.java rename to spring-boot-modules/spring-boot-libraries-2/src/test/java/com/baeldung/kong/domain/UpstreamObject.java diff --git a/spring-boot-modules/spring-boot-libraries/README.md b/spring-boot-modules/spring-boot-libraries/README.md index 6976435866..b72815e4a9 100644 --- a/spring-boot-modules/spring-boot-libraries/README.md +++ b/spring-boot-modules/spring-boot-libraries/README.md @@ -14,7 +14,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Boot and Caffeine Cache](https://www.baeldung.com/spring-boot-caffeine-cache) - [Spring Boot and Togglz Aspect](https://www.baeldung.com/spring-togglz) - [Getting Started with GraphQL and Spring Boot](https://www.baeldung.com/spring-graphql) -- [An Introduction to Kong](https://www.baeldung.com/kong) +- More articles: [[next -->]](/spring-boot-modules/spring-boot-libraries-2) ### GraphQL sample queries From 671517c5ed44722b1ff2dc009c3b2de1243ba6b4 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 17 Nov 2021 09:20:17 +0100 Subject: [PATCH 24/78] JAVA-8393 Split or move spring-security-core module --- spring-boot-modules/spring-boot-security/README.md | 1 + spring-security-modules/spring-security-core/README.md | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-security/README.md b/spring-boot-modules/spring-boot-security/README.md index 2c9d37eac0..b9966709cb 100644 --- a/spring-boot-modules/spring-boot-security/README.md +++ b/spring-boot-modules/spring-boot-security/README.md @@ -9,6 +9,7 @@ This module contains articles about Spring Boot Security - [Introduction to Spring Security Taglibs](https://www.baeldung.com/spring-security-taglibs) - [Guide to @CurrentSecurityContext in Spring Security](https://www.baeldung.com/spring-currentsecuritycontext) - [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) +- [Spring @EnableWebSecurity vs. @EnableGlobalMethodSecurity](https://www.baeldung.com/spring-enablewebsecurity-vs-enableglobalmethodsecurity) ### Spring Boot Security Auto-Configuration diff --git a/spring-security-modules/spring-security-core/README.md b/spring-security-modules/spring-security-core/README.md index f9c6d2e5fb..9f8e4dda53 100644 --- a/spring-security-modules/spring-security-core/README.md +++ b/spring-security-modules/spring-security-core/README.md @@ -10,7 +10,6 @@ This module contains articles about core Spring Security - [Deny Access on Missing @PreAuthorize to Spring Controller Methods](https://www.baeldung.com/spring-deny-access) - [Spring Security: Check If a User Has a Role in Java](https://www.baeldung.com/spring-security-check-user-role) - [Filtering Jackson JSON Output Based on Spring Security Role](https://www.baeldung.com/spring-security-role-filter-json) -- [Spring @EnableWebSecurity vs. @EnableGlobalMethodSecurity](https://www.baeldung.com/spring-enablewebsecurity-vs-enableglobalmethodsecurity) ### Build the Project From 6544b93cfe9d0b076bc2bd94b9bb693ad1f79066 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 17 Nov 2021 13:48:38 +0100 Subject: [PATCH 25/78] JAVA-8436: Add assertj.version property to the main pom.xml --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 2672706f6b..5e693c9809 100644 --- a/pom.xml +++ b/pom.xml @@ -1388,6 +1388,7 @@ 4.13.2 + 3.21.0 2.2 1.3 3.3.0 From bd69a7e89ee3dae3d40bc5a5b9292bf17d04d70d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:02:47 +0800 Subject: [PATCH 26/78] Update README.md --- xml/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/xml/README.md b/xml/README.md index 367a0334f6..16942c6836 100644 --- a/xml/README.md +++ b/xml/README.md @@ -12,3 +12,4 @@ This module contains articles about eXtensible Markup Language (XML) - [Convert XML to HTML in Java](https://www.baeldung.com/java-convert-xml-to-html) - [Parsing an XML File Using StAX](https://www.baeldung.com/java-stax) - [Parsing an XML File Using SAX Parser](https://www.baeldung.com/java-sax-parser) +- [Remove HTML Tags Using Java](https://www.baeldung.com/java-remove-html-tags) From 33a08820dd596239b5b7e320d270ce1fd42775fe Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:05:19 +0800 Subject: [PATCH 27/78] Update README.md --- .../spring-boot-basic-customization-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-basic-customization-2/README.md b/spring-boot-modules/spring-boot-basic-customization-2/README.md index f041c1d38a..0e688bda2a 100644 --- a/spring-boot-modules/spring-boot-basic-customization-2/README.md +++ b/spring-boot-modules/spring-boot-basic-customization-2/README.md @@ -5,4 +5,5 @@ This module contains articles about Spring Boot customization 2 ### Relevant Articles: - [DispatcherServlet and web.xml in Spring Boot](https://www.baeldung.com/spring-boot-dispatcherservlet-web-xml) - - [XML Defined Beans in Spring Boot](https://www.baeldung.com/spring-boot-xml-beans) \ No newline at end of file + - [XML Defined Beans in Spring Boot](https://www.baeldung.com/spring-boot-xml-beans) + - [What Is OncePerRequestFilter?](https://www.baeldung.com/spring-onceperrequestfilter) From bbb18bea71316738416d47b7eeb779ba14456ce7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:09:16 +0800 Subject: [PATCH 28/78] Update README.md --- testing-modules/testing-assertions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-assertions/README.md b/testing-modules/testing-assertions/README.md index ea238af599..bf35505211 100644 --- a/testing-modules/testing-assertions/README.md +++ b/testing-modules/testing-assertions/README.md @@ -2,3 +2,4 @@ - [Asserting Log Messages With JUnit](https://www.baeldung.com/junit-asserting-logs) - [Assert Two Lists for Equality Ignoring Order in Java](https://www.baeldung.com/java-assert-lists-equality-ignore-order) +- [Assert That a Java Optional Has a Certain Value](https://www.baeldung.com/java-optional-assert-value) From e2f2f11d4e961a3b901571059306efcf3a868f9d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:10:53 +0800 Subject: [PATCH 29/78] Update README.md --- spring-5-webflux/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-webflux/README.md b/spring-5-webflux/README.md index bd667468fb..889f211fc6 100644 --- a/spring-5-webflux/README.md +++ b/spring-5-webflux/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring 5 WebFlux - [Spring MVC Async vs Spring WebFlux](https://www.baeldung.com/spring-mvc-async-vs-webflux) - [Set a Timeout in Spring 5 Webflux WebClient](https://www.baeldung.com/spring-webflux-timeout) - [Guide to Retry in Spring WebFlux](https://www.baeldung.com/spring-webflux-retry) +- [Spring Webflux and @Cacheable Annotation](https://www.baeldung.com/spring-webflux-cacheable) From e61653c7aa10266528a359794bedeb4da95b9d38 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:12:46 +0800 Subject: [PATCH 30/78] Update README.md --- core-java-modules/core-java-string-operations-4/README.md | 1 + 1 file changed, 1 insertion(+) 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 88d562204b..304f604c5e 100644 --- a/core-java-modules/core-java-string-operations-4/README.md +++ b/core-java-modules/core-java-string-operations-4/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: +- [Ignoring Commas in Quotes When Splitting a Comma-separated String](https://www.baeldung.com/java-split-string-commas) From d42fee3169a1b3bcf7f0658a29901618ec34b661 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:14:49 +0800 Subject: [PATCH 31/78] Update README.md --- core-java-modules/core-java-lang-oop-constructors/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-oop-constructors/README.md b/core-java-modules/core-java-lang-oop-constructors/README.md index 69ade3e25a..d3d05d31bf 100644 --- a/core-java-modules/core-java-lang-oop-constructors/README.md +++ b/core-java-modules/core-java-lang-oop-constructors/README.md @@ -8,3 +8,4 @@ This module contains article about constructors in Java - [Cannot Reference “X” Before Supertype Constructor Has Been Called](https://www.baeldung.com/java-cannot-reference-x-before-supertype-constructor-error) - [Private Constructors in Java](https://www.baeldung.com/java-private-constructors) - [Throwing Exceptions in Constructors](https://www.baeldung.com/java-constructors-exceptions) +- [Constructors in Java Abstract Classes](https://www.baeldung.com/java-abstract-classes-constructors) From 95aa489cca416689902fe16637ece597515f359d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 18 Nov 2021 01:18:47 +0800 Subject: [PATCH 32/78] Update README.md --- apache-poi/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/apache-poi/README.md b/apache-poi/README.md index d19af8d6ef..13d62eeba0 100644 --- a/apache-poi/README.md +++ b/apache-poi/README.md @@ -13,3 +13,4 @@ This module contains articles about Apache POI - [Setting Formulas in Excel with Apache POI](https://www.baeldung.com/java-apache-poi-set-formulas) - [Insert a Row in Excel Using Apache POI](https://www.baeldung.com/apache-poi-insert-excel-row) - [Multiline Text in Excel Cell Using Apache POI](https://www.baeldung.com/apache-poi-write-multiline-text) +- [Set Background Color of a Cell with Apache POI](https://www.baeldung.com/apache-poi-background-color) From 2029d0a27ba740ac04569af569f7f4ac69609d23 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Wed, 17 Nov 2021 21:06:29 +0000 Subject: [PATCH 33/78] [JAVA-8383] Add charset to email mime type to handle special chars --- .../java/com/baeldung/mail/EmailService.java | 90 +++++++++++-------- .../src/main/resources/attachment.txt | 1 + .../baeldung/mail/EmailServiceLiveTest.java | 60 +++++++++++++ 3 files changed, 113 insertions(+), 38 deletions(-) create mode 100644 core-java-modules/core-java-networking-2/src/main/resources/attachment.txt create mode 100644 core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/EmailService.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/EmailService.java index bd2024fdfa..3d1e25e7a4 100644 --- a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/EmailService.java +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/EmailService.java @@ -1,40 +1,55 @@ package com.baeldung.mail; -import javax.mail.*; +import javax.mail.Authenticator; +import javax.mail.Message; +import javax.mail.Multipart; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import java.io.File; +import java.net.URI; import java.util.Properties; public class EmailService { - private String host = ""; - private int port = 0; - private String username = ""; - private String password = ""; + private String username; + private String password; + private final Properties prop; public EmailService(String host, int port, String username, String password) { - - this.host = host; - this.port = port; - this.username = username; - this.password = password; - - sendMail(); - } - - private void sendMail() { - - Properties prop = new Properties(); + prop = new Properties(); prop.put("mail.smtp.auth", true); prop.put("mail.smtp.starttls.enable", "true"); prop.put("mail.smtp.host", host); prop.put("mail.smtp.port", port); prop.put("mail.smtp.ssl.trust", host); + this.username = username; + this.password = password; + } + + public EmailService(String host, int port) { + prop = new Properties(); + prop.put("mail.smtp.host", host); + prop.put("mail.smtp.port", port); + } + + public static void main(String... args) { + try { + new EmailService("smtp.mailtrap.io", 25, "87ba3d9555fae8", "91cb4379af43ed") + .sendMail(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void sendMail() throws Exception { + Session session = Session.getInstance(prop, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { @@ -42,36 +57,35 @@ public class EmailService { } }); - try { + Message message = new MimeMessage(session); + message.setFrom(new InternetAddress("from@gmail.com")); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to@gmail.com")); + message.setSubject("Mail Subject"); - Message message = new MimeMessage(session); - message.setFrom(new InternetAddress("from@gmail.com")); - message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to@gmail.com")); - message.setSubject("Mail Subject"); + String msg = "This is my first email using JavaMailer"; - String msg = "This is my first email using JavaMailer"; + MimeBodyPart mimeBodyPart = new MimeBodyPart(); + mimeBodyPart.setContent(msg, "text/html; charset=utf-8"); - MimeBodyPart mimeBodyPart = new MimeBodyPart(); - mimeBodyPart.setContent(msg, "text/html"); + MimeBodyPart attachmentBodyPart = new MimeBodyPart(); - MimeBodyPart attachmentBodyPart = new MimeBodyPart(); - attachmentBodyPart.attachFile(new File("pom.xml")); + attachmentBodyPart.attachFile(getFile()); - Multipart multipart = new MimeMultipart(); - multipart.addBodyPart(mimeBodyPart); - multipart.addBodyPart(attachmentBodyPart); + Multipart multipart = new MimeMultipart(); + multipart.addBodyPart(mimeBodyPart); + multipart.addBodyPart(attachmentBodyPart); - message.setContent(multipart); + message.setContent(multipart); - Transport.send(message); - - } catch (Exception e) { - e.printStackTrace(); - } + Transport.send(message); } - public static void main(String ... args) { - new EmailService("smtp.mailtrap.io", 25, "87ba3d9555fae8", "91cb4379af43ed"); + private File getFile() throws Exception { + URI uri = this.getClass() + .getClassLoader() + .getResource("attachment.txt") + .toURI(); + return new File(uri); } } diff --git a/core-java-modules/core-java-networking-2/src/main/resources/attachment.txt b/core-java-modules/core-java-networking-2/src/main/resources/attachment.txt new file mode 100644 index 0000000000..a726ded018 --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/main/resources/attachment.txt @@ -0,0 +1 @@ +sample attachment content \ No newline at end of file diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java new file mode 100644 index 0000000000..7f543bc612 --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java @@ -0,0 +1,60 @@ +package com.baeldung.mail; + +import com.icegreen.greenmail.junit.GreenMailRule; +import com.icegreen.greenmail.util.ServerSetupTest; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +public class EmailServiceLiveTest { + + @Rule + public final GreenMailRule greenMail = new GreenMailRule(ServerSetupTest.SMTP); + + private EmailService emailService; + + @Before + public void setup() { + emailService = new EmailService("localhost", greenMail.getSmtp().getPort()); + } + + @Test + public void givenEmailMessageWithAttachment_whenEmailIsSent_MessageIsReceived() throws Exception { + + emailService.sendMail(); + + MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); + assertEquals(1, receivedMessages.length); + + MimeMessage receivedMessage = receivedMessages[0]; + assertEquals("Mail Subject", subjectFromMessage(receivedMessage)); + assertEquals("This is my first email using JavaMailer", emailTextFrom(receivedMessage)); + assertEquals("sample attachment content", attachmentContentsFrom(receivedMessage)); + } + + private static String subjectFromMessage(MimeMessage receivedMessage) throws MessagingException { + return receivedMessage.getSubject(); + } + + private static String emailTextFrom(MimeMessage receivedMessage) throws IOException, MessagingException { + return ((MimeMultipart) receivedMessage.getContent()) + .getBodyPart(0) + .getContent() + .toString(); + } + + private static String attachmentContentsFrom(MimeMessage receivedMessage) throws Exception { + return ((MimeMultipart) receivedMessage.getContent()) + .getBodyPart(1) + .getContent() + .toString(); + } + +} From 1f05cb187b104513070a66daa02cb6cf214a18b6 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 10:30:45 +0100 Subject: [PATCH 34/78] JAVA-8436: Add AssertJ dependency to the main pom.xml --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 5e693c9809..6d10dcb668 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,12 @@ ${junit-jupiter.version} test + + org.assertj + assertj-core + ${assertj.version} + test + org.hamcrest hamcrest From ce43aac971d38745b52d5bed497cb12b30fd5e1a Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 10:36:49 +0100 Subject: [PATCH 35/78] JAVA-8436: Remove AssertJ depenendency from the child modules - part 1 --- spring-core-2/pom.xml | 6 ------ spring-core-4/pom.xml | 7 ------- spring-di/pom.xml | 7 ------- spring-ejb/spring-ejb-remote/pom.xml | 7 ------- spring-jersey/pom.xml | 7 ------- testing-modules/assertion-libraries/pom.xml | 7 ------- testing-modules/junit5-annotations/pom.xml | 7 ------- testing-modules/mockito-3/pom.xml | 7 ------- testing-modules/testing-assertions/pom.xml | 7 ------- testing-modules/testing-libraries-2/pom.xml | 7 ------- video-tutorials/jackson-annotations/pom.xml | 7 ------- xml/pom.xml | 7 ------- 12 files changed, 83 deletions(-) diff --git a/spring-core-2/pom.xml b/spring-core-2/pom.xml index de5c7c0d4d..dda23c4ea4 100644 --- a/spring-core-2/pom.xml +++ b/spring-core-2/pom.xml @@ -129,11 +129,6 @@ spring-test test - - org.assertj - assertj-core - test - org.hamcrest hamcrest @@ -205,7 +200,6 @@ 25.1-jre 3.6 - 3.6.1 2.1.0 3.22.0-GA 3.2.2 diff --git a/spring-core-4/pom.xml b/spring-core-4/pom.xml index f9665a672b..1c3e138670 100644 --- a/spring-core-4/pom.xml +++ b/spring-core-4/pom.xml @@ -61,12 +61,6 @@ ${awaitility.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - javax.servlet javax.servlet-api @@ -79,7 +73,6 @@ 2.2.2.RELEASE 28.2-jre 4.0.2 - 2.9.1 \ No newline at end of file diff --git a/spring-di/pom.xml b/spring-di/pom.xml index cbd49242e4..20207663cf 100644 --- a/spring-di/pom.xml +++ b/spring-di/pom.xml @@ -74,12 +74,6 @@ ${mockito.spring.boot.version} test - - org.assertj - assertj-core - ${assertj.version} - test - commons-io commons-io @@ -156,7 +150,6 @@ 20.0 1.5.2.RELEASE 1.10.19 - 3.12.2 1.9.5 diff --git a/spring-ejb/spring-ejb-remote/pom.xml b/spring-ejb/spring-ejb-remote/pom.xml index b7bf2aa79b..a180955dcf 100644 --- a/spring-ejb/spring-ejb-remote/pom.xml +++ b/spring-ejb/spring-ejb-remote/pom.xml @@ -19,12 +19,6 @@ javaee-api provided - - org.assertj - assertj-core - ${assertj.version} - test - @@ -86,7 +80,6 @@ - 3.9.0 1.6.1 1.1.0.Alpha5 diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml index 64a34074bb..197469ccf9 100644 --- a/spring-jersey/pom.xml +++ b/spring-jersey/pom.xml @@ -105,12 +105,6 @@ slf4j-jdk14 ${org.slf4j.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.springframework.boot @@ -218,7 +212,6 @@ 4.5.5 4.0.0 2.27.2 - 3.10.0 1.5.10.RELEASE diff --git a/testing-modules/assertion-libraries/pom.xml b/testing-modules/assertion-libraries/pom.xml index 42dead6ee2..b5cfd711d2 100644 --- a/testing-modules/assertion-libraries/pom.xml +++ b/testing-modules/assertion-libraries/pom.xml @@ -39,12 +39,6 @@ assertj-guava ${assertj-guava.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.javalite javalite-common @@ -84,7 +78,6 @@ 0.32 3.1.0 - 3.9.0 2.1.0 1.4.13 0.12 diff --git a/testing-modules/junit5-annotations/pom.xml b/testing-modules/junit5-annotations/pom.xml index 86e71110c8..95c0d2d448 100644 --- a/testing-modules/junit5-annotations/pom.xml +++ b/testing-modules/junit5-annotations/pom.xml @@ -37,17 +37,10 @@ ${junit-platform.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - 2.8.2 - 3.11.1 \ No newline at end of file diff --git a/testing-modules/mockito-3/pom.xml b/testing-modules/mockito-3/pom.xml index 5a79d81080..10130290df 100644 --- a/testing-modules/mockito-3/pom.xml +++ b/testing-modules/mockito-3/pom.xml @@ -22,17 +22,10 @@ ${mockito.version} test - - org.assertj - assertj-core - ${assertj.version} - test - 3.8.0 - 3.8.0 \ No newline at end of file diff --git a/testing-modules/testing-assertions/pom.xml b/testing-modules/testing-assertions/pom.xml index f9cd35c5e5..12af95b575 100644 --- a/testing-modules/testing-assertions/pom.xml +++ b/testing-modules/testing-assertions/pom.xml @@ -18,12 +18,6 @@ logback-classic ${logback.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.hamcrest hamcrest-all @@ -39,7 +33,6 @@ - 3.16.1 4.4 diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index 2e8a1b4ed2..c7e9ea0e2b 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -30,12 +30,6 @@ ${lombok.version} provided - - org.assertj - assertj-core - ${assertj-core.version} - test - com.github.stefanbirkner system-rules @@ -114,7 +108,6 @@ 1.19.0 1.0.0 1.1.0 - 3.16.1 \ No newline at end of file diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index 827715fe5f..29f457964b 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -100,12 +100,6 @@ ${json-schema-validator.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -126,7 +120,6 @@ 3.0.1 3.0.0 - 3.6.1 2.2.6 3.0.1 diff --git a/xml/pom.xml b/xml/pom.xml index 9acaecbd22..968682ee38 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -123,12 +123,6 @@ commons-lang ${commons-lang.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.xmlunit xmlunit-assertj @@ -368,7 +362,6 @@ 2.3.0.1 2.3.2 1.0-2 - 3.12.2 2.6.3 2.3.29 0.9.6 From 795d78f45e9d41922b7e1d9a8a2e361ec522930e Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 12:23:39 +0100 Subject: [PATCH 36/78] JAVA-8436: Remove AssertJ depenendency from the child modules - part 2 --- apache-kafka/pom.xml | 7 ------- apache-libraries/pom.xml | 8 -------- aws/pom.xml | 7 ------- blade/pom.xml | 7 ------- cdi/pom.xml | 7 ------- ddd-modules/pom.xml | 8 -------- guest/core-java/pom.xml | 7 ------- immutables/pom.xml | 7 ------- javax-servlets/pom.xml | 7 ------- javaxval/pom.xml | 7 ------- jjwt/pom.xml | 5 ----- lombok/pom.xml | 7 ------- mapstruct/pom.xml | 7 ------- metrics/pom.xml | 7 ------- mustache/pom.xml | 4 ---- patterns/design-patterns-architectural/pom.xml | 7 ------- patterns/design-patterns-behavioral-2/pom.xml | 13 ------------- patterns/design-patterns-behavioral/pom.xml | 7 ------- patterns/design-patterns-creational/pom.xml | 7 ------- patterns/dip/pom.xml | 13 ------------- reactor-core/pom.xml | 7 ------- rxjava-core/pom.xml | 6 ------ rxjava-libraries/pom.xml | 6 ------ rxjava-observables/pom.xml | 6 ------ rxjava-operators/pom.xml | 6 ------ spring-boot-modules/spring-boot-keycloak/pom.xml | 8 -------- spring-cloud/spring-cloud-archaius/pom.xml | 5 ----- spring-core/pom.xml | 7 ------- 28 files changed, 200 deletions(-) diff --git a/apache-kafka/pom.xml b/apache-kafka/pom.xml index 8003743f95..9ff894bc55 100644 --- a/apache-kafka/pom.xml +++ b/apache-kafka/pom.xml @@ -98,12 +98,6 @@ jackson-databind ${jackson.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.testcontainers kafka @@ -170,7 +164,6 @@ - 3.6.2 2.8.0 1.15.3 1.15.3 diff --git a/apache-libraries/pom.xml b/apache-libraries/pom.xml index b4cf11b07d..3d78869865 100644 --- a/apache-libraries/pom.xml +++ b/apache-libraries/pom.xml @@ -156,13 +156,6 @@ solr-solrj ${solr.solr-solrj.version} - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -202,7 +195,6 @@ 1.8 1.8.2 2.19.0 - 3.9.0 1.1.2 1.1.0.Final 1.2.0 diff --git a/aws/pom.xml b/aws/pom.xml index 1663266612..7c363eb400 100644 --- a/aws/pom.xml +++ b/aws/pom.xml @@ -26,12 +26,6 @@ ${mockito-core.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - com.amazonaws aws-lambda-java-core @@ -118,7 +112,6 @@ 2.8.0 1.11.290 2.21.0 - 3.8.0 1.11.86 https://s3-us-west-2.amazonaws.com/dynamodb-local/release 1.10.L001 diff --git a/blade/pom.xml b/blade/pom.xml index 8fc517e966..9c8638f0bc 100644 --- a/blade/pom.xml +++ b/blade/pom.xml @@ -36,12 +36,6 @@ provided - - org.assertj - assertj-core - ${assertj-core.version} - test - org.apache.httpcomponents httpclient @@ -119,7 +113,6 @@ 4.5.6 4.5.6 4.4.10 - 3.11.1 3.0.0-M3 0.7 3.1.0 diff --git a/cdi/pom.xml b/cdi/pom.xml index 5eb566dcfb..ee23e082c7 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -25,12 +25,6 @@ weld-se-core ${weld-se-core.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.aspectj aspectjweaver @@ -53,7 +47,6 @@ 2.0.SP1 3.0.5.Final 1.9.2 - 3.10.0 \ No newline at end of file diff --git a/ddd-modules/pom.xml b/ddd-modules/pom.xml index fe3aaf1160..134a9d0566 100644 --- a/ddd-modules/pom.xml +++ b/ddd-modules/pom.xml @@ -39,12 +39,6 @@ ${junit-jupiter.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -80,8 +74,6 @@ 3.8.1 1.0 - - 3.12.2 diff --git a/guest/core-java/pom.xml b/guest/core-java/pom.xml index aaf67fd27e..2ab067ad40 100644 --- a/guest/core-java/pom.xml +++ b/guest/core-java/pom.xml @@ -20,17 +20,10 @@ log4j-core ${log4j2.version} - - org.assertj - assertj-core - ${assertj.version} - test - 2.8.2 - 3.6.1 \ No newline at end of file diff --git a/immutables/pom.xml b/immutables/pom.xml index 648166fd74..7704cddbb6 100644 --- a/immutables/pom.xml +++ b/immutables/pom.xml @@ -18,12 +18,6 @@ value ${immutables.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.mutabilitydetector MutabilityDetector @@ -34,7 +28,6 @@ 2.5.6 - 3.6.1 0.9.6 diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index f1677050cf..1dc58aa917 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/pom.xml @@ -16,12 +16,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - commons-fileupload @@ -56,7 +50,6 @@ 4.5.3 2.8.2 - 3.9.1 4.0.1 diff --git a/javaxval/pom.xml b/javaxval/pom.xml index f0093e0aa4..57369c6f52 100644 --- a/javaxval/pom.xml +++ b/javaxval/pom.xml @@ -34,19 +34,12 @@ spring-test ${org.springframework.version} - - org.assertj - assertj-core - ${assertj.version} - test - 6.0.13.Final 3.0.0 5.0.2.RELEASE - 3.11.1 \ No newline at end of file diff --git a/jjwt/pom.xml b/jjwt/pom.xml index 4c194f9285..cc169ba9fc 100644 --- a/jjwt/pom.xml +++ b/jjwt/pom.xml @@ -38,11 +38,6 @@ jjwt ${jjwt.version} - - org.assertj - assertj-core - test - diff --git a/lombok/pom.xml b/lombok/pom.xml index c5758ea8df..2daaf9f438 100644 --- a/lombok/pom.xml +++ b/lombok/pom.xml @@ -26,12 +26,6 @@ hibernate-jpa-2.1-api ${hibernate-jpa-2.1-api.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -77,7 +71,6 @@ 1.0.0.Final 1.18.10.0 - 3.8.0 \ No newline at end of file diff --git a/mapstruct/pom.xml b/mapstruct/pom.xml index 48687a73b9..4696a46abb 100644 --- a/mapstruct/pom.xml +++ b/mapstruct/pom.xml @@ -41,12 +41,6 @@ lombok-mapstruct-binding ${lombok.mapstruct.binding.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -87,7 +81,6 @@ 1.8 1.8 0.2.0 - 3.16.1 \ No newline at end of file diff --git a/metrics/pom.xml b/metrics/pom.xml index 0ba590ceec..6ac1761ca0 100644 --- a/metrics/pom.xml +++ b/metrics/pom.xml @@ -75,12 +75,6 @@ metrics-aspectj-deps ${metrics-aspectj.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.netflix.spectator spectator-api @@ -95,7 +89,6 @@ 1.7.1 2.0.7.RELEASE - 3.11.1 1.1.0 diff --git a/mustache/pom.xml b/mustache/pom.xml index db72e693c1..faa8bfd8a1 100644 --- a/mustache/pom.xml +++ b/mustache/pom.xml @@ -20,10 +20,6 @@ compiler ${mustache.compiler.api.version} - - org.assertj - assertj-core - org.springframework.boot spring-boot-starter-web diff --git a/patterns/design-patterns-architectural/pom.xml b/patterns/design-patterns-architectural/pom.xml index 11194a9c92..fe7bd38df8 100644 --- a/patterns/design-patterns-architectural/pom.xml +++ b/patterns/design-patterns-architectural/pom.xml @@ -30,12 +30,6 @@ rest-assured ${rest-assured.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.hibernate hibernate-core @@ -50,7 +44,6 @@ - 3.9.1 5.2.16.Final 6.0.6 2.5.3 diff --git a/patterns/design-patterns-behavioral-2/pom.xml b/patterns/design-patterns-behavioral-2/pom.xml index f123a8f2f5..da29575526 100644 --- a/patterns/design-patterns-behavioral-2/pom.xml +++ b/patterns/design-patterns-behavioral-2/pom.xml @@ -14,17 +14,4 @@ 1.0.0-SNAPSHOT - - - org.assertj - assertj-core - ${assertj.version} - test - - - - - 3.12.2 - - \ No newline at end of file diff --git a/patterns/design-patterns-behavioral/pom.xml b/patterns/design-patterns-behavioral/pom.xml index bc032a0f8f..3ddbd6f0fc 100644 --- a/patterns/design-patterns-behavioral/pom.xml +++ b/patterns/design-patterns-behavioral/pom.xml @@ -36,18 +36,11 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - 16.0.2 3.0.1 - 3.9.1 \ No newline at end of file diff --git a/patterns/design-patterns-creational/pom.xml b/patterns/design-patterns-creational/pom.xml index 21bc13c21c..de854d260e 100644 --- a/patterns/design-patterns-creational/pom.xml +++ b/patterns/design-patterns-creational/pom.xml @@ -26,18 +26,11 @@ jsr305 ${javax.annotations.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - 2.4.1 3.0.2 - 3.9.1 \ No newline at end of file diff --git a/patterns/dip/pom.xml b/patterns/dip/pom.xml index 44062aaede..3618791b97 100644 --- a/patterns/dip/pom.xml +++ b/patterns/dip/pom.xml @@ -14,17 +14,4 @@ 1.0.0-SNAPSHOT - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - - - 3.12.1 - - \ No newline at end of file diff --git a/reactor-core/pom.xml b/reactor-core/pom.xml index 420b1b028a..39a66cee3e 100644 --- a/reactor-core/pom.xml +++ b/reactor-core/pom.xml @@ -26,12 +26,6 @@ ${reactor.version} test - - org.assertj - assertj-core - ${assertj.version} - test - org.projectlombok lombok @@ -42,7 +36,6 @@ 3.4.9 - 3.6.1 \ No newline at end of file diff --git a/rxjava-core/pom.xml b/rxjava-core/pom.xml index cd6075e127..89ea1bf7a2 100644 --- a/rxjava-core/pom.xml +++ b/rxjava-core/pom.xml @@ -30,15 +30,9 @@ awaitility ${awaitility.version} - - org.assertj - assertj-core - ${assertj.version} - - 3.8.0 1.2.5 1.7.0 2.2.2 diff --git a/rxjava-libraries/pom.xml b/rxjava-libraries/pom.xml index 5d2c9ec3bb..f8df78d741 100644 --- a/rxjava-libraries/pom.xml +++ b/rxjava-libraries/pom.xml @@ -41,11 +41,6 @@ ${h2.version} runtime - - org.assertj - assertj-core - ${assertj.version} - @@ -53,7 +48,6 @@ 1.2.5 2.0.0 2.2.2 - 3.8.0 \ No newline at end of file diff --git a/rxjava-observables/pom.xml b/rxjava-observables/pom.xml index feb4fc1f39..bcc3c4bbce 100644 --- a/rxjava-observables/pom.xml +++ b/rxjava-observables/pom.xml @@ -25,17 +25,11 @@ rxjava-string ${rx.java.string.version} - - org.assertj - assertj-core - ${assertj.version} - 1.1.1 1.2.5 - 3.8.0 \ No newline at end of file diff --git a/rxjava-operators/pom.xml b/rxjava-operators/pom.xml index ba85dc428b..d833fb5d14 100644 --- a/rxjava-operators/pom.xml +++ b/rxjava-operators/pom.xml @@ -31,11 +31,6 @@ rxjava2-extensions ${rxjava2.ext.version} - - org.assertj - assertj-core - ${assertj.version} - io.reactivex rxjava-math @@ -51,7 +46,6 @@ 0.20.4 2.2.2 - 3.8.0 1.2.5 1.0.0 1.7.0 diff --git a/spring-boot-modules/spring-boot-keycloak/pom.xml b/spring-boot-modules/spring-boot-keycloak/pom.xml index adad6bb2d2..09ddcaa724 100644 --- a/spring-boot-modules/spring-boot-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak/pom.xml @@ -73,19 +73,11 @@ org.springframework.boot spring-boot-starter-web-services - org.springframework.security spring-security-test test - - org.assertj - assertj-core - 3.21.0 - test - - diff --git a/spring-cloud/spring-cloud-archaius/pom.xml b/spring-cloud/spring-cloud-archaius/pom.xml index efd912f8db..ba977bbdc9 100644 --- a/spring-cloud/spring-cloud-archaius/pom.xml +++ b/spring-cloud/spring-cloud-archaius/pom.xml @@ -46,11 +46,6 @@ org.springframework.boot spring-boot-starter-test - - org.assertj - assertj-core - test - org.junit.platform junit-platform-runner diff --git a/spring-core/pom.xml b/spring-core/pom.xml index ab41670224..7afcf7addd 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -57,12 +57,6 @@ ${mockito.spring.boot.version} test - - org.assertj - assertj-core - ${assertj.version} - test - commons-io commons-io @@ -89,7 +83,6 @@ 20.0 1.5.2.RELEASE 1.10.19 - 3.12.2 \ No newline at end of file From ae400f34cecbc6a8a14fafb6a56fbf2c877ce24b Mon Sep 17 00:00:00 2001 From: andresluzu Date: Thu, 18 Nov 2021 06:38:36 -0500 Subject: [PATCH 37/78] BAEL-5132 Abstract class constructors examples (#11389) --- .../defaultconstructor/AbstractClass.java | 5 ++++ .../defaultconstructor/ConcreteClass.java | 8 ++++++ .../noargs/AbstractClass.java | 8 ++++++ .../noargs/ConcreteClassA.java | 4 +++ .../noargs/ConcreteClassB.java | 8 ++++++ .../abstractconstructors/noargs/Counter.java | 18 ++++++++++++ .../noargs/SimpleCounter.java | 13 +++++++++ .../parametrized/Car.java | 28 +++++++++++++++++++ .../parametrized/ElectricCar.java | 17 +++++++++++ .../parametrized/FuelCar.java | 17 +++++++++++ .../noargs/AbstractClassUnitTest.java | 18 ++++++++++++ .../noargs/CounterUnitTest.java | 16 +++++++++++ .../parametrized/CarUnitTest.java | 20 +++++++++++++ 13 files changed, 180 insertions(+) create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/AbstractClass.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/ConcreteClass.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/AbstractClass.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassA.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassB.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/Counter.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/SimpleCounter.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/Car.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/ElectricCar.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/FuelCar.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/AbstractClassUnitTest.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/CounterUnitTest.java create mode 100644 core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/parametrized/CarUnitTest.java diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/AbstractClass.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/AbstractClass.java new file mode 100644 index 0000000000..7599529014 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/AbstractClass.java @@ -0,0 +1,5 @@ +package com.baeldung.abstractconstructors.defaultconstructor; + +public abstract class AbstractClass { + // compiler creates a default constructor +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/ConcreteClass.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/ConcreteClass.java new file mode 100644 index 0000000000..71c418735d --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/defaultconstructor/ConcreteClass.java @@ -0,0 +1,8 @@ +package com.baeldung.abstractconstructors.defaultconstructor; + +public class ConcreteClass extends AbstractClass { + + public ConcreteClass() { + super(); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/AbstractClass.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/AbstractClass.java new file mode 100644 index 0000000000..bdd554b2d9 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/AbstractClass.java @@ -0,0 +1,8 @@ +package com.baeldung.abstractconstructors.noargs; + +public abstract class AbstractClass { + + public AbstractClass() { + System.out.println("Initializing AbstractClass"); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassA.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassA.java new file mode 100644 index 0000000000..8339098127 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassA.java @@ -0,0 +1,4 @@ +package com.baeldung.abstractconstructors.noargs; + +public class ConcreteClassA extends AbstractClass { +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassB.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassB.java new file mode 100644 index 0000000000..cad20d2ec0 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/ConcreteClassB.java @@ -0,0 +1,8 @@ +package com.baeldung.abstractconstructors.noargs; + +public class ConcreteClassB extends AbstractClass { + + public ConcreteClassB() { + System.out.println("Initializing ConcreteClassB"); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/Counter.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/Counter.java new file mode 100644 index 0000000000..a0471ad777 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/Counter.java @@ -0,0 +1,18 @@ +package com.baeldung.abstractconstructors.noargs; + +public abstract class Counter { + + int value; + + private Counter() { + this.value = 0; + System.out.println("Counter No-Arguments constructor"); + } + + public Counter(int value) { + this.value = value; + System.out.println("Parametrized Counter constructor"); + } + + abstract int increment(); +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/SimpleCounter.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/SimpleCounter.java new file mode 100644 index 0000000000..93add905df --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/noargs/SimpleCounter.java @@ -0,0 +1,13 @@ +package com.baeldung.abstractconstructors.noargs; + +public class SimpleCounter extends Counter { + + public SimpleCounter(int value) { + super(value); + } + + @Override + int increment() { + return ++value; + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/Car.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/Car.java new file mode 100644 index 0000000000..8919636b7e --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/Car.java @@ -0,0 +1,28 @@ +package com.baeldung.abstractconstructors.parametrized; + +public abstract class Car { + + private int distance; + + private Car(int distance) { + this.distance = distance; + } + + public Car() { + this(0); + System.out.println("Car default constructor"); + } + + abstract String getInformation(); + + protected void display() { + String info = new StringBuilder(getInformation()) + .append("\nDistance: " + getDistance()) + .toString(); + System.out.println(info); + } + + public int getDistance() { + return distance; + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/ElectricCar.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/ElectricCar.java new file mode 100644 index 0000000000..e17ea6d9c5 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/ElectricCar.java @@ -0,0 +1,17 @@ +package com.baeldung.abstractconstructors.parametrized; + +public class ElectricCar extends Car { + + int chargingTime; + + public ElectricCar(int chargingTime) { + this.chargingTime = chargingTime; + } + + @Override + String getInformation() { + return new StringBuilder("Electric Car") + .append("\nCharging Time: " + chargingTime) + .toString(); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/FuelCar.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/FuelCar.java new file mode 100644 index 0000000000..c18c3a26ef --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/abstractconstructors/parametrized/FuelCar.java @@ -0,0 +1,17 @@ +package com.baeldung.abstractconstructors.parametrized; + +public class FuelCar extends Car { + + String fuel; + + public FuelCar(String fuel) { + this.fuel = fuel; + } + + @Override + String getInformation() { + return new StringBuilder("Fuel Car") + .append("\nFuel type: " + fuel) + .toString(); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/AbstractClassUnitTest.java b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/AbstractClassUnitTest.java new file mode 100644 index 0000000000..c72d3b0f3f --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/AbstractClassUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.abstractconstructors.noargs; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class AbstractClassUnitTest { + + @Test + void givenNoArgsAbstractConstructor_whenNewSubclassA_thenCalled() { + assertNotNull(new ConcreteClassA()); + } + + @Test + void givenNoArgsAbstractConstructor_whenNewSubclassB_thenCalled() { + assertNotNull(new ConcreteClassB()); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/CounterUnitTest.java b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/CounterUnitTest.java new file mode 100644 index 0000000000..774136c5b6 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/noargs/CounterUnitTest.java @@ -0,0 +1,16 @@ +package com.baeldung.abstractconstructors.noargs; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class CounterUnitTest { + + @Test + void givenNoArgAbstractConstructor_whenSubclassCreation_thenCalled() { + Counter counter = new SimpleCounter(1); + assertNotNull(counter); + assertEquals(1, counter.value); + } +} diff --git a/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/parametrized/CarUnitTest.java b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/parametrized/CarUnitTest.java new file mode 100644 index 0000000000..6d17861355 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/abstractconstructors/parametrized/CarUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.abstractconstructors.parametrized; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class CarUnitTest { + @Test + void givenParametrizedConstructor_whenConcreteCreation_thenCall() { + ElectricCar electricCar = new ElectricCar(8); + assertNotNull(electricCar); + electricCar.display(); + + System.out.println(); + + FuelCar fuelCar = new FuelCar("Gasoline"); + assertNotNull(fuelCar); + fuelCar.display(); + } +} From 2c2f2dcf0400d11191964520ca404989438433da Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 12:48:35 +0100 Subject: [PATCH 38/78] JAVA-8436: Remove AssertJ depenendency from the child modules - part 3 --- algorithms-genetic/pom.xml | 7 ------- algorithms-miscellaneous-1/pom.xml | 7 ------- algorithms-miscellaneous-2/pom.xml | 7 ------- algorithms-miscellaneous-3/pom.xml | 7 ------- algorithms-miscellaneous-4/pom.xml | 7 ------- algorithms-miscellaneous-5/pom.xml | 7 ------- algorithms-miscellaneous-6/pom.xml | 7 ------- algorithms-searching/pom.xml | 13 ------------- algorithms-sorting-2/pom.xml | 7 ------- algorithms-sorting/pom.xml | 7 ------- guava-modules/guava-collections-list/pom.xml | 8 -------- guava-modules/guava-collections-set/pom.xml | 15 --------------- guava-modules/guava-collections/pom.xml | 8 -------- guava-modules/guava-core/pom.xml | 12 ------------ guava-modules/guava-utilities/pom.xml | 12 ------------ jackson-modules/jackson-annotations/pom.xml | 7 ------- jackson-modules/jackson-conversions-2/pom.xml | 10 ---------- jackson-modules/jackson/pom.xml | 7 ------- jackson-simple/pom.xml | 12 ------------ java-collections-conversions-2/pom.xml | 6 ------ java-collections-maps-3/pom.xml | 7 ------- java-numbers-3/pom.xml | 7 ------- java-numbers-4/pom.xml | 7 ------- java-numbers/pom.xml | 7 ------- json-2/pom.xml | 7 ------- json/pom.xml | 7 ------- ksqldb/pom.xml | 7 ------- language-interop/pom.xml | 7 ------- libraries-2/pom.xml | 6 ------ libraries-4/pom.xml | 6 ------ libraries-5/pom.xml | 6 ------ libraries-6/pom.xml | 6 ------ libraries-apache-commons-collections/pom.xml | 7 ------- libraries-apache-commons/pom.xml | 6 ------ libraries-data-2/pom.xml | 6 ------ libraries-data-io/pom.xml | 7 ------- libraries-http/pom.xml | 6 ------ libraries-server/pom.xml | 7 ------- libraries-testing/pom.xml | 12 ------------ libraries/pom.xml | 7 ------- persistence-modules/core-java-persistence/pom.xml | 7 ------- persistence-modules/hibernate-enterprise/pom.xml | 7 ------- persistence-modules/hibernate-jpa/pom.xml | 7 ------- persistence-modules/hibernate-libraries/pom.xml | 7 ------- persistence-modules/hibernate-mapping/pom.xml | 7 ------- persistence-modules/hibernate-queries/pom.xml | 7 ------- persistence-modules/hibernate5/pom.xml | 7 ------- persistence-modules/java-jpa-2/pom.xml | 7 ------- persistence-modules/java-jpa-3/pom.xml | 7 ------- .../jpa-hibernate-cascade-type/pom.xml | 7 ------- persistence-modules/spring-jpa/pom.xml | 6 ------ persistence-modules/spring-mybatis/pom.xml | 8 -------- 52 files changed, 395 deletions(-) diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml index 00c9b88dfe..c53ae0f776 100644 --- a/algorithms-genetic/pom.xml +++ b/algorithms-genetic/pom.xml @@ -35,18 +35,11 @@ jenetics ${io.jenetics.version} - - org.assertj - assertj-core - ${org.assertj.core.version} - test - 3.6.1 3.7.0 - 3.9.0 1.11 diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index dd3742d4b0..3b55d979fe 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -35,12 +35,6 @@ ${lombok.version} provided - - org.assertj - assertj-core - ${org.assertj.core.version} - test - com.github.dpaukov combinatoricslib3 @@ -70,7 +64,6 @@ 3.6.1 - 3.9.0 1.11 27.0.1-jre 3.3.0 diff --git a/algorithms-miscellaneous-2/pom.xml b/algorithms-miscellaneous-2/pom.xml index fcefc3ccba..a411cfdb71 100644 --- a/algorithms-miscellaneous-2/pom.xml +++ b/algorithms-miscellaneous-2/pom.xml @@ -45,12 +45,6 @@ tradukisto ${tradukisto.version} - - org.assertj - assertj-core - ${org.assertj.core.version} - test - @@ -78,7 +72,6 @@ 1.0.1 1.0.1 1.0.1 - 3.9.0 1.11 2.7 diff --git a/algorithms-miscellaneous-3/pom.xml b/algorithms-miscellaneous-3/pom.xml index 19eca8eca7..525a2556de 100644 --- a/algorithms-miscellaneous-3/pom.xml +++ b/algorithms-miscellaneous-3/pom.xml @@ -14,12 +14,6 @@ - - org.assertj - assertj-core - ${org.assertj.core.version} - test - org.apache.commons commons-collections4 @@ -69,7 +63,6 @@ - 3.9.0 4.3 28.0-jre 2.6.0 diff --git a/algorithms-miscellaneous-4/pom.xml b/algorithms-miscellaneous-4/pom.xml index 1eae038bc0..8417c121bf 100644 --- a/algorithms-miscellaneous-4/pom.xml +++ b/algorithms-miscellaneous-4/pom.xml @@ -25,16 +25,9 @@ ${lombok.version} provided - - org.assertj - assertj-core - ${org.assertj.core.version} - test - - 3.9.0 27.0.1-jre diff --git a/algorithms-miscellaneous-5/pom.xml b/algorithms-miscellaneous-5/pom.xml index c68ac96c38..4a0abc5cba 100644 --- a/algorithms-miscellaneous-5/pom.xml +++ b/algorithms-miscellaneous-5/pom.xml @@ -34,17 +34,10 @@ guava ${guava.version} - - org.assertj - assertj-core - ${org.assertj.core.version} - test - 1.0.1 - 3.9.0 1.11 3.6.1 28.1-jre diff --git a/algorithms-miscellaneous-6/pom.xml b/algorithms-miscellaneous-6/pom.xml index a9eb75cf1e..1984139069 100644 --- a/algorithms-miscellaneous-6/pom.xml +++ b/algorithms-miscellaneous-6/pom.xml @@ -19,12 +19,6 @@ guava ${guava.version} - - org.assertj - assertj-core - ${org.assertj.core.version} - test - org.projectlombok lombok @@ -40,7 +34,6 @@ 28.1-jre - 3.9.0 3.6.1 diff --git a/algorithms-searching/pom.xml b/algorithms-searching/pom.xml index a67c062403..edb8a0c423 100644 --- a/algorithms-searching/pom.xml +++ b/algorithms-searching/pom.xml @@ -13,15 +13,6 @@ 1.0.0-SNAPSHOT - - - org.assertj - assertj-core - ${org.assertj.core.version} - test - - - algorithms-searching @@ -32,8 +23,4 @@ - - 3.9.0 - - \ No newline at end of file diff --git a/algorithms-sorting-2/pom.xml b/algorithms-sorting-2/pom.xml index c9bec354f3..a8477bf624 100644 --- a/algorithms-sorting-2/pom.xml +++ b/algorithms-sorting-2/pom.xml @@ -29,17 +29,10 @@ ${lombok.version} provided - - org.assertj - assertj-core - ${org.assertj.core.version} - test - 3.6.1 - 3.9.0 1.11 diff --git a/algorithms-sorting/pom.xml b/algorithms-sorting/pom.xml index e916d0aae5..383014d528 100644 --- a/algorithms-sorting/pom.xml +++ b/algorithms-sorting/pom.xml @@ -30,17 +30,10 @@ ${lombok.version} provided - - org.assertj - assertj-core - ${org.assertj.core.version} - test - 3.6.1 - 3.9.0 1.11 diff --git a/guava-modules/guava-collections-list/pom.xml b/guava-modules/guava-collections-list/pom.xml index 30d684d673..1b989e79b0 100644 --- a/guava-modules/guava-collections-list/pom.xml +++ b/guava-modules/guava-collections-list/pom.xml @@ -26,13 +26,6 @@ ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - - org.hamcrest java-hamcrest @@ -55,7 +48,6 @@ 4.1 - 3.6.1 2.0.0.0 diff --git a/guava-modules/guava-collections-set/pom.xml b/guava-modules/guava-collections-set/pom.xml index bd58645adc..49bfc46ee2 100644 --- a/guava-modules/guava-collections-set/pom.xml +++ b/guava-modules/guava-collections-set/pom.xml @@ -13,23 +13,8 @@ 0.0.1-SNAPSHOT - - - - org.assertj - assertj-core - ${assertj.version} - test - - - guava-collections-set - - - 3.6.1 - - \ No newline at end of file diff --git a/guava-modules/guava-collections/pom.xml b/guava-modules/guava-collections/pom.xml index 91e3efcd8c..7929283616 100644 --- a/guava-modules/guava-collections/pom.xml +++ b/guava-modules/guava-collections/pom.xml @@ -31,13 +31,6 @@ ${jool.version} - - org.assertj - assertj-core - ${assertj.version} - test - - org.hamcrest java-hamcrest @@ -61,7 +54,6 @@ 4.1 0.9.12 - 3.6.1 2.0.0.0 diff --git a/guava-modules/guava-core/pom.xml b/guava-modules/guava-core/pom.xml index 2540ac97a7..dd68fef43a 100644 --- a/guava-modules/guava-core/pom.xml +++ b/guava-modules/guava-core/pom.xml @@ -19,13 +19,6 @@ commons-lang3 ${commons-lang3.version} - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -38,9 +31,4 @@ - - - 3.6.1 - - \ No newline at end of file diff --git a/guava-modules/guava-utilities/pom.xml b/guava-modules/guava-utilities/pom.xml index debf014ac7..ab849072a5 100644 --- a/guava-modules/guava-utilities/pom.xml +++ b/guava-modules/guava-utilities/pom.xml @@ -19,13 +19,6 @@ commons-lang3 ${commons-lang3.version} - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -38,9 +31,4 @@ - - - 3.6.1 - - \ No newline at end of file diff --git a/jackson-modules/jackson-annotations/pom.xml b/jackson-modules/jackson-annotations/pom.xml index bdc131c867..56fd6cf2fa 100644 --- a/jackson-modules/jackson-annotations/pom.xml +++ b/jackson-modules/jackson-annotations/pom.xml @@ -25,12 +25,6 @@ ${rest-assured.version} test - - org.assertj - assertj-core - ${assertj.version} - test - @@ -44,7 +38,6 @@ - 3.11.0 3.1.1 diff --git a/jackson-modules/jackson-conversions-2/pom.xml b/jackson-modules/jackson-conversions-2/pom.xml index a498c8b4f8..7e994fb52b 100644 --- a/jackson-modules/jackson-conversions-2/pom.xml +++ b/jackson-modules/jackson-conversions-2/pom.xml @@ -32,12 +32,6 @@ jackson-dataformat-csv ${jackson.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -50,8 +44,4 @@ - - 3.11.0 - - \ No newline at end of file diff --git a/jackson-modules/jackson/pom.xml b/jackson-modules/jackson/pom.xml index a4aecfa3de..9df0f40874 100644 --- a/jackson-modules/jackson/pom.xml +++ b/jackson-modules/jackson/pom.xml @@ -48,12 +48,6 @@ ${rest-assured.version} test - - org.assertj - assertj-core - ${assertj.version} - test - @@ -69,7 +63,6 @@ 3.1.1 - 3.11.0 \ No newline at end of file diff --git a/jackson-simple/pom.xml b/jackson-simple/pom.xml index ae8e380b33..f71cb1ffbf 100644 --- a/jackson-simple/pom.xml +++ b/jackson-simple/pom.xml @@ -21,13 +21,6 @@ jackson-dataformat-xml ${jackson.version} - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -40,9 +33,4 @@ - - - 3.11.0 - - \ No newline at end of file diff --git a/java-collections-conversions-2/pom.xml b/java-collections-conversions-2/pom.xml index cd4366e87c..694b416169 100644 --- a/java-collections-conversions-2/pom.xml +++ b/java-collections-conversions-2/pom.xml @@ -16,12 +16,6 @@ - - org.assertj - assertj-core - 3.17.2 - test - org.apache.commons commons-lang3 diff --git a/java-collections-maps-3/pom.xml b/java-collections-maps-3/pom.xml index 0cdf24e31b..6f724ab5ef 100644 --- a/java-collections-maps-3/pom.xml +++ b/java-collections-maps-3/pom.xml @@ -22,12 +22,6 @@ ${spring.version} test - - org.assertj - assertj-core - ${assertj.version} - test - org.apache.commons commons-collections4 @@ -37,7 +31,6 @@ 4.1 - 3.6.1 5.2.5.RELEASE diff --git a/java-numbers-3/pom.xml b/java-numbers-3/pom.xml index e8e080c4c0..68c2ac98de 100644 --- a/java-numbers-3/pom.xml +++ b/java-numbers-3/pom.xml @@ -30,12 +30,6 @@ ${commons-lang3.version} test - - org.assertj - assertj-core - ${assertj.version} - test - @@ -51,7 +45,6 @@ 2.6.0 0.10.2 - 3.6.1 \ No newline at end of file diff --git a/java-numbers-4/pom.xml b/java-numbers-4/pom.xml index dbd6ac456a..9b2e799840 100644 --- a/java-numbers-4/pom.xml +++ b/java-numbers-4/pom.xml @@ -25,12 +25,6 @@ ${commons-lang3.version} test - - org.assertj - assertj-core - ${assertj.version} - test - @@ -45,7 +39,6 @@ 0.10.2 - 3.6.1 \ No newline at end of file diff --git a/java-numbers/pom.xml b/java-numbers/pom.xml index 8bab655f73..c06bc48c5d 100644 --- a/java-numbers/pom.xml +++ b/java-numbers/pom.xml @@ -31,12 +31,6 @@ decimal4j ${decimal4j.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -51,7 +45,6 @@ 1.0.3 - 3.6.1 \ No newline at end of file diff --git a/json-2/pom.xml b/json-2/pom.xml index b4301c41e5..591b7c0883 100644 --- a/json-2/pom.xml +++ b/json-2/pom.xml @@ -24,12 +24,6 @@ jsoniter ${jsoniter.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.squareup.moshi moshi @@ -147,7 +141,6 @@ 0.9.23 - 3.11.1 1.9.2 diff --git a/json/pom.xml b/json/pom.xml index 260b2d1ad9..2919a3a4ee 100644 --- a/json/pom.xml +++ b/json/pom.xml @@ -68,12 +68,6 @@ ${commons-collections4.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -85,7 +79,6 @@ 20171018 2.8.5 1.1.2 - 3.11.1 \ No newline at end of file diff --git a/ksqldb/pom.xml b/ksqldb/pom.xml index 2f92419d6e..ee4906090f 100644 --- a/ksqldb/pom.xml +++ b/ksqldb/pom.xml @@ -39,12 +39,6 @@ ${awaitility.version} test - - org.assertj - assertj-core - ${assertj.version} - test - org.testcontainers testcontainers @@ -61,7 +55,6 @@ 6.2.0 - 3.20.2 4.1.0 1.15.3 diff --git a/language-interop/pom.xml b/language-interop/pom.xml index f2b0a08969..57dd8bdd9a 100644 --- a/language-interop/pom.xml +++ b/language-interop/pom.xml @@ -24,12 +24,6 @@ commons-exec ${commons-exec.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -49,7 +43,6 @@ 2.7.2 1.3 - 3.6.1 \ No newline at end of file diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml index 0988ed454e..409363111a 100644 --- a/libraries-2/pom.xml +++ b/libraries-2/pom.xml @@ -39,11 +39,6 @@ parallel-collectors ${parallel-collectors.version} - - org.assertj - assertj-core - ${assertj.version} - io.github.classgraph classgraph @@ -128,7 +123,6 @@ 3.0.7 - 3.6.2 4.8.28 6.0.0.Final 3.9.6 diff --git a/libraries-4/pom.xml b/libraries-4/pom.xml index b16d1f216f..7d19f6d504 100644 --- a/libraries-4/pom.xml +++ b/libraries-4/pom.xml @@ -73,11 +73,6 @@ vavr ${vavr.version} - - org.assertj - assertj-core - ${assertj.version} - org.pcollections pcollections @@ -117,7 +112,6 @@ 2.5 3.2.0-m7 0.9.0 - 3.6.2 2.1.2 3.0.0 0.6.5 diff --git a/libraries-5/pom.xml b/libraries-5/pom.xml index a3ca204995..63d1924852 100644 --- a/libraries-5/pom.xml +++ b/libraries-5/pom.xml @@ -17,11 +17,6 @@ spring-web ${spring.version} - - org.assertj - assertj-core - ${assertj.version} - org.jooq jool @@ -119,7 +114,6 @@ 3.5.0 0.9.12 4.3.8.RELEASE - 3.6.2 2.11 2.5.11 0.6.5 diff --git a/libraries-6/pom.xml b/libraries-6/pom.xml index cf2c2c551d..accf5f3a9a 100644 --- a/libraries-6/pom.xml +++ b/libraries-6/pom.xml @@ -74,11 +74,6 @@ commons-net ${commons-net.version} - - org.assertj - assertj-core - ${assertj.version} - commons-io commons-io @@ -148,7 +143,6 @@ 0.12.1 1.15 3.6 - 3.6.2 3.5-beta72 3.0 1.8.1 diff --git a/libraries-apache-commons-collections/pom.xml b/libraries-apache-commons-collections/pom.xml index e2805552e3..2cb73babe6 100644 --- a/libraries-apache-commons-collections/pom.xml +++ b/libraries-apache-commons-collections/pom.xml @@ -24,17 +24,10 @@ ${org.hamcrest.java-hamcrest.version} test - - org.assertj - assertj-core - ${assertj.version} - test - 4.1 - 3.6.2 2.0.0.0 diff --git a/libraries-apache-commons/pom.xml b/libraries-apache-commons/pom.xml index 8fa55c1b0e..9bf6c40e19 100644 --- a/libraries-apache-commons/pom.xml +++ b/libraries-apache-commons/pom.xml @@ -13,11 +13,6 @@ - - org.assertj - assertj-core - ${assertj.version} - commons-beanutils commons-beanutils @@ -69,7 +64,6 @@ 1.1 1.9.3 1.2 - 3.6.2 1.6 3.5.2 3.6.1 diff --git a/libraries-data-2/pom.xml b/libraries-data-2/pom.xml index 75b2cc962d..b69d9808c4 100644 --- a/libraries-data-2/pom.xml +++ b/libraries-data-2/pom.xml @@ -96,11 +96,6 @@ derive4j ${derive4j.version} - - org.assertj - assertj-core - ${assertj.version} - org.slf4j slf4j-api @@ -160,7 +155,6 @@ 4.3.8.RELEASE 4.0.0 1.1.0 - 3.6.2 3.0.0 2.8.4 29.0-jre diff --git a/libraries-data-io/pom.xml b/libraries-data-io/pom.xml index 1335ba54d1..713c4342d1 100644 --- a/libraries-data-io/pom.xml +++ b/libraries-data-io/pom.xml @@ -95,12 +95,6 @@ protobuf-java ${google-protobuf.version} - - org.assertj - assertj-core - ${org.assertj.core.version} - test - @@ -110,7 +104,6 @@ 4.1 1.23.0 v4-rev493-1.21.0 - 3.9.0 3.3.5 2.1 2.8.7 diff --git a/libraries-http/pom.xml b/libraries-http/pom.xml index a00bb4bd39..0ee5f4b290 100644 --- a/libraries-http/pom.xml +++ b/libraries-http/pom.xml @@ -13,11 +13,6 @@ - - org.assertj - assertj-core - ${assertj.version} - com.squareup.okhttp3 @@ -116,7 +111,6 @@ 2.8.5 4.5.3 - 3.6.2 4.9.1 1.23.0 2.2.0 diff --git a/libraries-server/pom.xml b/libraries-server/pom.xml index 954f666785..66d6295f7c 100644 --- a/libraries-server/pom.xml +++ b/libraries-server/pom.xml @@ -19,12 +19,6 @@ org.eclipse.paho.client.mqttv3 ${eclipse.paho.client.mqttv3.version} - - - org.assertj - assertj-core - ${assertj.version} - org.eclipse.jetty jetty-server @@ -96,7 +90,6 @@ - 3.6.2 4.5.3 9.4.27.v20200227 4.1.20.Final diff --git a/libraries-testing/pom.xml b/libraries-testing/pom.xml index d7b4a88369..d62d094f08 100644 --- a/libraries-testing/pom.xml +++ b/libraries-testing/pom.xml @@ -118,11 +118,6 @@ ${spring-mock-mvc.version} test - - org.assertj - assertj-core - ${assertj.version} - org.hamcrest @@ -147,12 +142,6 @@ ${h2.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - net.bytebuddy byte-buddy @@ -206,7 +195,6 @@ 0.8.1 4.3.8.RELEASE 4.1.1 - 3.14.0 2.0.0.0 1.4.200 2.7.0 diff --git a/libraries/pom.xml b/libraries/pom.xml index b2e429ff65..b0a0aa22ea 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -45,12 +45,6 @@ javassist ${javaassist.version} - - - org.assertj - assertj-core - ${assertj.version} - org.javers javers-core @@ -272,7 +266,6 @@ 0.7.0 3.2.7 1.2 - 3.6.2 3.1.0 2.92 1.9.26 diff --git a/persistence-modules/core-java-persistence/pom.xml b/persistence-modules/core-java-persistence/pom.xml index 96f8cef310..efef12a525 100644 --- a/persistence-modules/core-java-persistence/pom.xml +++ b/persistence-modules/core-java-persistence/pom.xml @@ -22,12 +22,6 @@ ${postgresql.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -62,7 +56,6 @@ 1.4.200 - 3.10.0 2.4.0 3.2.0 0.9.5.2 diff --git a/persistence-modules/hibernate-enterprise/pom.xml b/persistence-modules/hibernate-enterprise/pom.xml index 1d9ebfc156..18d1a4f3a6 100644 --- a/persistence-modules/hibernate-enterprise/pom.xml +++ b/persistence-modules/hibernate-enterprise/pom.xml @@ -19,12 +19,6 @@ hibernate-core ${hibernate.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -87,7 +81,6 @@ 5.3.7.Final 6.0.6 2.2.3 - 3.8.0 0.9 2.3.4 diff --git a/persistence-modules/hibernate-jpa/pom.xml b/persistence-modules/hibernate-jpa/pom.xml index 85bfdac07f..7779a85e79 100644 --- a/persistence-modules/hibernate-jpa/pom.xml +++ b/persistence-modules/hibernate-jpa/pom.xml @@ -45,12 +45,6 @@ spring-boot-starter-test ${spring-boot.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -92,7 +86,6 @@ 5.3.7.Final 8.0.13 2.2.3 - 3.8.0 2.1.7.RELEASE diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml index 7d552b262d..81f084e102 100644 --- a/persistence-modules/hibernate-libraries/pom.xml +++ b/persistence-modules/hibernate-libraries/pom.xml @@ -62,12 +62,6 @@ ${hibernate.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - mysql mysql-connector-java @@ -166,7 +160,6 @@ - 3.15.0 1.6 29.0-jre 2.9.7 diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index 805402951e..9661c3fd4c 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -29,12 +29,6 @@ hibernate-types-52 ${hibernate-types.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -77,7 +71,6 @@ 5.4.12.Final 2.10.4 - 3.8.0 6.0.16.Final 3.0.1-b11 1.0.3 diff --git a/persistence-modules/hibernate-queries/pom.xml b/persistence-modules/hibernate-queries/pom.xml index 83b2ea4d00..20c2da9ea9 100644 --- a/persistence-modules/hibernate-queries/pom.xml +++ b/persistence-modules/hibernate-queries/pom.xml @@ -19,12 +19,6 @@ hibernate-core ${hibernate.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -60,7 +54,6 @@ 6.0.6 2.2.3 - 3.8.0 \ No newline at end of file diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml index d46d2c16d4..6bec0d4981 100644 --- a/persistence-modules/hibernate5/pom.xml +++ b/persistence-modules/hibernate5/pom.xml @@ -19,12 +19,6 @@ hibernate-core ${hibernate.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -66,7 +60,6 @@ 5.4.12.Final 6.0.6 2.2.3 - 3.8.0 \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/pom.xml b/persistence-modules/java-jpa-2/pom.xml index 26895f3a87..884142f821 100644 --- a/persistence-modules/java-jpa-2/pom.xml +++ b/persistence-modules/java-jpa-2/pom.xml @@ -58,12 +58,6 @@ querydsl-jpa ${querydsl.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -139,7 +133,6 @@ 5.4.14.Final 2.7.4 2.2 - 3.11.1 3.5.1 3.3.3 3.0.0 diff --git a/persistence-modules/java-jpa-3/pom.xml b/persistence-modules/java-jpa-3/pom.xml index 0eb4b8075d..b67b8bf608 100644 --- a/persistence-modules/java-jpa-3/pom.xml +++ b/persistence-modules/java-jpa-3/pom.xml @@ -62,12 +62,6 @@ ${postgresql.version} runtime - - org.assertj - assertj-core - ${assertj.version} - test - org.testcontainers postgresql @@ -94,7 +88,6 @@ 2.7.4 8.0.21 2.2 - 3.11.1 3.5.1 3.3.3 3.0.0 diff --git a/persistence-modules/jpa-hibernate-cascade-type/pom.xml b/persistence-modules/jpa-hibernate-cascade-type/pom.xml index 467fe11bc3..fd0ae117c7 100644 --- a/persistence-modules/jpa-hibernate-cascade-type/pom.xml +++ b/persistence-modules/jpa-hibernate-cascade-type/pom.xml @@ -17,12 +17,6 @@ hibernate-core ${hibernate.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -48,7 +42,6 @@ 5.4.3.Final - 3.12.2 6.0.17.Final 3.0.0 3.0.1-b11 diff --git a/persistence-modules/spring-jpa/pom.xml b/persistence-modules/spring-jpa/pom.xml index 1dca2baa98..c0324e9efd 100644 --- a/persistence-modules/spring-jpa/pom.xml +++ b/persistence-modules/spring-jpa/pom.xml @@ -98,11 +98,6 @@ guava ${guava.version} - - org.assertj - assertj-core - ${assertj.version} - org.apache.commons @@ -132,7 +127,6 @@ 2.2.5 21.0 - 3.8.0 \ No newline at end of file diff --git a/persistence-modules/spring-mybatis/pom.xml b/persistence-modules/spring-mybatis/pom.xml index 1a55e76900..4eda66e1a9 100644 --- a/persistence-modules/spring-mybatis/pom.xml +++ b/persistence-modules/spring-mybatis/pom.xml @@ -64,12 +64,6 @@ ${org.springframework.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -90,8 +84,6 @@ 3.5.2 2.1.0 1.4.197 - - 3.8.0 \ No newline at end of file From f4c9afe7275adf98b6f1a5b3fac7d55d45716f8f Mon Sep 17 00:00:00 2001 From: vunamtien Date: Thu, 18 Nov 2021 19:25:27 +0700 Subject: [PATCH 39/78] BAEL-5193 Compare strings while ignoring whitespace (#11455) * BAEL-5193-compare-strings-ignoring-whitespace * refactor * refactor Co-authored-by: tienvn4 --- .../core-java-string-operations-4/pom.xml | 12 ++++++++ .../CompareIgnoreSpacesUnitTest.java | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/comparestrings/CompareIgnoreSpacesUnitTest.java diff --git a/core-java-modules/core-java-string-operations-4/pom.xml b/core-java-modules/core-java-string-operations-4/pom.xml index ea6bdcd849..ce6119cbbe 100644 --- a/core-java-modules/core-java-string-operations-4/pom.xml +++ b/core-java-modules/core-java-string-operations-4/pom.xml @@ -32,6 +32,16 @@ opencsv ${opencsv.version} + + org.springframework + spring-core + ${spring-core.version} + + + org.apache.commons + commons-lang3 + ${apache-commons-lang3.version} + @@ -53,6 +63,8 @@ 3.6.1 31.0.1-jre 4.1 + 5.3.13 + 3.12.0 diff --git a/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/comparestrings/CompareIgnoreSpacesUnitTest.java b/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/comparestrings/CompareIgnoreSpacesUnitTest.java new file mode 100644 index 0000000000..570ceb1598 --- /dev/null +++ b/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/comparestrings/CompareIgnoreSpacesUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.comparestrings; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class CompareIgnoreSpacesUnitTest { + + private static String normalString = "ABCDEF"; + private static String stringWithSpaces = " AB CD EF "; + + @Test + public void givenTwoStrings_thenCompareWithReplaceAllMethod() { + assertEquals(normalString.replaceAll("\\s+",""), stringWithSpaces.replaceAll("\\s+","")); + } + + @Test + public void givenTwoStrings_thenCompareWithApacheStringUtils() { + assertEquals(StringUtils.deleteWhitespace(normalString), StringUtils.deleteWhitespace(stringWithSpaces)); + } + + @Test + public void givenTwoStrings_thenCompareWithSpringStringUtils() { + assertEquals(org.springframework.util.StringUtils.trimAllWhitespace(normalString), org.springframework.util.StringUtils.trimAllWhitespace(stringWithSpaces)); + } + +} From b978d68efb9adb228427932942c799a947b37566 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 14:03:13 +0100 Subject: [PATCH 40/78] JAVA-8436: Remove AssertJ depenendency from the child modules - part 4 --- core-java-modules/core-java-11-2/pom.xml | 7 ------- core-java-modules/core-java-11/pom.xml | 7 ------- core-java-modules/core-java-12/pom.xml | 7 ------- core-java-modules/core-java-13/pom.xml | 10 ---------- core-java-modules/core-java-14/pom.xml | 10 ---------- core-java-modules/core-java-15/pom.xml | 7 ------- core-java-modules/core-java-16/pom.xml | 7 ------- core-java-modules/core-java-17/pom.xml | 10 ---------- core-java-modules/core-java-8-2/pom.xml | 7 ------- core-java-modules/core-java-8-datetime-2/pom.xml | 8 -------- core-java-modules/core-java-8-datetime/pom.xml | 8 -------- core-java-modules/core-java-8/pom.xml | 9 --------- .../core-java-9-improvements/pom.xml | 8 -------- .../core-java-9-new-features/pom.xml | 8 -------- core-java-modules/core-java-9/pom.xml | 8 -------- core-java-modules/core-java-annotations/pom.xml | 13 ------------- core-java-modules/core-java-arrays-guides/pom.xml | 10 ---------- .../core-java-arrays-operations-advanced/pom.xml | 10 ---------- .../core-java-arrays-operations-basic/pom.xml | 7 ------- .../core-java-arrays-sorting/pom.xml | 8 -------- core-java-modules/core-java-char/pom.xml | 10 ---------- core-java-modules/core-java-collections-2/pom.xml | 7 ------- core-java-modules/core-java-collections-3/pom.xml | 7 ------- core-java-modules/core-java-collections-4/pom.xml | 13 ------------- .../core-java-collections-array-list/pom.xml | 7 ------- .../core-java-collections-list-2/pom.xml | 7 ------- .../core-java-collections-list-3/pom.xml | 7 ------- .../core-java-collections-list/pom.xml | 7 ------- .../core-java-collections-maps-2/pom.xml | 7 ------- .../core-java-collections-maps/pom.xml | 7 ------- core-java-modules/core-java-collections/pom.xml | 10 ---------- .../core-java-concurrency-advanced-2/pom.xml | 10 ---------- .../core-java-concurrency-advanced-3/pom.xml | 7 ------- .../core-java-concurrency-advanced/pom.xml | 9 --------- .../core-java-concurrency-basic/pom.xml | 8 -------- .../core-java-concurrency-collections-2/pom.xml | 8 -------- .../core-java-concurrency-collections/pom.xml | 14 -------------- .../core-java-date-operations-1/pom.xml | 9 +-------- .../core-java-date-operations-2/pom.xml | 7 ------- .../core-java-datetime-conversion/pom.xml | 9 --------- .../core-java-datetime-string/pom.xml | 9 --------- core-java-modules/core-java-exceptions-2/pom.xml | 12 ------------ core-java-modules/core-java-exceptions-3/pom.xml | 9 --------- core-java-modules/core-java-exceptions/pom.xml | 9 --------- core-java-modules/core-java-function/pom.xml | 15 --------------- core-java-modules/core-java-io-2/pom.xml | 8 -------- core-java-modules/core-java-io-3/pom.xml | 11 ----------- core-java-modules/core-java-io-4/pom.xml | 11 ----------- core-java-modules/core-java-io-apis/pom.xml | 11 ----------- core-java-modules/core-java-io/pom.xml | 9 --------- core-java-modules/core-java-jar/pom.xml | 9 --------- core-java-modules/core-java-jndi/pom.xml | 7 ------- core-java-modules/core-java-jvm-2/pom.xml | 7 ------- core-java-modules/core-java-jvm/pom.xml | 8 -------- core-java-modules/core-java-lang-2/pom.xml | 7 ------- core-java-modules/core-java-lang-3/pom.xml | 10 ---------- core-java-modules/core-java-lang-math-2/pom.xml | 7 ------- core-java-modules/core-java-lang-math/pom.xml | 15 --------------- .../core-java-lang-oop-constructors/pom.xml | 13 ------------- .../core-java-lang-oop-inheritance/pom.xml | 13 ------------- .../core-java-lang-oop-methods/pom.xml | 7 ------- .../core-java-lang-oop-modifiers/pom.xml | 10 ---------- .../core-java-lang-oop-patterns/pom.xml | 7 ------- .../core-java-lang-operators-2/pom.xml | 12 ------------ .../core-java-lang-operators/pom.xml | 12 ------------ core-java-modules/core-java-lang-syntax/pom.xml | 12 ------------ core-java-modules/core-java-networking-3/pom.xml | 7 ------- core-java-modules/core-java-nio-2/pom.xml | 13 ------------- core-java-modules/core-java-optional/pom.xml | 7 ------- core-java-modules/core-java-os/pom.xml | 10 ---------- core-java-modules/core-java-reflection/pom.xml | 9 --------- core-java-modules/core-java-regex-2/pom.xml | 13 ------------- core-java-modules/core-java-regex/pom.xml | 10 ---------- core-java-modules/core-java-security-2/pom.xml | 10 ---------- core-java-modules/core-java-security-3/pom.xml | 10 ---------- .../core-java-security-algorithms/pom.xml | 10 ---------- core-java-modules/core-java-security/pom.xml | 15 --------------- core-java-modules/core-java-serialization/pom.xml | 13 ------------- core-java-modules/core-java-streams-2/pom.xml | 7 ------- core-java-modules/core-java-streams-3/pom.xml | 9 --------- core-java-modules/core-java-streams/pom.xml | 10 ---------- .../core-java-string-algorithms-2/pom.xml | 7 ------- .../core-java-string-algorithms-3/pom.xml | 8 -------- .../core-java-string-algorithms/pom.xml | 7 ------- .../core-java-string-conversions-2/pom.xml | 7 ------- .../core-java-string-conversions/pom.xml | 8 -------- .../core-java-string-operations-2/pom.xml | 7 ------- .../core-java-string-operations-3/pom.xml | 7 ------- .../core-java-string-operations-4/pom.xml | 7 ------- .../core-java-string-operations/pom.xml | 7 ------- core-java-modules/core-java-strings/pom.xml | 7 ------- core-java-modules/core-java-sun/pom.xml | 10 ---------- .../core-java-time-measurements/pom.xml | 10 ---------- core-java-modules/core-java-uuid/pom.xml | 7 ------- core-java-modules/core-java/pom.xml | 9 --------- core-java-modules/multimodulemavenproject/pom.xml | 12 ------------ 96 files changed, 1 insertion(+), 871 deletions(-) diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml index 2b7b042c61..332b24ff2e 100644 --- a/core-java-modules/core-java-11-2/pom.xml +++ b/core-java-modules/core-java-11-2/pom.xml @@ -20,12 +20,6 @@ guava ${guava.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.mock-server mockserver-junit-jupiter @@ -87,7 +81,6 @@ 11 11 29.0-jre - 3.17.2 5.11.1 3.0.0 3.0.0 diff --git a/core-java-modules/core-java-11/pom.xml b/core-java-modules/core-java-11/pom.xml index d3ffb0a8f0..fc61e373ec 100644 --- a/core-java-modules/core-java-11/pom.xml +++ b/core-java-modules/core-java-11/pom.xml @@ -21,12 +21,6 @@ guava ${guava.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.openjdk.jmh jmh-core @@ -103,7 +97,6 @@ 11 11 27.1-jre - 3.11.1 benchmarks 10.0.0 3.2.4 diff --git a/core-java-modules/core-java-12/pom.xml b/core-java-modules/core-java-12/pom.xml index 516f28fc3a..9f95b1bc3f 100644 --- a/core-java-modules/core-java-12/pom.xml +++ b/core-java-modules/core-java-12/pom.xml @@ -16,12 +16,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - commons-io commons-io @@ -53,7 +47,6 @@ 12 12 - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-13/pom.xml b/core-java-modules/core-java-13/pom.xml index d28618a21a..9e42838971 100644 --- a/core-java-modules/core-java-13/pom.xml +++ b/core-java-modules/core-java-13/pom.xml @@ -16,15 +16,6 @@ 1.0.0-SNAPSHOT - - - org.assertj - assertj-core - ${assertj.version} - test - - - @@ -52,7 +43,6 @@ 13 13 - 3.6.1 3.0.0-M3 diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml index 3967ce3455..35ea0bd2d0 100644 --- a/core-java-modules/core-java-14/pom.xml +++ b/core-java-modules/core-java-14/pom.xml @@ -14,15 +14,6 @@ 1.0.0-SNAPSHOT - - - org.assertj - assertj-core - ${assertj.version} - test - - - @@ -49,7 +40,6 @@ 14 - 3.6.1 3.8.1 3.0.0-M3 diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index a71987c23a..8cb6c2410d 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -21,12 +21,6 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -55,7 +49,6 @@ 15 - 3.17.2 3.8.1 3.0.0-M3 diff --git a/core-java-modules/core-java-16/pom.xml b/core-java-modules/core-java-16/pom.xml index 99952a73d9..4adc3ee6d1 100644 --- a/core-java-modules/core-java-16/pom.xml +++ b/core-java-modules/core-java-16/pom.xml @@ -17,12 +17,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - org.apache.commons commons-lang3 @@ -67,7 +61,6 @@ 16 16 3.0.0-M5 - 3.17.2 \ No newline at end of file diff --git a/core-java-modules/core-java-17/pom.xml b/core-java-modules/core-java-17/pom.xml index 677454a64b..2fe16cad57 100644 --- a/core-java-modules/core-java-17/pom.xml +++ b/core-java-modules/core-java-17/pom.xml @@ -16,15 +16,6 @@ ../../ - - - org.assertj - assertj-core - ${assertj.version} - test - - - @@ -63,7 +54,6 @@ 17 17 3.0.0-M5 - 3.17.2 \ No newline at end of file diff --git a/core-java-modules/core-java-8-2/pom.xml b/core-java-modules/core-java-8-2/pom.xml index af26289db8..7db1e1ed4e 100644 --- a/core-java-modules/core-java-8-2/pom.xml +++ b/core-java-modules/core-java-8-2/pom.xml @@ -20,17 +20,10 @@ icu4j ${icu.version} - - org.assertj - assertj-core - ${assertj.version} - test - 64.2 - 3.12.2 \ No newline at end of file diff --git a/core-java-modules/core-java-8-datetime-2/pom.xml b/core-java-modules/core-java-8-datetime-2/pom.xml index e662ba400c..9e54b0ee12 100644 --- a/core-java-modules/core-java-8-datetime-2/pom.xml +++ b/core-java-modules/core-java-8-datetime-2/pom.xml @@ -25,12 +25,6 @@ joda-time ${joda-time.version} - - org.assertj - assertj-core - ${assertj.version} - test - log4j log4j @@ -63,8 +57,6 @@ 1.8 1.8 2.10 - - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-8-datetime/pom.xml b/core-java-modules/core-java-8-datetime/pom.xml index f58557df7f..01ec6c0b76 100644 --- a/core-java-modules/core-java-8-datetime/pom.xml +++ b/core-java-modules/core-java-8-datetime/pom.xml @@ -25,12 +25,6 @@ joda-time ${joda-time.version} - - org.assertj - assertj-core - ${assertj.version} - test - log4j log4j @@ -64,8 +58,6 @@ 1.8 1.8 2.10 - - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-8/pom.xml b/core-java-modules/core-java-8/pom.xml index 987ba2e568..85e289280b 100644 --- a/core-java-modules/core-java-8/pom.xml +++ b/core-java-modules/core-java-8/pom.xml @@ -31,13 +31,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -53,8 +46,6 @@ 4.1 - - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-9-improvements/pom.xml b/core-java-modules/core-java-9-improvements/pom.xml index 6abdd7dab8..e6c596937b 100644 --- a/core-java-modules/core-java-9-improvements/pom.xml +++ b/core-java-modules/core-java-9-improvements/pom.xml @@ -21,12 +21,6 @@ ${awaitility.version} test - - org.assertj - assertj-core - ${assertj.version} - test - com.google.guava guava @@ -68,8 +62,6 @@ - - 3.10.0 1.7.0 1.9 1.9 diff --git a/core-java-modules/core-java-9-new-features/pom.xml b/core-java-modules/core-java-9-new-features/pom.xml index 7dca8d5f88..ce90a0f04a 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -20,12 +20,6 @@ rxjava ${rxjava.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.junit.platform junit-platform-runner @@ -156,8 +150,6 @@ 3.0.0 - - 3.10.0 4.0.2 1.9 1.9 diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index d4d58085c8..03a097e7a9 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -21,12 +21,6 @@ ${awaitility.version} test - - org.assertj - assertj-core - ${assertj.version} - test - com.google.guava guava @@ -78,8 +72,6 @@ - - 3.10.0 1.7.0 1.9 1.9 diff --git a/core-java-modules/core-java-annotations/pom.xml b/core-java-modules/core-java-annotations/pom.xml index 7e87678159..a1f84ab563 100644 --- a/core-java-modules/core-java-annotations/pom.xml +++ b/core-java-modules/core-java-annotations/pom.xml @@ -14,15 +14,6 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - core-java-annotations @@ -32,9 +23,5 @@ - - - 3.10.0 - \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml index 0c8b680c1b..d22f6b4d7d 100644 --- a/core-java-modules/core-java-arrays-guides/pom.xml +++ b/core-java-modules/core-java-arrays-guides/pom.xml @@ -24,16 +24,6 @@ jmh-generator-annprocess ${jmh-generator.version} - - org.assertj - assertj-core - ${assertj.version} - test - - - 3.19.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-advanced/pom.xml b/core-java-modules/core-java-arrays-operations-advanced/pom.xml index 50830eba2a..cbcd6ae440 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml +++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml @@ -19,12 +19,6 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - org.openjdk.jmh jmh-core @@ -64,8 +58,4 @@ - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-basic/pom.xml b/core-java-modules/core-java-arrays-operations-basic/pom.xml index 382cee102d..6517b2efb9 100644 --- a/core-java-modules/core-java-arrays-operations-basic/pom.xml +++ b/core-java-modules/core-java-arrays-operations-basic/pom.xml @@ -30,12 +30,6 @@ jmh-generator-annprocess ${jmh-generator.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -67,7 +61,6 @@ 3.2.0 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-sorting/pom.xml b/core-java-modules/core-java-arrays-sorting/pom.xml index e9946d46ed..97ff95e92b 100644 --- a/core-java-modules/core-java-arrays-sorting/pom.xml +++ b/core-java-modules/core-java-arrays-sorting/pom.xml @@ -36,13 +36,6 @@ jmh-generator-annprocess ${jmh-generator.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -75,7 +68,6 @@ 3.2.0 28.2-jre - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-char/pom.xml b/core-java-modules/core-java-char/pom.xml index 009197a1d0..7dc0923fb5 100644 --- a/core-java-modules/core-java-char/pom.xml +++ b/core-java-modules/core-java-char/pom.xml @@ -15,12 +15,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - org.openjdk.jmh jmh-core @@ -33,8 +27,4 @@ - - 3.11.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-collections-2/pom.xml b/core-java-modules/core-java-collections-2/pom.xml index 0f1f1ee2fe..23100b1d87 100644 --- a/core-java-modules/core-java-collections-2/pom.xml +++ b/core-java-modules/core-java-collections-2/pom.xml @@ -34,12 +34,6 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.junit.platform junit-platform-runner @@ -51,7 +45,6 @@ 7.1.0 4.1 - 3.11.1 1.3 diff --git a/core-java-modules/core-java-collections-3/pom.xml b/core-java-modules/core-java-collections-3/pom.xml index 4ca4bda1ee..6ef8e3c81a 100644 --- a/core-java-modules/core-java-collections-3/pom.xml +++ b/core-java-modules/core-java-collections-3/pom.xml @@ -25,12 +25,6 @@ jmh-core ${jmh-core.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.apache.commons commons-lang3 @@ -39,7 +33,6 @@ - 3.11.1 0.10 diff --git a/core-java-modules/core-java-collections-4/pom.xml b/core-java-modules/core-java-collections-4/pom.xml index d86b04644c..2193b5118a 100644 --- a/core-java-modules/core-java-collections-4/pom.xml +++ b/core-java-modules/core-java-collections-4/pom.xml @@ -14,17 +14,4 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj.version} - test - - - - - 3.19.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list/pom.xml b/core-java-modules/core-java-collections-array-list/pom.xml index c14e59bac0..ca9c173947 100644 --- a/core-java-modules/core-java-collections-array-list/pom.xml +++ b/core-java-modules/core-java-collections-array-list/pom.xml @@ -20,17 +20,10 @@ commons-collections4 ${commons-collections4.version} - - org.assertj - assertj-core - ${assertj.version} - test - 4.1 - 3.11.1 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list-2/pom.xml b/core-java-modules/core-java-collections-list-2/pom.xml index 51e66fc0c2..7876b19cf9 100644 --- a/core-java-modules/core-java-collections-list-2/pom.xml +++ b/core-java-modules/core-java-collections-list-2/pom.xml @@ -20,12 +20,6 @@ commons-collections4 ${commons-collections4.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.projectlombok lombok @@ -36,7 +30,6 @@ 4.1 - 3.11.1 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list-3/pom.xml b/core-java-modules/core-java-collections-list-3/pom.xml index efe79509c1..9238939df7 100644 --- a/core-java-modules/core-java-collections-list-3/pom.xml +++ b/core-java-modules/core-java-collections-list-3/pom.xml @@ -26,12 +26,6 @@ ${guava.version} compile - - org.assertj - assertj-core - ${assertj.version} - test - net.sf.trove4j trove4j @@ -61,7 +55,6 @@ 4.1 - 3.11.1 3.0.2 8.1.0 1.2.0 diff --git a/core-java-modules/core-java-collections-list/pom.xml b/core-java-modules/core-java-collections-list/pom.xml index ae1e1561c6..b60906d1ba 100644 --- a/core-java-modules/core-java-collections-list/pom.xml +++ b/core-java-modules/core-java-collections-list/pom.xml @@ -25,17 +25,10 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - 4.1 - 3.11.1 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-2/pom.xml b/core-java-modules/core-java-collections-maps-2/pom.xml index 772cf30416..060796fafa 100644 --- a/core-java-modules/core-java-collections-maps-2/pom.xml +++ b/core-java-modules/core-java-collections-maps-2/pom.xml @@ -51,12 +51,6 @@ ${avaitility.version} test - - org.assertj - assertj-core - ${assertj.version} - test - @@ -66,7 +60,6 @@ 8.2.0 0.7.2 8.1.0 - 3.11.1 \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps/pom.xml b/core-java-modules/core-java-collections-maps/pom.xml index 245c4b04bb..66aca9c1b2 100644 --- a/core-java-modules/core-java-collections-maps/pom.xml +++ b/core-java-modules/core-java-collections-maps/pom.xml @@ -20,17 +20,10 @@ commons-collections4 ${commons-collections4.version} - - org.assertj - assertj-core - ${assertj.version} - test - 4.1 - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-collections/pom.xml b/core-java-modules/core-java-collections/pom.xml index 8fbc6e8de7..8df0d7cdd3 100644 --- a/core-java-modules/core-java-collections/pom.xml +++ b/core-java-modules/core-java-collections/pom.xml @@ -15,12 +15,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - org.openjdk.jmh jmh-core @@ -33,8 +27,4 @@ - - 3.11.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-advanced-2/pom.xml b/core-java-modules/core-java-concurrency-advanced-2/pom.xml index 93c23ccae7..1f19dc8cca 100644 --- a/core-java-modules/core-java-concurrency-advanced-2/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced-2/pom.xml @@ -30,12 +30,6 @@ jmh-generator-annprocess ${jmh-generator.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -48,8 +42,4 @@ - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-advanced-3/pom.xml b/core-java-modules/core-java-concurrency-advanced-3/pom.xml index 915aa8d912..591e46f505 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced-3/pom.xml @@ -15,12 +15,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - com.jcabi jcabi-aspects @@ -94,7 +88,6 @@ - 3.14.0 1.8 1.8 0.22.6 diff --git a/core-java-modules/core-java-concurrency-advanced/pom.xml b/core-java-modules/core-java-concurrency-advanced/pom.xml index 3c21b49ae5..a026bdb2cd 100644 --- a/core-java-modules/core-java-concurrency-advanced/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced/pom.xml @@ -35,12 +35,6 @@ commons-math3 ${commons-math3.version} - - org.assertj - assertj-core - ${assertj.version} - test - com.jayway.awaitility awaitility @@ -60,13 +54,10 @@ - 21.0 3.6.1 4.1 4.01 - - 3.6.1 1.7.0 diff --git a/core-java-modules/core-java-concurrency-basic/pom.xml b/core-java-modules/core-java-concurrency-basic/pom.xml index 7212a2dcb1..1e3157291a 100644 --- a/core-java-modules/core-java-concurrency-basic/pom.xml +++ b/core-java-modules/core-java-concurrency-basic/pom.xml @@ -20,12 +20,6 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - com.jayway.awaitility awaitility @@ -45,8 +39,6 @@ - - 3.6.1 1.7.0 diff --git a/core-java-modules/core-java-concurrency-collections-2/pom.xml b/core-java-modules/core-java-concurrency-collections-2/pom.xml index 8de0e1bef7..02c046b2ea 100644 --- a/core-java-modules/core-java-concurrency-collections-2/pom.xml +++ b/core-java-modules/core-java-concurrency-collections-2/pom.xml @@ -29,18 +29,10 @@ jmh-generator-annprocess ${jmh-generator.version} - - org.assertj - assertj-core - ${assertj.version} - test - 28.2-jre - - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-collections/pom.xml b/core-java-modules/core-java-concurrency-collections/pom.xml index f22da1c848..8b8d2fe03b 100644 --- a/core-java-modules/core-java-concurrency-collections/pom.xml +++ b/core-java-modules/core-java-concurrency-collections/pom.xml @@ -14,15 +14,6 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj.version} - test - - - core-java-concurrency-collections @@ -33,9 +24,4 @@ - - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index 8a13163ba4..ea9f94fa56 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -25,12 +25,7 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - + com.darwinsys hirondelle-date4j @@ -62,8 +57,6 @@ 2.10 - - 3.6.1 RELEASE 1.9 1.9 diff --git a/core-java-modules/core-java-date-operations-2/pom.xml b/core-java-modules/core-java-date-operations-2/pom.xml index 1d283851ca..f60c7b7fc0 100644 --- a/core-java-modules/core-java-date-operations-2/pom.xml +++ b/core-java-modules/core-java-date-operations-2/pom.xml @@ -30,18 +30,11 @@ hirondelle-date4j ${hirondelle-date4j.version} - - org.assertj - assertj-core - ${assertj.version} - test - 2.10 1.5.1 - 3.14.0 \ No newline at end of file diff --git a/core-java-modules/core-java-datetime-conversion/pom.xml b/core-java-modules/core-java-datetime-conversion/pom.xml index 8f082e2793..6e9aeaf5af 100644 --- a/core-java-modules/core-java-datetime-conversion/pom.xml +++ b/core-java-modules/core-java-datetime-conversion/pom.xml @@ -31,13 +31,6 @@ log4j ${log4j.version} - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -63,8 +56,6 @@ 2.10 - - 3.6.1 1.9 1.9 diff --git a/core-java-modules/core-java-datetime-string/pom.xml b/core-java-modules/core-java-datetime-string/pom.xml index a65659be71..2b3c2edb02 100644 --- a/core-java-modules/core-java-datetime-string/pom.xml +++ b/core-java-modules/core-java-datetime-string/pom.xml @@ -31,13 +31,6 @@ log4j ${log4j.version} - - - org.assertj - assertj-core - ${assertj.version} - test - joda-time joda-time @@ -76,8 +69,6 @@ 1.6 2.10.10 RELEASE - - 3.6.1 1.9 1.9 diff --git a/core-java-modules/core-java-exceptions-2/pom.xml b/core-java-modules/core-java-exceptions-2/pom.xml index d952683a64..9103672cd4 100644 --- a/core-java-modules/core-java-exceptions-2/pom.xml +++ b/core-java-modules/core-java-exceptions-2/pom.xml @@ -15,13 +15,6 @@ - - - org.assertj - assertj-core - ${assertj-core.version} - test - org.apache.commons commons-lang3 @@ -29,9 +22,4 @@ - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml index ffc21799ce..18dc52932e 100644 --- a/core-java-modules/core-java-exceptions-3/pom.xml +++ b/core-java-modules/core-java-exceptions-3/pom.xml @@ -22,18 +22,9 @@ ${h2.version} test - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - 3.10.0 1.4.191 diff --git a/core-java-modules/core-java-exceptions/pom.xml b/core-java-modules/core-java-exceptions/pom.xml index d5581279b5..f1f60120a5 100644 --- a/core-java-modules/core-java-exceptions/pom.xml +++ b/core-java-modules/core-java-exceptions/pom.xml @@ -32,19 +32,10 @@ commons-lang3 ${commons-lang3.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - 1.5.0-b01 - - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-function/pom.xml b/core-java-modules/core-java-function/pom.xml index cc44ba5a7c..a3add5a686 100644 --- a/core-java-modules/core-java-function/pom.xml +++ b/core-java-modules/core-java-function/pom.xml @@ -14,16 +14,6 @@ 0.0.1-SNAPSHOT - - - - org.assertj - assertj-core - ${assertj.version} - test - - - core-java-function @@ -34,9 +24,4 @@ - - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-io-2/pom.xml b/core-java-modules/core-java-io-2/pom.xml index 924248f4f9..800756767c 100644 --- a/core-java-modules/core-java-io-2/pom.xml +++ b/core-java-modules/core-java-io-2/pom.xml @@ -38,13 +38,6 @@ log4j-over-slf4j ${org.slf4j.version} - - - org.assertj - assertj-core - ${assertj.version} - test - com.github.tomakehurst @@ -76,7 +69,6 @@ - 3.6.1 3.0.0-M1 2.26.3 diff --git a/core-java-modules/core-java-io-3/pom.xml b/core-java-modules/core-java-io-3/pom.xml index 017b56f03f..7af90dbab9 100644 --- a/core-java-modules/core-java-io-3/pom.xml +++ b/core-java-modules/core-java-io-3/pom.xml @@ -38,17 +38,6 @@ log4j-over-slf4j ${org.slf4j.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/pom.xml b/core-java-modules/core-java-io-4/pom.xml index 0501bb4a66..9fc00ff586 100644 --- a/core-java-modules/core-java-io-4/pom.xml +++ b/core-java-modules/core-java-io-4/pom.xml @@ -32,17 +32,6 @@ log4j-over-slf4j ${org.slf4j.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-io-apis/pom.xml b/core-java-modules/core-java-io-apis/pom.xml index f2a574ed89..fab2bff959 100644 --- a/core-java-modules/core-java-io-apis/pom.xml +++ b/core-java-modules/core-java-io-apis/pom.xml @@ -32,13 +32,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -51,8 +44,4 @@ - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index a036818226..7de29ac23c 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -15,13 +15,6 @@ - - - org.assertj - assertj-core - ${assertj.version} - test - org.hsqldb hsqldb @@ -132,8 +125,6 @@ - - 3.6.1 3.0.0-M1 2.4.0 diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index 3c5a1b35bf..da107c745f 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -49,13 +49,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj-core.version} - test - org.javamoney moneta @@ -376,8 +369,6 @@ 0.4 1.8.7 - - 3.10.0 1.1 3.0.0-M1 diff --git a/core-java-modules/core-java-jndi/pom.xml b/core-java-modules/core-java-jndi/pom.xml index f971623bc2..68b7f9361f 100644 --- a/core-java-modules/core-java-jndi/pom.xml +++ b/core-java-modules/core-java-jndi/pom.xml @@ -47,12 +47,6 @@ ${apacheds.version} test - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -71,7 +65,6 @@ 5.0.9.RELEASE 1.4.199 - 3.21.0 2.0.0.AM26 1.8 1.8 diff --git a/core-java-modules/core-java-jvm-2/pom.xml b/core-java-modules/core-java-jvm-2/pom.xml index b34aac5a78..60a2795116 100644 --- a/core-java-modules/core-java-jvm-2/pom.xml +++ b/core-java-modules/core-java-jvm-2/pom.xml @@ -15,12 +15,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - org.openjdk.jol jol-core @@ -39,7 +33,6 @@ - 3.6.1 0.10 0.10.2 31.0.1-jre diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index 38cb1a7825..c47765e43d 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -20,12 +20,6 @@ commons-lang3 ${commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.javassist javassist @@ -66,8 +60,6 @@ - 3.6.1 - 3.27.0-GA 1.8.0 0.10 diff --git a/core-java-modules/core-java-lang-2/pom.xml b/core-java-modules/core-java-lang-2/pom.xml index d1a8d68075..f155f2abaf 100644 --- a/core-java-modules/core-java-lang-2/pom.xml +++ b/core-java-modules/core-java-lang-2/pom.xml @@ -45,12 +45,6 @@ jmh-core ${jmh-core.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -64,7 +58,6 @@ - 3.12.2 1.9.4 29.0-jre diff --git a/core-java-modules/core-java-lang-3/pom.xml b/core-java-modules/core-java-lang-3/pom.xml index 0eda5dd16b..92c724826c 100644 --- a/core-java-modules/core-java-lang-3/pom.xml +++ b/core-java-modules/core-java-lang-3/pom.xml @@ -15,12 +15,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - com.google.guava guava @@ -45,8 +39,4 @@ - - 3.12.2 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/pom.xml b/core-java-modules/core-java-lang-math-2/pom.xml index 4411d313db..4057429896 100644 --- a/core-java-modules/core-java-lang-math-2/pom.xml +++ b/core-java-modules/core-java-lang-math-2/pom.xml @@ -44,12 +44,6 @@ guava ${guava.version} - - org.assertj - assertj-core - ${org.assertj.core.version} - test - com.github.dpaukov combinatoricslib3 @@ -65,7 +59,6 @@ 3.6.1 - 3.9.0 27.0.1-jre 3.3.0 0.38 diff --git a/core-java-modules/core-java-lang-math/pom.xml b/core-java-modules/core-java-lang-math/pom.xml index 2cc9b90fa4..37550b67d8 100644 --- a/core-java-modules/core-java-lang-math/pom.xml +++ b/core-java-modules/core-java-lang-math/pom.xml @@ -14,16 +14,6 @@ 0.0.1-SNAPSHOT - - - - org.assertj - assertj-core - ${assertj.version} - test - - - core-java-lang-math @@ -34,9 +24,4 @@ - - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-constructors/pom.xml b/core-java-modules/core-java-lang-oop-constructors/pom.xml index 5635059fa9..061b3c08de 100644 --- a/core-java-modules/core-java-lang-oop-constructors/pom.xml +++ b/core-java-modules/core-java-lang-oop-constructors/pom.xml @@ -13,17 +13,4 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-inheritance/pom.xml b/core-java-modules/core-java-lang-oop-inheritance/pom.xml index e0272fb94e..4fc7e14d84 100644 --- a/core-java-modules/core-java-lang-oop-inheritance/pom.xml +++ b/core-java-modules/core-java-lang-oop-inheritance/pom.xml @@ -13,17 +13,4 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-methods/pom.xml b/core-java-modules/core-java-lang-oop-methods/pom.xml index 938b457872..e57b51b7bd 100644 --- a/core-java-modules/core-java-lang-oop-methods/pom.xml +++ b/core-java-modules/core-java-lang-oop-methods/pom.xml @@ -24,12 +24,6 @@ commons-lang ${commons-lang.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - nl.jqno.equalsverifier equalsverifier @@ -40,7 +34,6 @@ 1.18.12 - 3.10.0 3.0.3 diff --git a/core-java-modules/core-java-lang-oop-modifiers/pom.xml b/core-java-modules/core-java-lang-oop-modifiers/pom.xml index 70c70608eb..109a87c41e 100644 --- a/core-java-modules/core-java-lang-oop-modifiers/pom.xml +++ b/core-java-modules/core-java-lang-oop-modifiers/pom.xml @@ -14,12 +14,6 @@ - - org.assertj - assertj-core - ${assertj-core.version} - test - com.h2database h2 @@ -28,8 +22,4 @@ - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-patterns/pom.xml b/core-java-modules/core-java-lang-oop-patterns/pom.xml index 8b8b4a7b46..4b89584def 100644 --- a/core-java-modules/core-java-lang-oop-patterns/pom.xml +++ b/core-java-modules/core-java-lang-oop-patterns/pom.xml @@ -29,17 +29,10 @@ gson ${gson.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - 2.8.2 - 3.10.0 \ No newline at end of file diff --git a/core-java-modules/core-java-lang-operators-2/pom.xml b/core-java-modules/core-java-lang-operators-2/pom.xml index 1779b7384c..724dad95ee 100644 --- a/core-java-modules/core-java-lang-operators-2/pom.xml +++ b/core-java-modules/core-java-lang-operators-2/pom.xml @@ -21,13 +21,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -40,9 +33,4 @@ - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-operators/pom.xml b/core-java-modules/core-java-lang-operators/pom.xml index 63f42917b8..c61fb81354 100644 --- a/core-java-modules/core-java-lang-operators/pom.xml +++ b/core-java-modules/core-java-lang-operators/pom.xml @@ -21,13 +21,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -40,9 +33,4 @@ - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-lang-syntax/pom.xml b/core-java-modules/core-java-lang-syntax/pom.xml index da7d56de7b..7cdbc40fbc 100644 --- a/core-java-modules/core-java-lang-syntax/pom.xml +++ b/core-java-modules/core-java-lang-syntax/pom.xml @@ -26,13 +26,6 @@ log4j-over-slf4j ${org.slf4j.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -45,9 +38,4 @@ - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-networking-3/pom.xml b/core-java-modules/core-java-networking-3/pom.xml index 2fd97ef831..ee822e57cb 100644 --- a/core-java-modules/core-java-networking-3/pom.xml +++ b/core-java-modules/core-java-networking-3/pom.xml @@ -29,12 +29,6 @@ tomcat-embed-core ${tomcat.embeded.version} - - org.assertj - assertj-core - ${assertj.version} - test - com.sun.mail javax.mail @@ -76,7 +70,6 @@ 5.2.8.RELEASE 9.4.31.v20200723 10.0.0-M7 - 3.11.1 5.3.3 1.32 0.17 diff --git a/core-java-modules/core-java-nio-2/pom.xml b/core-java-modules/core-java-nio-2/pom.xml index 9d5e267b46..eb56c2bf68 100644 --- a/core-java-modules/core-java-nio-2/pom.xml +++ b/core-java-modules/core-java-nio-2/pom.xml @@ -14,17 +14,4 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj.version} - test - - - - - 3.6.1 - - \ No newline at end of file diff --git a/core-java-modules/core-java-optional/pom.xml b/core-java-modules/core-java-optional/pom.xml index dd5217df74..d04763598d 100644 --- a/core-java-modules/core-java-optional/pom.xml +++ b/core-java-modules/core-java-optional/pom.xml @@ -56,18 +56,11 @@ ${rest-assured.version} test - - org.assertj - assertj-core - ${assertj.version} - test - 5.4.0.Final 27.1-jre - 3.10.0 3.1.1 diff --git a/core-java-modules/core-java-os/pom.xml b/core-java-modules/core-java-os/pom.xml index c0eac46db8..970c8a562a 100644 --- a/core-java-modules/core-java-os/pom.xml +++ b/core-java-modules/core-java-os/pom.xml @@ -35,13 +35,6 @@ log4j ${log4j.version} - - - org.assertj - assertj-core - ${assertj.version} - test - org.unix4j unix4j-command @@ -76,11 +69,8 @@ - 4.1 4.01 - - 3.6.1 1.8.9 1.9 1.9 diff --git a/core-java-modules/core-java-reflection/pom.xml b/core-java-modules/core-java-reflection/pom.xml index 32777e228f..1706bf3c45 100644 --- a/core-java-modules/core-java-reflection/pom.xml +++ b/core-java-modules/core-java-reflection/pom.xml @@ -14,14 +14,6 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj-core.version} - - - core-java-reflection @@ -45,7 +37,6 @@ - 3.10.0 1.8 1.8 diff --git a/core-java-modules/core-java-regex-2/pom.xml b/core-java-modules/core-java-regex-2/pom.xml index a47c0ff357..ae9385e63c 100644 --- a/core-java-modules/core-java-regex-2/pom.xml +++ b/core-java-modules/core-java-regex-2/pom.xml @@ -14,17 +14,4 @@ 0.0.1-SNAPSHOT - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - - - 3.15.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-regex/pom.xml b/core-java-modules/core-java-regex/pom.xml index 3fb63fb42a..93f3ae3cdb 100644 --- a/core-java-modules/core-java-regex/pom.xml +++ b/core-java-modules/core-java-regex/pom.xml @@ -25,12 +25,6 @@ jmh-generator-annprocess ${jmh-core.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -43,8 +37,4 @@ - - 3.15.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-security-2/pom.xml b/core-java-modules/core-java-security-2/pom.xml index 8de12c0c46..7a354ee9e2 100644 --- a/core-java-modules/core-java-security-2/pom.xml +++ b/core-java-modules/core-java-security-2/pom.xml @@ -25,13 +25,6 @@ bcprov-jdk15on ${bouncycastle.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - javax.xml.bind @@ -41,11 +34,8 @@ - 1.60 1.11 - - 3.18.0 2.3.1 diff --git a/core-java-modules/core-java-security-3/pom.xml b/core-java-modules/core-java-security-3/pom.xml index a0e73a1e29..3cd546e697 100644 --- a/core-java-modules/core-java-security-3/pom.xml +++ b/core-java-modules/core-java-security-3/pom.xml @@ -25,13 +25,6 @@ bcprov-jdk15on ${bouncycastle.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - javax.xml.bind @@ -41,11 +34,8 @@ - 1.60 1.11 - - 3.18.0 2.3.1 diff --git a/core-java-modules/core-java-security-algorithms/pom.xml b/core-java-modules/core-java-security-algorithms/pom.xml index db1bf09ead..967ddc103e 100644 --- a/core-java-modules/core-java-security-algorithms/pom.xml +++ b/core-java-modules/core-java-security-algorithms/pom.xml @@ -25,13 +25,6 @@ bcprov-jdk15on ${bouncycastle.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - javax.xml.bind @@ -41,11 +34,8 @@ - 1.60 1.11 - - 3.18.0 2.3.1 diff --git a/core-java-modules/core-java-security/pom.xml b/core-java-modules/core-java-security/pom.xml index daba990776..b36de5ac4c 100644 --- a/core-java-modules/core-java-security/pom.xml +++ b/core-java-modules/core-java-security/pom.xml @@ -14,19 +14,4 @@ 0.0.1-SNAPSHOT - - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - - - - 3.10.0 - - \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml index 754dcd434b..0ce5785fd9 100644 --- a/core-java-modules/core-java-serialization/pom.xml +++ b/core-java-modules/core-java-serialization/pom.xml @@ -43,13 +43,6 @@ log4j-over-slf4j ${org.slf4j.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - org.springframework spring-core @@ -177,16 +170,10 @@ - 0.4 1.8.7 - - 3.10.0 - 1.1 3.0.0-M1 - - 4.3.20.RELEASE diff --git a/core-java-modules/core-java-streams-2/pom.xml b/core-java-modules/core-java-streams-2/pom.xml index 08b82bcc11..c8fa83c55a 100644 --- a/core-java-modules/core-java-streams-2/pom.xml +++ b/core-java-modules/core-java-streams-2/pom.xml @@ -30,18 +30,11 @@ log4j ${log4j.version} - - org.assertj - assertj-core - ${assertj.version} - test - 1.9 1.9 - 3.11.1 \ No newline at end of file diff --git a/core-java-modules/core-java-streams-3/pom.xml b/core-java-modules/core-java-streams-3/pom.xml index 6ace96fc4d..c2dfdc392b 100644 --- a/core-java-modules/core-java-streams-3/pom.xml +++ b/core-java-modules/core-java-streams-3/pom.xml @@ -37,13 +37,6 @@ ${jmh-generator.version} test - - - org.assertj - assertj-core - ${assertj.version} - test - @@ -75,8 +68,6 @@ 1.18.20 - - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-streams/pom.xml b/core-java-modules/core-java-streams/pom.xml index 4862672c8a..a6bb827e77 100644 --- a/core-java-modules/core-java-streams/pom.xml +++ b/core-java-modules/core-java-streams/pom.xml @@ -43,13 +43,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj.version} - test - com.codepoetics protonpack @@ -105,14 +98,11 @@ - 0.9.0 1.15 0.6.5 2.10 1.3 - - 3.11.1 1.8.9 3.1 1.8 diff --git a/core-java-modules/core-java-string-algorithms-2/pom.xml b/core-java-modules/core-java-string-algorithms-2/pom.xml index 4b0d55508f..9fbe10865d 100644 --- a/core-java-modules/core-java-string-algorithms-2/pom.xml +++ b/core-java-modules/core-java-string-algorithms-2/pom.xml @@ -35,12 +35,6 @@ jmh-generator-annprocess ${jmh-generator.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.bitbucket.cowwoc diff-match-patch @@ -60,7 +54,6 @@ - 3.6.1 1.2 diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index 88a3029cf1..6700e9ba95 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -14,13 +14,6 @@ - - - org.assertj - assertj-core - ${assertj.version} - test - com.google.guava guava @@ -56,7 +49,6 @@ - 3.6.1 28.1-jre 1.7 diff --git a/core-java-modules/core-java-string-algorithms/pom.xml b/core-java-modules/core-java-string-algorithms/pom.xml index 9fea569b29..07018c7694 100644 --- a/core-java-modules/core-java-string-algorithms/pom.xml +++ b/core-java-modules/core-java-string-algorithms/pom.xml @@ -45,12 +45,6 @@ emoji-java ${emoji-java.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -66,7 +60,6 @@ 27.0.1-jre 0.4.0 - 3.6.1 4.0.0 diff --git a/core-java-modules/core-java-string-conversions-2/pom.xml b/core-java-modules/core-java-string-conversions-2/pom.xml index 3e03f4c016..f97443d9ca 100644 --- a/core-java-modules/core-java-string-conversions-2/pom.xml +++ b/core-java-modules/core-java-string-conversions-2/pom.xml @@ -41,12 +41,6 @@ commons-text ${commons-text.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -61,7 +55,6 @@ 64.2 - 3.12.2 1.9 30.1.1-jre diff --git a/core-java-modules/core-java-string-conversions/pom.xml b/core-java-modules/core-java-string-conversions/pom.xml index 1047e3e7c3..148f04101f 100644 --- a/core-java-modules/core-java-string-conversions/pom.xml +++ b/core-java-modules/core-java-string-conversions/pom.xml @@ -35,13 +35,6 @@ guava ${guava.version} - - - org.assertj - assertj-core - ${assertj.version} - test - org.hamcrest hamcrest @@ -62,7 +55,6 @@ 61.1 - 3.6.1 \ No newline at end of file diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml index db8f78da70..0d31486759 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -66,12 +66,6 @@ commons-codec ${commons-codec.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -108,7 +102,6 @@ - 3.6.1 2.0.0.Final 28.2-jre 6.0.2.Final diff --git a/core-java-modules/core-java-string-operations-3/pom.xml b/core-java-modules/core-java-string-operations-3/pom.xml index 2567f776b1..1b1237a8c3 100644 --- a/core-java-modules/core-java-string-operations-3/pom.xml +++ b/core-java-modules/core-java-string-operations-3/pom.xml @@ -26,12 +26,6 @@ commons-lang3 ${apache-commons-lang3.version} - - org.assertj - assertj-core - ${assertj.version} - test - org.apache.maven maven-artifact @@ -82,7 +76,6 @@ 11 11 - 3.6.1 5.3.9 3.12.0 31.0.1-jre diff --git a/core-java-modules/core-java-string-operations-4/pom.xml b/core-java-modules/core-java-string-operations-4/pom.xml index ea6bdcd849..d0e5ae29d5 100644 --- a/core-java-modules/core-java-string-operations-4/pom.xml +++ b/core-java-modules/core-java-string-operations-4/pom.xml @@ -16,12 +16,6 @@ - - org.assertj - assertj-core - ${assertj.version} - test - com.google.guava guava @@ -50,7 +44,6 @@ 11 11 - 3.6.1 31.0.1-jre 4.1 diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml index 67ce43277e..20e4df3ba3 100644 --- a/core-java-modules/core-java-string-operations/pom.xml +++ b/core-java-modules/core-java-string-operations/pom.xml @@ -40,12 +40,6 @@ commons-codec ${commons-codec.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -59,7 +53,6 @@ - 3.6.1 1.15 diff --git a/core-java-modules/core-java-strings/pom.xml b/core-java-modules/core-java-strings/pom.xml index aca0bb3346..d78cb7b92d 100644 --- a/core-java-modules/core-java-strings/pom.xml +++ b/core-java-modules/core-java-strings/pom.xml @@ -36,12 +36,6 @@ icu4j ${icu4j.version} - - org.assertj - assertj-core - ${assertj.version} - test - @@ -55,7 +49,6 @@ - 3.6.1 61.1 15 diff --git a/core-java-modules/core-java-sun/pom.xml b/core-java-modules/core-java-sun/pom.xml index 4c26b59168..e959932235 100644 --- a/core-java-modules/core-java-sun/pom.xml +++ b/core-java-modules/core-java-sun/pom.xml @@ -15,13 +15,6 @@ - - - org.assertj - assertj-core - ${assertj.version} - test - com.sun tools @@ -93,10 +86,7 @@ - - 3.6.1 1.7.0 - 1.8.0 diff --git a/core-java-modules/core-java-time-measurements/pom.xml b/core-java-modules/core-java-time-measurements/pom.xml index d3c351b385..e2924b5278 100644 --- a/core-java-modules/core-java-time-measurements/pom.xml +++ b/core-java-modules/core-java-time-measurements/pom.xml @@ -27,13 +27,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj.version} - test - joda-time joda-time @@ -87,12 +80,9 @@ - 3.6.1 2.10 1.18.12 - - 3.6.1 1.8.9 2.0.7 1.44 diff --git a/core-java-modules/core-java-uuid/pom.xml b/core-java-modules/core-java-uuid/pom.xml index a38306f269..983d0f2ba3 100644 --- a/core-java-modules/core-java-uuid/pom.xml +++ b/core-java-modules/core-java-uuid/pom.xml @@ -25,12 +25,6 @@ log4j-over-slf4j ${org.slf4j.version} - - org.assertj - assertj-core - ${assertj-core.version} - test - @@ -147,7 +141,6 @@ - 3.10.0 3.0.0-M1 diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml index 42262be29a..8d6921b493 100644 --- a/core-java-modules/core-java/pom.xml +++ b/core-java-modules/core-java/pom.xml @@ -49,13 +49,6 @@ ${lombok.version} provided - - - org.assertj - assertj-core - ${assertj-core.version} - test - org.javamoney moneta @@ -185,8 +178,6 @@ 0.4 1.8.7 - - 3.10.0 1.1 3.0.0-M1 diff --git a/core-java-modules/multimodulemavenproject/pom.xml b/core-java-modules/multimodulemavenproject/pom.xml index 79d884cd86..fbafa7ebff 100644 --- a/core-java-modules/multimodulemavenproject/pom.xml +++ b/core-java-modules/multimodulemavenproject/pom.xml @@ -23,17 +23,6 @@ mainappmodule - - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - - @@ -54,7 +43,6 @@ 3.8.0 1.9 1.9 - 3.12.2 \ No newline at end of file From b4836ce7d9fff1a70b5260a03985e6a316368f5c Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Thu, 18 Nov 2021 13:23:25 +0000 Subject: [PATCH 41/78] [JAVA-6455] Remove Lombok --- .../h2db/springboot/models/Country.java | 42 +++++++++++++++++-- .../baeldung/SpringBootH2IntegrationTest.java | 13 +++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java index f0f02c41d3..d6edab9421 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java @@ -1,15 +1,13 @@ package com.baeldung.h2db.springboot.models; -import lombok.Data; - import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; +import java.util.Objects; @Table(name = "countries") @Entity -@Data public class Country { @Id @@ -18,4 +16,42 @@ public class Country { private String name; + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Country country = (Country) o; + return id == country.id && name.equals(country.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + return "Country{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } } diff --git a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java index abdbd76c19..4c11ae6b0d 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java @@ -15,6 +15,8 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = SpringBootH2Application.class) public class SpringBootH2IntegrationTest { + private static final Country AN_EXPECTED_COUNTRY = buildCountry(); + @Autowired private CountryRepository countryRepository; @@ -22,7 +24,16 @@ public class SpringBootH2IntegrationTest { public void givenInitData_whenApplicationStarts_thenDataIsLoaded() { Iterable users = countryRepository.findAll(); - assertThat(users).hasSize(5); + assertThat(users) + .hasSize(5) + .contains(AN_EXPECTED_COUNTRY); + } + + private static Country buildCountry() { + Country c = new Country(); + c.setId(5); + c.setName("Canada"); + return c; } } From d12fe37f47802bd54038ab8afc1108b7dc12a8a1 Mon Sep 17 00:00:00 2001 From: Seshu Kumar T Date: Thu, 18 Nov 2021 23:34:28 +0530 Subject: [PATCH 42/78] Excel Cell Border Example (#11472) Co-authored-by: Seshu Thanneeru --- .../excel/cellstyle/CellBordersHandler.java | 37 +++++ .../cellstyle/CellBorderHandlerUnitTest.java | 130 ++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 apache-poi/src/main/java/com/baeldung/poi/excel/cellstyle/CellBordersHandler.java create mode 100644 apache-poi/src/test/java/com/baeldung/poi/excel/cellstyle/CellBorderHandlerUnitTest.java diff --git a/apache-poi/src/main/java/com/baeldung/poi/excel/cellstyle/CellBordersHandler.java b/apache-poi/src/main/java/com/baeldung/poi/excel/cellstyle/CellBordersHandler.java new file mode 100644 index 0000000000..1c96db0b60 --- /dev/null +++ b/apache-poi/src/main/java/com/baeldung/poi/excel/cellstyle/CellBordersHandler.java @@ -0,0 +1,37 @@ +package com.baeldung.poi.excel.cellstyle; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.RegionUtil; + +public class CellBordersHandler { + + public void setRegionBorder(CellRangeAddress region, Sheet sheet, BorderStyle borderStyle) { + RegionUtil.setBorderTop(borderStyle, region, sheet); + RegionUtil.setBorderBottom(borderStyle, region, sheet); + RegionUtil.setBorderLeft(borderStyle, region, sheet); + RegionUtil.setBorderRight(borderStyle, region, sheet); + } + + public void setRegionBorderWithColor(CellRangeAddress region, Sheet sheet, BorderStyle borderStyle, short color) { + RegionUtil.setTopBorderColor(color, region, sheet); + RegionUtil.setBottomBorderColor(color, region, sheet); + RegionUtil.setLeftBorderColor(color, region, sheet); + RegionUtil.setRightBorderColor(color, region, sheet); + RegionUtil.setBorderTop(borderStyle, region, sheet); + RegionUtil.setBorderBottom(borderStyle, region, sheet); + RegionUtil.setBorderLeft(borderStyle, region, sheet); + RegionUtil.setBorderRight(borderStyle, region, sheet); + } + + public void setCrazyBorder(CellRangeAddress region, Sheet sheet) { + RegionUtil.setTopBorderColor(IndexedColors.RED.index, region, sheet); + RegionUtil.setBottomBorderColor(IndexedColors.GREEN.index, region, sheet); + RegionUtil.setLeftBorderColor(IndexedColors.BLUE.index, region, sheet); + RegionUtil.setRightBorderColor(IndexedColors.VIOLET.index, region, sheet); + RegionUtil.setBorderTop(BorderStyle.DASH_DOT, region, sheet); + RegionUtil.setBorderBottom(BorderStyle.DOUBLE, region, sheet); + RegionUtil.setBorderLeft(BorderStyle.DOTTED, region, sheet); + RegionUtil.setBorderRight(BorderStyle.SLANTED_DASH_DOT, region, sheet); + } +} diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/cellstyle/CellBorderHandlerUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/cellstyle/CellBorderHandlerUnitTest.java new file mode 100644 index 0000000000..3cabff2dff --- /dev/null +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/cellstyle/CellBorderHandlerUnitTest.java @@ -0,0 +1,130 @@ +package com.baeldung.poi.excel.cellstyle; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.*; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Paths; + +import static org.junit.Assert.assertEquals; + +public class CellBorderHandlerUnitTest { + private static final String FILE_NAME = "cellstyle/CellStyleHandlerTest.xlsx"; + private static final int SHEET_INDEX = 0; + + private static CellBordersHandler cellBordersHandler; + private static Workbook workbook; + + @BeforeClass + public static void setup() throws URISyntaxException, IOException { + String fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString(); + cellBordersHandler = new CellBordersHandler(); + workbook = new XSSFWorkbook(fileLocation); + createRowsAndCells(workbook); + } + + private static void createRowsAndCells(Workbook workbook) { + Sheet sheet = workbook.getSheetAt(SHEET_INDEX); + for (int rowIndex = 0; rowIndex < 10; rowIndex++) { + Row row = sheet.getRow(rowIndex); + if (row == null) { + row = sheet.createRow(rowIndex); + } + for (int colIndex = 0; colIndex < 10; colIndex++) { + Cell cell = row.getCell(colIndex); + if (cell == null) { + row.createCell(colIndex); + } + } + } + } + + @Test + public void givenWorkbookCell_whenSetRegionBorder() { + Sheet sheet = workbook.getSheetAt(SHEET_INDEX); + + CellRangeAddress region = new CellRangeAddress(1, 1, 1, 1); + cellBordersHandler.setRegionBorder(region, sheet, BorderStyle.THICK); + + Row row = sheet.getRow(1); + Cell cell = row.getCell(1); + assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getBorderBottom(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getBorderRight(), BorderStyle.THICK); + } + + @Test + public void givenWorkbookCell_whenSetRegionBorderWithColor() { + Sheet sheet = workbook.getSheetAt(SHEET_INDEX); + + CellRangeAddress region = new CellRangeAddress(1, 1, 3, 3); + cellBordersHandler.setRegionBorderWithColor(region, sheet, BorderStyle.THICK, IndexedColors.MAROON.index); + + Row row = sheet.getRow(1); + Cell cell = row.getCell(1 + 2); + assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getBorderBottom(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getBorderRight(), BorderStyle.THICK); + assertEquals(cell.getCellStyle().getTopBorderColor(), IndexedColors.MAROON.index); + assertEquals(cell.getCellStyle().getBottomBorderColor(), IndexedColors.MAROON.index); + assertEquals(cell.getCellStyle().getLeftBorderColor(), IndexedColors.MAROON.index); + assertEquals(cell.getCellStyle().getRightBorderColor(), IndexedColors.MAROON.index); + } + + @Test + public void givenWorkbookCell_whenSetCrazyBorder() { + Sheet sheet = workbook.getSheetAt(SHEET_INDEX); + + CellRangeAddress region = new CellRangeAddress(1, 1, 5, 5); + cellBordersHandler.setCrazyBorder(region, sheet); + + Row row = sheet.getRow(1); + Cell cell = row.getCell(5); + assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.DASH_DOT); + assertEquals(cell.getCellStyle().getBorderBottom(), BorderStyle.DOUBLE); + assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.DOTTED); + assertEquals(cell.getCellStyle().getBorderRight(), BorderStyle.SLANTED_DASH_DOT); + assertEquals(cell.getCellStyle().getTopBorderColor(), IndexedColors.RED.index); + assertEquals(cell.getCellStyle().getBottomBorderColor(), IndexedColors.GREEN.index); + assertEquals(cell.getCellStyle().getLeftBorderColor(), IndexedColors.BLUE.index); + assertEquals(cell.getCellStyle().getRightBorderColor(), IndexedColors.VIOLET.index); + } + + @Test + public void givenWorkbookRegion_whenSetRegionBorder() { + Sheet sheet = workbook.getSheetAt(SHEET_INDEX); + + CellRangeAddress region = new CellRangeAddress(3, 5, 1, 5); + cellBordersHandler.setRegionBorder(region, sheet, BorderStyle.MEDIUM); + + Row row = sheet.getRow(3); + Cell cell = row.getCell(1); + assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.MEDIUM); + assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.MEDIUM); + } + + @Test + public void givenWorkbookRegion_whenSetRegionBorderWithColor() { + Sheet sheet = workbook.getSheetAt(SHEET_INDEX); + + CellRangeAddress region = new CellRangeAddress(7, 8, 1, 5); + cellBordersHandler.setRegionBorderWithColor(region, sheet, BorderStyle.MEDIUM, IndexedColors.ORANGE.index); + + Row row = sheet.getRow(7); + Cell cell = row.getCell(1); + assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.MEDIUM); + assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.MEDIUM); + assertEquals(cell.getCellStyle().getTopBorderColor(), IndexedColors.ORANGE.index); + assertEquals(cell.getCellStyle().getLeftBorderColor(), IndexedColors.ORANGE.index); + } + + @AfterClass + public static void close() throws IOException { + workbook.close(); + } +} From cc76ff346416914461a9489011d1ff92c4e5d976 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 19:29:30 +0100 Subject: [PATCH 43/78] JAVA-8436: Fix unit tests in assertion-libraries --- .../java/com/baeldung/assertj/AssertJConditionUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing-modules/assertion-libraries/src/test/java/com/baeldung/assertj/AssertJConditionUnitTest.java b/testing-modules/assertion-libraries/src/test/java/com/baeldung/assertj/AssertJConditionUnitTest.java index ec2d93500f..4ed7fc3ee0 100644 --- a/testing-modules/assertion-libraries/src/test/java/com/baeldung/assertj/AssertJConditionUnitTest.java +++ b/testing-modules/assertion-libraries/src/test/java/com/baeldung/assertj/AssertJConditionUnitTest.java @@ -25,7 +25,7 @@ public class AssertJConditionUnitTest { assertThat(member).isNot(senior); fail(); } catch (AssertionError e) { - assertThat(e).hasMessageContaining("not to be "); + assertThat(e).hasMessageContaining("not to be senior"); } } @@ -38,7 +38,7 @@ public class AssertJConditionUnitTest { assertThat(member).has(nameJohn); fail(); } catch (AssertionError e) { - assertThat(e).hasMessageContaining(""); + assertThat(e).hasMessageContaining("name John"); } } From eda9dd0b7e87dbdb46c5c55e788c0cbc87124f2c Mon Sep 17 00:00:00 2001 From: priya-soni Date: Fri, 19 Nov 2021 03:34:38 +0530 Subject: [PATCH 44/78] BAEL-5191-JsonNode-Get-All-Keys-From-A-Json-Structure (#11451) * BAEL-5191-JsonNode-Get-All-Keys-From-A-Json-Structure * Added test cases for GetAllKeysFromJSON class methods * Updated test class name --- .../jackson/jsonnode/GetAllKeysFromJSON.java | 172 ++++++++++++++++++ .../jsonnode/GetAllKeysFromJSONUnitTest.java | 56 ++++++ 2 files changed, 228 insertions(+) create mode 100644 jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java create mode 100644 jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java diff --git a/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java b/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java new file mode 100644 index 0000000000..d740b457af --- /dev/null +++ b/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java @@ -0,0 +1,172 @@ +package com.baeldung.jackson.jsonnode; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; + +public class GetAllKeysFromJSON { + + public static List getKeysInJsonUsingMaps(String json, ObjectMapper mapper) { + List keys = new ArrayList<>(); + + try { + Map jsonElements = mapper.readValue(json, new TypeReference>() { + }); + getAllKeys(jsonElements, keys); + return keys; + + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return keys; + } + + public static void getAllKeys(Map jsonElements, List keys) { + + jsonElements.entrySet() + .forEach(entry -> { + keys.add(entry.getKey()); + if (entry.getValue() instanceof Map) { + Map map = (Map) entry.getValue(); + getAllKeys(map, keys); + } else if (entry.getValue() instanceof List) { + List list = (List) entry.getValue(); + list.forEach(listEntry -> { + if (listEntry instanceof Map) { + Map map = (Map) listEntry; + getAllKeys(map, keys); + } + }); + } + }); + } + + public static List getKeysInJsonUsingJsonNodeFieldNames(String json, ObjectMapper mapper) { + List keys = new ArrayList<>(); + + try { + JsonNode jsonNode = mapper.readTree(json); + Iterator iterator = jsonNode.fieldNames(); + iterator.forEachRemaining(e -> keys.add(e)); + + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return keys; + } + + public static List getAllKeysInJsonUsingJsonNodeFieldNames(String json, ObjectMapper mapper) { + List keys = new ArrayList<>(); + + try { + JsonNode jsonNode = mapper.readTree(json); + getAllKeysUsingJsonNodeFieldNames(jsonNode, keys); + + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return keys; + } + + public static List getAllKeysInJsonUsingJsonNodeFields(String json, ObjectMapper mapper) { + List keys = new ArrayList<>(); + + try { + JsonNode jsonNode = mapper.readTree(json); + getAllKeysUsingJsonNodeFields(jsonNode, keys); + + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return keys; + } + + public static void getAllKeysUsingJsonNodeFields(JsonNode jsonNode, List keys) { + + if (jsonNode.isObject()) { + Iterator> fields = jsonNode.fields(); + + fields.forEachRemaining(field -> { + keys.add(field.getKey()); + getAllKeysUsingJsonNodeFieldNames((JsonNode) field.getValue(), keys); + }); + } else if (jsonNode.isArray()) { + ArrayNode arrayField = (ArrayNode) jsonNode; + arrayField.forEach(node -> { + getAllKeysUsingJsonNodeFieldNames(node, keys); + }); + } + + } + + public static void getAllKeysUsingJsonNodeFieldNames(JsonNode jsonNode, List keys) { + + if (jsonNode.isObject()) { + Iterator fieldNames = jsonNode.fieldNames(); + + fieldNames.forEachRemaining(fieldName -> { + keys.add(fieldName); + getAllKeysUsingJsonNodeFieldNames(jsonNode.get(fieldName), keys); + }); + } else if (jsonNode.isArray()) { + ArrayNode arrayField = (ArrayNode) jsonNode; + arrayField.forEach(node -> { + getAllKeysUsingJsonNodeFieldNames(node, keys); + }); + } + + } + + public static List getKeysInJsonUsingJsonParser(String json, ObjectMapper mapper) { + List keys = new ArrayList<>(); + + try { + JsonNode jsonNode = mapper.readTree(json); + JsonParser jsonParser = jsonNode.traverse(); + while (!jsonParser.isClosed()) { + if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { + keys.add((jsonParser.getCurrentName())); + } + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return keys; + } + + public static List getKeysInJsonUsingJsonParser(String json) { + List keys = new ArrayList<>(); + + try { + JsonFactory factory = new JsonFactory(); + JsonParser jsonParser = factory.createParser(json); + while (!jsonParser.isClosed()) { + if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { + keys.add((jsonParser.getCurrentName())); + } + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return keys; + } +} diff --git a/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java b/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java new file mode 100644 index 0000000000..b547422aad --- /dev/null +++ b/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.jackson.jsonnode; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class GetAllKeysFromJSONUnitTest { + + private static String json = "{\r\n" + " \"Name\":\"Craig\",\r\n" + " \"Age\":10,\r\n" + " \"BookInterests\":[\r\n" + " {\r\n" + " \"Book\":\"The Kite Runner\",\r\n" + " \"Author\":\"Khaled Hosseini\"\r\n" + " },\r\n" + + " {\r\n" + " \"Book\":\"Harry Potter\",\r\n" + " \"Author\":\"J. K. Rowling\"\r\n" + " }\r\n" + " ],\r\n" + " \"FoodInterests\":{\r\n" + " \"Breakfast\":[\r\n" + " {\r\n" + + " \"Bread\":\"Whole wheat\",\r\n" + " \"Beverage\":\"Fruit juice\"\r\n" + " },\r\n" + " {\r\n" + " \"Sandwich\":\"Vegetable Sandwich\",\r\n" + " \"Beverage\":\"Coffee\"\r\n" + + " }\r\n" + " ]\r\n" + " }\r\n" + "}"; + + private static ObjectMapper mapper = new ObjectMapper(); + + // Top level keys : [Name, Age, BookInterests, FoodInterests] + // All keys: [Name, Age, BookInterests, Book, Author, Book, Author, FoodInterests, Breakfast, Bread, Beverage, Sandwich, Beverage] + + @Test + public void givenAJsonNode_whenUsingFieldNamesMethod_thenWeGetTopFieldNames() { + List keys = GetAllKeysFromJSON.getKeysInJsonUsingJsonNodeFieldNames(json, mapper); + assertEquals(4, keys.size()); + } + + @Test + public void givenAJsonNode_whenUsingFieldNamesMethodForAllNodes_thenWeGetAllFieldNames() { + List keys = GetAllKeysFromJSON.getAllKeysInJsonUsingJsonNodeFieldNames(json, mapper); + assertEquals(13, keys.size()); + } + + @Test + public void givenAJsonNode_whenUsingFieldsMethod_thenWeGetAllFieldNames() { + List keys = GetAllKeysFromJSON.getAllKeysInJsonUsingJsonNodeFields(json, mapper); + assertEquals(13, keys.size()); + } + + @Test + public void givenAJsonNode_whenUsingJsonParserMethod_thenWeGetAllFieldNames() { + List keys = GetAllKeysFromJSON.getKeysInJsonUsingJsonParser(json, mapper); + assertEquals(13, keys.size()); + + keys = GetAllKeysFromJSON.getKeysInJsonUsingJsonParser(json); + assertEquals(13, keys.size()); + } + + @Test + public void givenAJsonNode_whenUsingMaps_thenWeGetAllFieldNames() { + List keys = GetAllKeysFromJSON.getKeysInJsonUsingMaps(json, mapper); + assertEquals(13, keys.size()); + } + +} From 662d474478b1992b98d5f26f997169080d10f296 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 18 Nov 2021 23:17:00 +0100 Subject: [PATCH 45/78] JAVA-8436: Upgrade AssertJ Guava to 3.4.0 --- testing-modules/assertion-libraries/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/assertion-libraries/pom.xml b/testing-modules/assertion-libraries/pom.xml index b5cfd711d2..ea9a37afaf 100644 --- a/testing-modules/assertion-libraries/pom.xml +++ b/testing-modules/assertion-libraries/pom.xml @@ -77,7 +77,7 @@ 0.32 - 3.1.0 + 3.4.0 2.1.0 1.4.13 0.12 From 44d10f5e9485f6cfa6f10a3970b168f41dc9f30f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 19 Nov 2021 13:37:18 +0800 Subject: [PATCH 46/78] Update README.md --- spring-boot-modules/spring-boot-runtime/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-runtime/README.md b/spring-boot-modules/spring-boot-runtime/README.md index 6f21efe793..94822af09e 100644 --- a/spring-boot-modules/spring-boot-runtime/README.md +++ b/spring-boot-modules/spring-boot-runtime/README.md @@ -10,3 +10,4 @@ This module contains articles about administering a Spring Boot runtime - [Project Configuration with Spring](https://www.baeldung.com/project-configuration-with-spring) - [Spring – Log Incoming Requests](https://www.baeldung.com/spring-http-logging) - [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat) + - [Max-HTTP-Header-Size in Spring Boot 2](https://www.baeldung.com/spring-boot-max-http-header-size) From a62c0f3c8bc30625e98425efb0f90c331a6cabd2 Mon Sep 17 00:00:00 2001 From: chaos2418 <> Date: Thu, 18 Nov 2021 11:19:23 +0530 Subject: [PATCH 47/78] JAVA-8405: reducing logging for tutorials-build-job --- .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../exceptions/LambdaExceptionWrappers.java | 11 +++-- .../MethodReferenceUnitTest.java | 8 +-- .../java/com/baeldung/generics/Building.java | 2 +- .../java/com/baeldung/generics/House.java | 2 +- .../baeldung/initializationguide/User.java | 13 +++-- .../java/com/baeldung/loops/LoopsInJava.java | 13 +++-- .../switchstatement/SwitchStatement.java | 10 +++- .../com/baeldung/loops/LoopsUnitTest.java | 23 ++++++--- jta/src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ logback-config.xml | 12 +++++ .../lazyinitialization/HibernateUtil.java | 2 +- .../transientobject/HibernateUtil.java | 2 +- .../interceptors/CustomInterceptor.java | 4 +- .../hibernate/interceptors/entity/User.java | 3 +- .../hibernate/hilo/HibernateHiloUnitTest.java | 6 +-- .../proxy/HibernateProxyUnitTest.java | 3 ++ .../test/resources/hibernate-hilo.properties | 2 +- .../hibernate-interceptors.properties | 2 +- .../resources/hibernate-lifecycle.properties | 2 +- .../hibernate-namingstrategy.properties | 2 +- .../hibernate-persistjson.properties | 2 +- .../src/test/resources/hibernate.properties | 2 +- .../src/test/resources/logback-test.xml | 12 +++++ .../java/com/baeldung/SpringContextTest.java | 2 + .../partialupdate/PartialUpdateUnitTest.java | 2 + .../src/test/resources/logback-test.xml | 13 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ pom.xml | 7 ++- .../src/test/resources/logback-test.xml | 12 +++++ .../backpressure/BackpressureUnitTest.java | 16 +++--- spring-aop/pom.xml | 9 ++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../ehcache/calculator/SquaredCalculator.java | 6 ++- .../ehcache/SquareCalculatorUnitTest.java | 24 ++++++--- .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../src/test/resources/logback-test.xml | 12 +++++ .../BeforeAndAfterAnnotationsUnitTest.java | 8 +-- ...ClassAndAfterClassAnnotationsUnitTest.java | 10 ++-- .../migration/junit4/RuleExampleUnitTest.java | 11 +++-- .../junit4/rules/TraceUnitTestRule.java | 14 ++++-- ...foreAllAndAfterAllAnnotationsUnitTest.java | 8 +-- ...reEachAndAfterEachAnnotationsUnitTest.java | 8 +-- .../migration/junit5/RuleExampleUnitTest.java | 9 ++-- .../junit5/extensions/TraceUnitExtension.java | 8 ++- .../ReadResourceDirectoryUnitTest.java | 11 +++-- .../RegisterExtensionSampleExtension.java | 4 +- .../RepeatedTestAnnotationUnitTest.java | 22 +++++---- .../ConditionalAnnotationsUnitTest.java | 49 ++++++++++++------- .../DisabledOnQAEnvironmentExtension.java | 7 ++- ...eneratorTestInvocationContextProvider.java | 21 ++++++-- .../baeldung/junit/log/BusinessWorker.java | 2 +- 81 files changed, 715 insertions(+), 126 deletions(-) create mode 100644 apache-olingo/olingo2/src/test/resources/logback-test.xml create mode 100644 apache-shiro/src/test/resources/logback-test.xml create mode 100644 jta/src/test/resources/logback-test.xml create mode 100644 kubernetes/k8s-admission-controller/src/test/resources/logback-test.xml create mode 100644 libraries-3/src/test/resources/logback-test.xml create mode 100644 libraries-security/src/test/resources/logback-test.xml create mode 100644 logback-config.xml create mode 100644 persistence-modules/spring-boot-persistence-h2/src/test/resources/logback-test.xml create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/logback-test.xml create mode 100644 persistence-modules/spring-mybatis/src/test/resources/logback-test.xml create mode 100644 persistence-modules/spring-persistence-simple/src/test/resources/logback-test.xml create mode 100644 software-security/sql-injection-samples/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-1/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-data-2/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-properties-2/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/logback-test.xml create mode 100644 spring-boot-modules/spring-boot-validation/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-archaius/basic-config/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-archaius/extra-configs/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-archaius/jdbc-config/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-functions/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/src/test/resources/logback-test.xml create mode 100644 spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/src/test/resources/logback-test.xml create mode 100644 spring-core-5/src/test/resources/logback-test.xml create mode 100644 spring-di-2/src/test/resources/logback-test.xml create mode 100644 spring-security-modules/spring-5-security/src/test/resources/logback-test.xml create mode 100644 spring-security-modules/spring-security-oidc/src/test/resources/logback-test.xml create mode 100644 spring-security-modules/spring-security-web-boot-3/src/test/resources/logback-test.xml create mode 100644 spring-web-modules/spring-boot-jsp/src/test/resources/logback-test.xml create mode 100644 spring-web-modules/spring-mvc-basics/src/test/resources/logback-test.xml create mode 100644 spring-web-modules/spring-mvc-java-2/src/test/resources/logback-test.xml create mode 100644 spring-web-modules/spring-rest-http/src/test/resources/logback-test.xml create mode 100644 spring-web-modules/spring-resttemplate-2/src/test/resources/logback-test.xml create mode 100644 spring-web-modules/spring-thymeleaf-2/src/test/resources/logback-test.xml diff --git a/apache-olingo/olingo2/src/test/resources/logback-test.xml b/apache-olingo/olingo2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/apache-olingo/olingo2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/apache-shiro/src/test/resources/logback-test.xml b/apache-shiro/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/apache-shiro/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java index 64532c8b6f..ce33aaf237 100644 --- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java +++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java @@ -1,15 +1,20 @@ package com.baeldung.java8.lambda.exceptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.function.Consumer; public class LambdaExceptionWrappers { + private static final Logger LOGGER = LoggerFactory.getLogger(LambdaExceptionWrappers.class); + public static Consumer lambdaWrapper(Consumer consumer) { return i -> { try { consumer.accept(i); } catch (ArithmeticException e) { - System.err.println("Arithmetic Exception occured : " + e.getMessage()); + LOGGER.error("Arithmetic Exception occured : {}", e.getMessage()); } }; } @@ -21,7 +26,7 @@ public class LambdaExceptionWrappers { } catch (Exception ex) { try { E exCast = clazz.cast(ex); - System.err.println("Exception occured : " + exCast.getMessage()); + LOGGER.error("Exception occured : {}", exCast.getMessage()); } catch (ClassCastException ccEx) { throw ex; } @@ -46,7 +51,7 @@ public class LambdaExceptionWrappers { } catch (Exception ex) { try { E exCast = exceptionClass.cast(ex); - System.err.println("Exception occured : " + exCast.getMessage()); + LOGGER.error("Exception occured : {}", exCast.getMessage()); } catch (ClassCastException ccEx) { throw new RuntimeException(ex); } diff --git a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java index 957294153b..87c01c3ded 100644 --- a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java +++ b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/methodreference/MethodReferenceUnitTest.java @@ -7,14 +7,16 @@ import java.util.function.BiFunction; import org.apache.commons.lang3.StringUtils; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MethodReferenceUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(MethodReferenceUnitTest.class); + private static void doNothingAtAll(Object... o) { } - ; - @Test public void referenceToStaticMethod() { List messages = Arrays.asList("Hello", "Baeldung", "readers!"); @@ -61,7 +63,7 @@ public class MethodReferenceUnitTest { @Test public void limitationsAndAdditionalExamples() { - createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize())); + createBicyclesList().forEach(b -> LOGGER.debug("Bike brand is '{}' and frame size is '{}'", b.getBrand(), b.getFrameSize())); createBicyclesList().forEach((o) -> MethodReferenceUnitTest.doNothingAtAll(o)); } diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java index a34dcd3c7e..875b1d0f6d 100644 --- a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/Building.java @@ -7,6 +7,6 @@ public class Building { private static final Logger LOGGER = LoggerFactory.getLogger(Building.class); public void paint() { - LOGGER.info("Painting Building"); + LOGGER.debug("Painting Building"); } } diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java index 88e7d2710a..c1bc6483c4 100644 --- a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/generics/House.java @@ -7,6 +7,6 @@ public class House extends Building { private static final Logger LOGGER = LoggerFactory.getLogger(House.class); public void paint() { - LOGGER.info("Painting House"); + LOGGER.debug("Painting House"); } } diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java index 1d9a872d69..1604f27368 100644 --- a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/initializationguide/User.java @@ -1,8 +1,13 @@ package com.baeldung.initializationguide; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.Serializable; public class User implements Serializable, Cloneable { + + private static final Logger LOGGER = LoggerFactory.getLogger(User.class); private static final long serialVersionUID = 1L; static String forum; private String name; @@ -10,12 +15,12 @@ public class User implements Serializable, Cloneable { { id = 0; - System.out.println("Instance Initializer"); + LOGGER.debug("Instance Initializer"); } static { - forum = "Java"; - System.out.println("Static Initializer"); + forum = "Java"; + LOGGER.debug("Static Initializer"); } public User(String name, int id) { @@ -25,7 +30,7 @@ public class User implements Serializable, Cloneable { } public User() { - System.out.println("Constructor"); + LOGGER.debug("Constructor"); } public String getName() { diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java index 1b2e621b52..cdbcd9e341 100644 --- a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/loops/LoopsInJava.java @@ -1,12 +1,17 @@ package com.baeldung.loops; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class LoopsInJava { + private static final Logger LOGGER = LoggerFactory.getLogger(LoopsInJava.class); + public int[] simple_for_loop() { int[] arr = new int[5]; for (int i = 0; i < 5; i++) { arr[i] = i; - System.out.println("Simple for loop: i - " + i); + LOGGER.debug("Simple for loop: i - " + i); } return arr; } @@ -16,7 +21,7 @@ public class LoopsInJava { int[] arr = new int[5]; for (int num : intArr) { arr[num] = num; - System.out.println("Enhanced for-each loop: i - " + num); + LOGGER.debug("Enhanced for-each loop: i - " + num); } return arr; } @@ -26,7 +31,7 @@ public class LoopsInJava { int[] arr = new int[5]; while (i < 5) { arr[i] = i; - System.out.println("While loop: i - " + i++); + LOGGER.debug("While loop: i - " + i++); } return arr; } @@ -36,7 +41,7 @@ public class LoopsInJava { int[] arr = new int[5]; do { arr[i] = i; - System.out.println("Do-While loop: i - " + i++); + LOGGER.debug("Do-While loop: i - " + i++); } while (i < 5); return arr; } diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java index 69e151bfcb..55b3cbfaaf 100644 --- a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java +++ b/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/switchstatement/SwitchStatement.java @@ -1,7 +1,13 @@ package com.baeldung.switchstatement; +import com.baeldung.loops.LoopsInJava; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class SwitchStatement { + private static final Logger LOGGER = LoggerFactory.getLogger(SwitchStatement.class); + public String exampleOfIF(String animal) { String result; @@ -42,11 +48,11 @@ public class SwitchStatement { switch (animal) { case "DOG": - System.out.println("domestic animal"); + LOGGER.debug("domestic animal"); result = "domestic animal"; default: - System.out.println("unknown animal"); + LOGGER.debug("unknown animal"); result = "unknown animal"; } diff --git a/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/loops/LoopsUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/loops/LoopsUnitTest.java index 5a8b116a2c..354a408af6 100644 --- a/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/loops/LoopsUnitTest.java +++ b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/loops/LoopsUnitTest.java @@ -8,12 +8,16 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import com.baeldung.initializationguide.User; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class LoopsUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(LoopsUnitTest.class); private LoopsInJava loops = new LoopsInJava(); private static List list = new ArrayList<>(); private static Set set = new HashSet<>(); @@ -65,41 +69,44 @@ public class LoopsUnitTest { @Test public void whenUsingSimpleFor_shouldIterateList() { for (int i = 0; i < list.size(); i++) { - System.out.println(list.get(i)); + LOGGER.debug(list.get(i)); } } @Test public void whenUsingEnhancedFor_shouldIterateList() { for (String item : list) { - System.out.println(item); + LOGGER.debug(item); } } @Test public void whenUsingEnhancedFor_shouldIterateSet() { for (String item : set) { - System.out.println(item); + LOGGER.debug(item); } } @Test public void whenUsingEnhancedFor_shouldIterateMap() { for (Entry entry : map.entrySet()) { - System.out.println("Key: " + entry.getKey() + " - " + "Value: " + entry.getValue()); + LOGGER.debug("Key: " + entry.getKey() + " - " + "Value: " + entry.getValue()); } } @Test public void whenUsingSimpleFor_shouldRunLabelledLoop() { - aa: for (int i = 1; i <= 3; i++) { - if (i == 1) + aa: + for (int i = 1; i <= 3; i++) { + if (i == 1) { continue; - bb: for (int j = 1; j <= 3; j++) { + } + bb: + for (int j = 1; j <= 3; j++) { if (i == 2 && j == 2) { break aa; } - System.out.println(i + " " + j); + LOGGER.debug(i + " " + j); } } } diff --git a/jta/src/test/resources/logback-test.xml b/jta/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/jta/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/kubernetes/k8s-admission-controller/src/test/resources/logback-test.xml b/kubernetes/k8s-admission-controller/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/kubernetes/k8s-admission-controller/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/libraries-3/src/test/resources/logback-test.xml b/libraries-3/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/libraries-3/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/libraries-security/src/test/resources/logback-test.xml b/libraries-security/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/libraries-security/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/logback-config.xml b/logback-config.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/logback-config.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java index b84a512fd4..911e3f7540 100644 --- a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java @@ -24,7 +24,7 @@ public class HibernateUtil { settings.put(Environment.USER, "sa"); settings.put(Environment.PASS, ""); settings.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect"); - settings.put(Environment.SHOW_SQL, "true"); + settings.put(Environment.SHOW_SQL, "false"); settings.put(Environment.HBM2DDL_AUTO, "update"); configuration.setProperties(settings); configuration.addAnnotatedClass(User.class); diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/transientobject/HibernateUtil.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/transientobject/HibernateUtil.java index a40279661f..ace9e57d84 100644 --- a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/transientobject/HibernateUtil.java +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/transientobject/HibernateUtil.java @@ -27,7 +27,7 @@ public class HibernateUtil { settings.put(Environment.USER, "sa"); settings.put(Environment.PASS, ""); settings.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect"); - settings.put(Environment.SHOW_SQL, "true"); + settings.put(Environment.SHOW_SQL, "false"); settings.put(Environment.USE_SQL_COMMENTS, "true"); settings.put(Environment.HBM2DDL_AUTO, "update"); configuration.setProperties(settings); diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/CustomInterceptor.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/CustomInterceptor.java index 1d60ccb6c0..24b06f9b65 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/CustomInterceptor.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/CustomInterceptor.java @@ -16,7 +16,7 @@ public class CustomInterceptor extends EmptyInterceptor { @Override public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) { if (entity instanceof User) { - logger.info(((User) entity).toString()); + logger.debug(entity.toString()); } return super.onSave(entity, id, state, propertyNames, types); } @@ -25,7 +25,7 @@ public class CustomInterceptor extends EmptyInterceptor { public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object [] previousState, String[] propertyNames, Type[] types) { if (entity instanceof User) { ((User) entity).setLastModified(new Date()); - logger.info(((User) entity).toString()); + logger.debug(entity.toString()); } return super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types); } diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/entity/User.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/entity/User.java index 2b1dbe702b..b627cefa33 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/entity/User.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/interceptors/entity/User.java @@ -1,7 +1,5 @@ package com.baeldung.hibernate.interceptors.entity; -import java.util.Date; - import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -9,6 +7,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import java.util.Date; @Entity(name = "hbi_user") public class User { diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/hilo/HibernateHiloUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/hilo/HibernateHiloUnitTest.java index 9285c30af5..d0eab565df 100644 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/hilo/HibernateHiloUnitTest.java +++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/hilo/HibernateHiloUnitTest.java @@ -42,9 +42,9 @@ public class HibernateHiloUnitTest { private void configureLogger() { BasicConfigurator.configure(); LogManager.getLogger("org.hibernate").setLevel(Level.ERROR); - LogManager.getLogger("org.hibernate.id.enhanced.SequenceStructure").setLevel(Level.DEBUG); - LogManager.getLogger("org.hibernate.event.internal.AbstractSaveEventListener").setLevel(Level.DEBUG); - LogManager.getLogger("org.hibernate.SQL").setLevel(Level.DEBUG); + LogManager.getLogger("org.hibernate.id.enhanced.SequenceStructure").setLevel(Level.INFO); + LogManager.getLogger("org.hibernate.event.internal.AbstractSaveEventListener").setLevel(Level.INFO); + LogManager.getLogger("org.hibernate.SQL").setLevel(Level.INFO); } diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/proxy/HibernateProxyUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/proxy/HibernateProxyUnitTest.java index 0a4caf032b..217351cd75 100644 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/proxy/HibernateProxyUnitTest.java +++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/proxy/HibernateProxyUnitTest.java @@ -1,5 +1,8 @@ package com.baeldung.hibernate.proxy; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; import org.hibernate.*; import org.hibernate.proxy.HibernateProxy; import org.junit.After; diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-hilo.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-hilo.properties index 60d487c1bd..94f3597f1f 100644 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-hilo.properties +++ b/persistence-modules/hibernate5/src/test/resources/hibernate-hilo.properties @@ -2,7 +2,7 @@ hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:mem:hilo_db;DB_CLOSE_DELAY=-1 hibernate.connection.username=sa hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop hibernate.c3p0.min_size=5 hibernate.c3p0.max_size=20 diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-interceptors.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-interceptors.properties index 58b55d0a09..e5bb5a36a7 100644 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-interceptors.properties +++ b/persistence-modules/hibernate5/src/test/resources/hibernate-interceptors.properties @@ -5,6 +5,6 @@ hibernate.connection.autocommit=true jdbc.password= hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop hibernate.current_session_context_class=org.hibernate.context.internal.ThreadLocalSessionContext \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-lifecycle.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-lifecycle.properties index d043b624f2..1a5e6482bf 100644 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-lifecycle.properties +++ b/persistence-modules/hibernate5/src/test/resources/hibernate-lifecycle.properties @@ -5,5 +5,5 @@ hibernate.connection.password= hibernate.connection.autocommit=true hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.hbm2ddl.auto=validate \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-namingstrategy.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-namingstrategy.properties index f75a35bdfe..263033823c 100644 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-namingstrategy.properties +++ b/persistence-modules/hibernate5/src/test/resources/hibernate-namingstrategy.properties @@ -3,7 +3,7 @@ hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 hibernate.connection.username=sa hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop hibernate.physical_naming_strategy=com.baeldung.hibernate.namingstrategy.CustomPhysicalNamingStrategy diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-persistjson.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-persistjson.properties index 2cf8ac5b63..2481591fca 100644 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-persistjson.properties +++ b/persistence-modules/hibernate5/src/test/resources/hibernate-persistjson.properties @@ -3,5 +3,5 @@ hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 hibernate.connection.username=sa hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate.properties b/persistence-modules/hibernate5/src/test/resources/hibernate.properties index c14782ce0f..42d8e8564f 100644 --- a/persistence-modules/hibernate5/src/test/resources/hibernate.properties +++ b/persistence-modules/hibernate5/src/test/resources/hibernate.properties @@ -5,7 +5,7 @@ hibernate.connection.autocommit=true jdbc.password= hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true +hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop hibernate.c3p0.min_size=5 diff --git a/persistence-modules/spring-boot-persistence-h2/src/test/resources/logback-test.xml b/persistence-modules/spring-boot-persistence-h2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java index eaccf4acba..67ce958c64 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java @@ -3,12 +3,14 @@ package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.boot.Application; @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) +@TestPropertySource(properties = {"spring.jpa.show-sql=false "}) public class SpringContextTest { @Test diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java index 874e18c4ad..e217ef590e 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.partialupdate.model.Customer; @@ -16,6 +17,7 @@ import com.baeldung.partialupdate.service.CustomerService; @RunWith(SpringRunner.class) @SpringBootTest(classes = PartialUpdateApplication.class) +@TestPropertySource(properties = {"spring.jpa.show-sql=false "}) public class PartialUpdateUnitTest { @Autowired diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/logback-test.xml b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..1595326253 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-mybatis/src/test/resources/logback-test.xml b/persistence-modules/spring-mybatis/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/persistence-modules/spring-mybatis/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-persistence-simple/src/test/resources/logback-test.xml b/persistence-modules/spring-persistence-simple/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/persistence-modules/spring-persistence-simple/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 372bc5a9f3..8a853ca1d3 100644 --- a/pom.xml +++ b/pom.xml @@ -289,7 +289,6 @@ default-first - org.apache.maven.plugins maven-surefire-plugin @@ -309,6 +308,9 @@ **/JdbcTest.java **/*LiveTest.java + + ${tutorialsproject.basedir}/logback-config.xml + @@ -576,6 +578,9 @@ **/*JdbcTest.java **/*LiveTest.java + + ${tutorialsproject.basedir}/logback-config.xml + diff --git a/software-security/sql-injection-samples/src/test/resources/logback-test.xml b/software-security/sql-injection-samples/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/software-security/sql-injection-samples/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java index e7cb60dbf9..a12d762fe5 100644 --- a/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java +++ b/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java @@ -1,21 +1,25 @@ package com.baeldung.backpressure; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.BaseSubscriber; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; public class BackpressureUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(BackpressureUnitTest.class); + @Test public void whenLimitRateSet_thenSplitIntoChunks() throws InterruptedException { Flux limit = Flux.range(1, 25); limit.limitRate(10); limit.subscribe( - value -> System.out.println(value), + value -> LOGGER.debug(String.valueOf(value)), err -> err.printStackTrace(), - () -> System.out.println("Finished!!"), + () -> LOGGER.debug("Finished!!"), subscription -> subscription.request(15) ); @@ -34,12 +38,12 @@ public class BackpressureUnitTest { Flux request = Flux.range(1, 50); request.subscribe( - System.out::println, + integer -> LOGGER.debug(String.valueOf(integer)), err -> err.printStackTrace(), - () -> System.out.println("All 50 items have been successfully processed!!!"), + () -> LOGGER.debug("All 50 items have been successfully processed!!!"), subscription -> { for (int i = 0; i < 5; i++) { - System.out.println("Requesting the next 10 elements!!!"); + LOGGER.debug("Requesting the next 10 elements!!!"); subscription.request(10); } } @@ -68,7 +72,7 @@ public class BackpressureUnitTest { @Override protected void hookOnNext(Integer value) { request(3); - System.out.println(value); + LOGGER.debug(String.valueOf(value)); cancel(); } }); diff --git a/spring-aop/pom.xml b/spring-aop/pom.xml index da981987fe..cbec4ef35b 100644 --- a/spring-aop/pom.xml +++ b/spring-aop/pom.xml @@ -65,6 +65,15 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.basedir}/src/main/resources/logback.xml + + + diff --git a/spring-boot-modules/spring-boot-1/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-1/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-data-2/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-data-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-data-2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties-2/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-properties-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties-2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-properties/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-validation/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-validation/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-boot-modules/spring-boot-validation/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java b/spring-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java index caf1df2a1b..e653e84048 100644 --- a/spring-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java +++ b/spring-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java @@ -1,8 +1,12 @@ package com.baeldung.ehcache.calculator; import com.baeldung.ehcache.config.CacheHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SquaredCalculator { + + private static final Logger LOGGER = LoggerFactory.getLogger(SquaredCalculator.class); private CacheHelper cache; public int getSquareValueOfNumber(int input) { @@ -10,7 +14,7 @@ public class SquaredCalculator { return cache.getSquareNumberCache().get(input); } - System.out.println("Calculating square value of " + input + " and caching result."); + LOGGER.debug("Calculating square value of {} and caching result.", input); int squaredValue = (int) Math.pow(input, 2); cache.getSquareNumberCache().put(input, squaredValue); diff --git a/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java b/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java index 37df749bab..311b7c575e 100644 --- a/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java +++ b/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java @@ -4,13 +4,18 @@ import com.baeldung.ehcache.calculator.SquaredCalculator; import com.baeldung.ehcache.config.CacheHelper; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class SquareCalculatorUnitTest { - private SquaredCalculator squaredCalculator = new SquaredCalculator(); - private CacheHelper cacheHelper = new CacheHelper(); + + private static final Logger LOGGER = LoggerFactory.getLogger(SquareCalculatorUnitTest.class); + + private final SquaredCalculator squaredCalculator = new SquaredCalculator(); + private final CacheHelper cacheHelper = new CacheHelper(); @Before public void setup() { @@ -20,21 +25,24 @@ public class SquareCalculatorUnitTest { @Test public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() { for (int i = 10; i < 15; i++) { - assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); - System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n"); + assertFalse(cacheHelper.getSquareNumberCache() + .containsKey(i)); + LOGGER.debug("Square value of {} is: {}", i, squaredCalculator.getSquareValueOfNumber(i)); } } @Test public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() { for (int i = 10; i < 15; i++) { - assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); - System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n"); + assertFalse(cacheHelper.getSquareNumberCache() + .containsKey(i)); + LOGGER.debug("Square value of {} is: {}", i, squaredCalculator.getSquareValueOfNumber(i)); } for (int i = 10; i < 15; i++) { - assertTrue(cacheHelper.getSquareNumberCache().containsKey(i)); - System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n"); + assertTrue(cacheHelper.getSquareNumberCache() + .containsKey(i)); + LOGGER.debug("Square value of {} is: {}", i, squaredCalculator.getSquareValueOfNumber(i) + "\n"); } } } diff --git a/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/additional-sources-simple/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-archaius/basic-config/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-archaius/basic-config/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/basic-config/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-archaius/extra-configs/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-archaius/extra-configs/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/extra-configs/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-functions/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-functions/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-functions/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/src/test/resources/logback-test.xml b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-core-5/src/test/resources/logback-test.xml b/spring-core-5/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-core-5/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-di-2/src/test/resources/logback-test.xml b/spring-di-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-di-2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-security-modules/spring-5-security/src/test/resources/logback-test.xml b/spring-security-modules/spring-5-security/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-security-modules/spring-5-security/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-security-modules/spring-security-oidc/src/test/resources/logback-test.xml b/spring-security-modules/spring-security-oidc/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-security-modules/spring-security-oidc/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-boot-3/src/test/resources/logback-test.xml b/spring-security-modules/spring-security-web-boot-3/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-security-modules/spring-security-web-boot-3/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-boot-jsp/src/test/resources/logback-test.xml b/spring-web-modules/spring-boot-jsp/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-web-modules/spring-boot-jsp/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics/src/test/resources/logback-test.xml b/spring-web-modules/spring-mvc-basics/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-web-modules/spring-mvc-basics/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-java-2/src/test/resources/logback-test.xml b/spring-web-modules/spring-mvc-java-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-web-modules/spring-mvc-java-2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-rest-http/src/test/resources/logback-test.xml b/spring-web-modules/spring-rest-http/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-web-modules/spring-rest-http/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-resttemplate-2/src/test/resources/logback-test.xml b/spring-web-modules/spring-resttemplate-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-thymeleaf-2/src/test/resources/logback-test.xml b/spring-web-modules/spring-thymeleaf-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..8d4771e308 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-2/src/test/resources/logback-test.xml @@ -0,0 +1,12 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + + \ No newline at end of file diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java index 6022de123f..3e09a3adbb 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java @@ -23,19 +23,19 @@ public class BeforeAndAfterAnnotationsUnitTest { @Before public void init() { - LOG.info("startup"); + LOG.debug("startup"); list = new ArrayList<>(Arrays.asList("test1", "test2")); } @After public void teardown() { - LOG.info("teardown"); + LOG.debug("teardown"); list.clear(); } @Test public void whenCheckingListSize_thenSizeEqualsToInit() { - LOG.info("executing test"); + LOG.debug("executing test"); assertEquals(2, list.size()); list.add("another test"); @@ -43,7 +43,7 @@ public class BeforeAndAfterAnnotationsUnitTest { @Test public void whenCheckingListSizeAgain_thenSizeEqualsToInit() { - LOG.info("executing another test"); + LOG.debug("executing another test"); assertEquals(2, list.size()); list.add("yet another test"); diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java index 8a82a75d3d..8b0ddd259f 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java @@ -12,24 +12,24 @@ import org.slf4j.LoggerFactory; public class BeforeClassAndAfterClassAnnotationsUnitTest { private static final Logger LOG = LoggerFactory.getLogger(BeforeClassAndAfterClassAnnotationsUnitTest.class); - + @BeforeClass public static void setup() { - LOG.info("startup - creating DB connection"); + LOG.debug("startup - creating DB connection"); } @AfterClass public static void tearDown() { - LOG.info("closing DB connection"); + LOG.debug("closing DB connection"); } @Test public void simpleTest() { - LOG.info("simple test"); + LOG.debug("simple test"); } @Test public void anotherSimpleTest() { - LOG.info("another simple test"); + LOG.debug("another simple test"); } } diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java index 969d1b370e..9cf6eafd7e 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java @@ -1,18 +1,21 @@ package com.baeldung.migration.junit4; +import com.baeldung.migration.junit4.rules.TraceUnitTestRule; import org.junit.Rule; import org.junit.Test; - -import com.baeldung.migration.junit4.rules.TraceUnitTestRule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RuleExampleUnitTest { - + + private static final Logger LOGGER = LoggerFactory.getLogger(RuleExampleUnitTest.class); + @Rule public final TraceUnitTestRule traceRuleTests = new TraceUnitTestRule(); @Test public void whenTracingTests() { - System.out.println("This is my test"); + LOGGER.debug("This is my test"); /*...*/ } } diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java index 5c993f17fd..b17e0b07c8 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java @@ -1,15 +1,19 @@ package com.baeldung.migration.junit4.rules; -import java.util.ArrayList; -import java.util.List; - import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.MultipleFailureException; import org.junit.runners.model.Statement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; public class TraceUnitTestRule implements TestRule { + private static final Logger LOGGER = LoggerFactory.getLogger(TraceUnitTestRule.class); + @Override public Statement apply(Statement base, Description description) { @@ -18,13 +22,13 @@ public class TraceUnitTestRule implements TestRule { public void evaluate() throws Throwable { List errors = new ArrayList(); - System.out.println("Starting test ... " + description.getMethodName()); + LOGGER.debug("Starting test ... {}", description.getMethodName()); try { base.evaluate(); } catch (Throwable e) { errors.add(e); } finally { - System.out.println("... test finished. " + description.getMethodName()); + LOGGER.debug("... test finished. {}", description.getMethodName()); } MultipleFailureException.assertEmpty(errors); diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java index b81e9b7b8e..5181d54a46 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java @@ -15,21 +15,21 @@ public class BeforeAllAndAfterAllAnnotationsUnitTest { @BeforeAll public static void setup() { - LOG.info("startup - creating DB connection"); + LOG.debug("startup - creating DB connection"); } @AfterAll public static void tearDown() { - LOG.info("closing DB connection"); + LOG.debug("closing DB connection"); } @Test public void simpleTest() { - LOG.info("simple test"); + LOG.debug("simple test"); } @Test public void anotherSimpleTest() { - LOG.info("another simple test"); + LOG.debug("another simple test"); } } diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java index f0093b3bf6..b2112ef2c3 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java @@ -23,19 +23,19 @@ public class BeforeEachAndAfterEachAnnotationsUnitTest { @BeforeEach public void init() { - LOG.info("startup"); + LOG.debug("startup"); list = new ArrayList<>(Arrays.asList("test1", "test2")); } @AfterEach public void teardown() { - LOG.info("teardown"); + LOG.debug("teardown"); list.clear(); } @Test public void whenCheckingListSize_ThenSizeEqualsToInit() { - LOG.info("executing test"); + LOG.debug("executing test"); assertEquals(2, list.size()); list.add("another test"); @@ -43,7 +43,7 @@ public class BeforeEachAndAfterEachAnnotationsUnitTest { @Test public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() { - LOG.info("executing another test"); + LOG.debug("executing another test"); assertEquals(2, list.size()); list.add("yet another test"); diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java index 7b1bcda730..c67a57dcbd 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java @@ -1,19 +1,22 @@ package com.baeldung.migration.junit5; +import com.baeldung.migration.junit5.extensions.TraceUnitExtension; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; - -import com.baeldung.migration.junit5.extensions.TraceUnitExtension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @RunWith(JUnitPlatform.class) @ExtendWith(TraceUnitExtension.class) public class RuleExampleUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(RuleExampleUnitTest.class); + @Test public void whenTracingTests() { - System.out.println("This is my test"); + LOGGER.debug("This is my test"); /*...*/ } } diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java index db5d3e2573..165ca8741a 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java @@ -3,17 +3,21 @@ package com.baeldung.migration.junit5.extensions; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TraceUnitExtension implements AfterEachCallback, BeforeEachCallback { + private static final Logger LOGGER = LoggerFactory.getLogger(TraceUnitExtension.class); + @Override public void beforeEach(ExtensionContext context) throws Exception { - System.out.println("Starting test ... " + context.getDisplayName()); + LOGGER.debug("Starting test ... {}", context.getDisplayName()); } @Override public void afterEach(ExtensionContext context) throws Exception { - System.out.println("... test finished. " + context.getDisplayName()); + LOGGER.debug("... test finished. {}", context.getDisplayName()); } } diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java index eb8cab2462..b8358449c0 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java @@ -1,7 +1,10 @@ package com.baeldung.resourcedirectory; +import com.baeldung.migration.junit5.extensions.TraceUnitExtension; import org.junit.Assert; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.nio.file.Path; @@ -9,6 +12,8 @@ import java.nio.file.Paths; public class ReadResourceDirectoryUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(TraceUnitExtension.class); + @Test public void givenResourcePath_whenReadAbsolutePathWithFile_thenAbsolutePathEndsWithDirectory() { String path = "src/test/resources"; @@ -16,7 +21,7 @@ public class ReadResourceDirectoryUnitTest { File file = new File(path); String absolutePath = file.getAbsolutePath(); - System.out.println(absolutePath); + LOGGER.debug(absolutePath); Assert.assertTrue(absolutePath.endsWith("src" + File.separator + "test" + File.separator + "resources")); } @@ -26,7 +31,7 @@ public class ReadResourceDirectoryUnitTest { String absolutePath = resourceDirectory.toFile().getAbsolutePath(); - System.out.println(absolutePath); + LOGGER.debug(absolutePath); Assert.assertTrue(absolutePath.endsWith("src" + File.separator + "test" + File.separator + "resources")); } @@ -38,7 +43,7 @@ public class ReadResourceDirectoryUnitTest { File file = new File(classLoader.getResource(resourceName).getFile()); String absolutePath = file.getAbsolutePath(); - System.out.println(absolutePath); + LOGGER.debug(absolutePath); Assert.assertTrue(absolutePath.endsWith(File.separator + "example_resource.txt")); } diff --git a/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/registerextension/RegisterExtensionSampleExtension.java b/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/registerextension/RegisterExtensionSampleExtension.java index 5339f98875..31d45955ca 100644 --- a/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/registerextension/RegisterExtensionSampleExtension.java +++ b/testing-modules/junit5-annotations/src/main/java/com/baeldung/junit5/registerextension/RegisterExtensionSampleExtension.java @@ -20,12 +20,12 @@ public class RegisterExtensionSampleExtension implements BeforeAllCallback, Befo @Override public void beforeAll(ExtensionContext extensionContext) throws Exception { - logger.info("Type {} In beforeAll : {}", type, extensionContext.getDisplayName()); + logger.debug("Type {} In beforeAll : {}", type, extensionContext.getDisplayName()); } @Override public void beforeEach(ExtensionContext extensionContext) throws Exception { - logger.info("Type {} In beforeEach : {}", type, extensionContext.getDisplayName()); + logger.debug("Type {} In beforeEach : {}", type, extensionContext.getDisplayName()); } public String getType() { diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/RepeatedTestAnnotationUnitTest.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/RepeatedTestAnnotationUnitTest.java index f9121d8790..c3e6d19568 100644 --- a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/RepeatedTestAnnotationUnitTest.java +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/RepeatedTestAnnotationUnitTest.java @@ -1,41 +1,45 @@ package com.baeldung.junit5; -import static org.junit.jupiter.api.Assertions.assertEquals; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.RepetitionInfo; import org.junit.jupiter.api.TestInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class RepeatedTestAnnotationUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(RepeatedTestAnnotationUnitTest.class); + @BeforeEach void beforeEachTest() { - System.out.println("Before Each Test"); + LOGGER.debug("Before Each Test"); } @AfterEach void afterEachTest() { - System.out.println("After Each Test"); - System.out.println("====================="); + LOGGER.debug("After Each Test"); + LOGGER.debug("====================="); } @RepeatedTest(3) void repeatedTest(TestInfo testInfo) { - System.out.println("Executing repeated test"); + LOGGER.debug("Executing repeated test"); assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2"); } @RepeatedTest(value = 3, name = RepeatedTest.LONG_DISPLAY_NAME) void repeatedTestWithLongName() { - System.out.println("Executing repeated test with long name"); + LOGGER.debug("Executing repeated test with long name"); assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2"); } @RepeatedTest(value = 3, name = RepeatedTest.SHORT_DISPLAY_NAME) void repeatedTestWithShortName() { - System.out.println("Executing repeated test with long name"); + LOGGER.debug("Executing repeated test with long name"); assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2"); } @@ -46,7 +50,7 @@ public class RepeatedTestAnnotationUnitTest { @RepeatedTest(3) void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) { - System.out.println("Repetition #" + repetitionInfo.getCurrentRepetition()); + LOGGER.debug("Repetition # {}", repetitionInfo.getCurrentRepetition()); assertEquals(3, repetitionInfo.getTotalRepetitions()); } } diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/conditional/ConditionalAnnotationsUnitTest.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/conditional/ConditionalAnnotationsUnitTest.java index ba840a1c33..0d4013116f 100644 --- a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/conditional/ConditionalAnnotationsUnitTest.java +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/conditional/ConditionalAnnotationsUnitTest.java @@ -2,7 +2,20 @@ package com.baeldung.junit5.conditional; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.*; +import org.junit.jupiter.api.condition.DisabledForJreRange; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.condition.EnabledOnJre; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.condition.OS; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -11,64 +24,66 @@ import java.lang.annotation.Target; public class ConditionalAnnotationsUnitTest { + private static final Logger LOGGER = LoggerFactory.getLogger(ConditionalAnnotationsUnitTest.class); + @Test @EnabledOnOs({OS.WINDOWS, OS.MAC}) public void shouldRunBothWindowsAndMac() { - System.out.println("runs on Windows and Mac"); + LOGGER.debug("runs on Windows and Mac"); } @Test @DisabledOnOs(OS.LINUX) public void shouldNotRunAtLinux() { - System.out.println("will not run on Linux"); + LOGGER.debug("will not run on Linux"); } @Test @EnabledOnJre({JRE.JAVA_10, JRE.JAVA_11}) public void shouldOnlyRunOnJava10And11() { - System.out.println("runs with java 10 and 11"); + LOGGER.debug("runs with java 10 and 11"); } @Test @EnabledForJreRange(min = JRE.JAVA_8, max = JRE.JAVA_13) public void shouldOnlyRunOnJava8UntilJava13() { - System.out.println("runs with Java 8, 9, 10, 11, 12 and 13!"); + LOGGER.debug("runs with Java 8, 9, 10, 11, 12 and 13!"); } @Test @DisabledForJreRange(min = JRE.JAVA_14, max = JRE.JAVA_15) public void shouldNotBeRunOnJava14AndJava15() { - System.out.println("Shouldn't be run on Java 14 and 15."); + LOGGER.debug("Shouldn't be run on Java 14 and 15."); } @Test @DisabledOnJre(JRE.OTHER) public void thisTestOnlyRunsWithUpToDateJREs() { - System.out.println("this test will only run on java8, 9, 10 and 11."); + LOGGER.debug("this test will only run on java8, 9, 10 and 11."); } @Test @EnabledIfSystemProperty(named = "java.vm.vendor", matches = "Oracle.*") public void onlyIfVendorNameStartsWithOracle() { - System.out.println("runs only if vendor name starts with Oracle"); + LOGGER.debug("runs only if vendor name starts with Oracle"); } @Test @DisabledIfSystemProperty(named = "file.separator", matches = "[/]") public void disabledIfFileSeperatorIsSlash() { - System.out.println("Will not run if file.sepeartor property is /"); + LOGGER.debug("Will not run if file.sepeartor property is /"); } @Test @EnabledIfEnvironmentVariable(named = "GDMSESSION", matches = "ubuntu") public void onlyRunOnUbuntuServer() { - System.out.println("only runs if GDMSESSION is ubuntu"); + LOGGER.debug("only runs if GDMSESSION is ubuntu"); } @Test @DisabledIfEnvironmentVariable(named = "LC_TIME", matches = ".*UTF-8.") public void shouldNotRunWhenTimeIsNotUTF8() { - System.out.println("will not run if environment variable LC_TIME is UTF-8"); + LOGGER.debug("will not run if environment variable LC_TIME is UTF-8"); } // Commented codes are going to work prior JUnit 5.5 @@ -76,13 +91,13 @@ public class ConditionalAnnotationsUnitTest { @Test // @EnabledIf("'FR' == systemProperty.get('user.country')") public void onlyFrenchPeopleWillRunThisMethod() { - System.out.println("will run only if user.country is FR"); + LOGGER.debug("will run only if user.country is FR"); } @Test // @DisabledIf("java.lang.System.getProperty('os.name').toLowerCase().contains('mac')") public void shouldNotRunOnMacOS() { - System.out.println("will not run if our os.name is mac"); + LOGGER.debug("will not run if our os.name is mac"); } @Test @@ -97,14 +112,14 @@ public class ConditionalAnnotationsUnitTest { engine = "nashorn", reason = "Self-fulfilling: {result}")*/ public void onlyRunsInFebruary() { - System.out.println("this test only runs in February"); + LOGGER.debug("this test only runs in February"); } @Test /*@DisabledIf("systemEnvironment.get('XPC_SERVICE_NAME') != null " + "&& systemEnvironment.get('XPC_SERVICE_NAME').contains('intellij')")*/ public void notValidForIntelliJ() { - System.out.println("this test will run if our ide is INTELLIJ"); + LOGGER.debug("this test will run if our ide is INTELLIJ"); } @Target(ElementType.METHOD) @@ -117,7 +132,7 @@ public class ConditionalAnnotationsUnitTest { @ThisTestWillOnlyRunAtLinuxAndMacWithJava9Or10Or11 public void someSuperTestMethodHere() { - System.out.println("this method will run with java9, 10, 11 and Linux or macOS."); + LOGGER.debug("this method will run with java9, 10, 11 and Linux or macOS."); } @Target(ElementType.METHOD) @@ -129,6 +144,6 @@ public class ConditionalAnnotationsUnitTest { @RepeatedTest(2) @CoinToss public void gamble() { - System.out.println("This tests run status is a gamble with %50 rate"); + LOGGER.debug("This tests run status is a gamble with %50 rate"); } } diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/DisabledOnQAEnvironmentExtension.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/DisabledOnQAEnvironmentExtension.java index cd8b7b677d..fec2980b6f 100644 --- a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/DisabledOnQAEnvironmentExtension.java +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/DisabledOnQAEnvironmentExtension.java @@ -3,11 +3,16 @@ package com.baeldung.junit5.templates; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.Properties; public class DisabledOnQAEnvironmentExtension implements ExecutionCondition { + + private static final Logger LOGGER = LoggerFactory.getLogger(DisabledOnQAEnvironmentExtension.class); + @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Properties properties = new Properties(); @@ -16,7 +21,7 @@ public class DisabledOnQAEnvironmentExtension implements ExecutionCondition { .getResourceAsStream("application.properties")); if ("qa".equalsIgnoreCase(properties.getProperty("env"))) { String reason = String.format("The test '%s' is disabled on QA environment", context.getDisplayName()); - System.out.println(reason); + LOGGER.debug(reason); return ConditionEvaluationResult.disabled(reason); } } catch (IOException e) { diff --git a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/UserIdGeneratorTestInvocationContextProvider.java b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/UserIdGeneratorTestInvocationContextProvider.java index 277ec03f05..3e1aaaabd3 100644 --- a/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/UserIdGeneratorTestInvocationContextProvider.java +++ b/testing-modules/junit5-annotations/src/test/java/com/baeldung/junit5/templates/UserIdGeneratorTestInvocationContextProvider.java @@ -1,6 +1,15 @@ package com.baeldung.junit5.templates; -import org.junit.jupiter.api.extension.*; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.AfterTestExecutionCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; +import org.junit.jupiter.api.extension.Extension; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; import java.util.stream.Stream; @@ -9,6 +18,8 @@ import static java.util.Arrays.asList; public class UserIdGeneratorTestInvocationContextProvider implements TestTemplateInvocationContextProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(UserIdGeneratorTestInvocationContextProvider.class); + @Override public boolean supportsTestTemplate(ExtensionContext extensionContext) { return true; @@ -44,13 +55,13 @@ public class UserIdGeneratorTestInvocationContextProvider implements TestTemplat new BeforeTestExecutionCallback() { @Override public void beforeTestExecution(ExtensionContext extensionContext) { - System.out.println("BeforeTestExecutionCallback:Disabled context"); + LOGGER.debug("BeforeTestExecutionCallback:Disabled context"); } }, new AfterTestExecutionCallback() { @Override public void afterTestExecution(ExtensionContext extensionContext) { - System.out.println("AfterTestExecutionCallback:Disabled context"); + LOGGER.debug("AfterTestExecutionCallback:Disabled context"); } }); } @@ -72,13 +83,13 @@ public class UserIdGeneratorTestInvocationContextProvider implements TestTemplat new BeforeEachCallback() { @Override public void beforeEach(ExtensionContext extensionContext) { - System.out.println("BeforeEachCallback:Enabled context"); + LOGGER.debug("BeforeEachCallback:Enabled context"); } }, new AfterEachCallback() { @Override public void afterEach(ExtensionContext extensionContext) { - System.out.println("AfterEachCallback:Enabled context"); + LOGGER.debug("AfterEachCallback:Enabled context"); } }); } diff --git a/testing-modules/testing-assertions/src/main/java/com/baeldung/junit/log/BusinessWorker.java b/testing-modules/testing-assertions/src/main/java/com/baeldung/junit/log/BusinessWorker.java index 86cd38824c..b95faa7874 100644 --- a/testing-modules/testing-assertions/src/main/java/com/baeldung/junit/log/BusinessWorker.java +++ b/testing-modules/testing-assertions/src/main/java/com/baeldung/junit/log/BusinessWorker.java @@ -4,7 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class BusinessWorker { - private static Logger LOGGER = LoggerFactory.getLogger(BusinessWorker.class); + private static final Logger LOGGER = LoggerFactory.getLogger(BusinessWorker.class); public void generateLogs(String msg) { LOGGER.trace(msg); From fd2ae3452eae5e51c9ef7e87b2b728bb71278dd1 Mon Sep 17 00:00:00 2001 From: Azhwani Date: Fri, 19 Nov 2021 12:48:29 +0100 Subject: [PATCH 48/78] + Remove junit versions to use those of the main pom --- testing-modules/junit-5/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 9b2518d10b..148abecb0f 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -137,10 +137,7 @@ - 5.8.1 2.23.0 - 1.8.1 - 5.8.1 2.8.2 2.0.0 2.22.0 From c1a5a6d934f8c153eb025c92c7ae29457d1fe24b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 19 Nov 2021 21:25:17 +0800 Subject: [PATCH 49/78] Update README.md --- persistence-modules/java-mongodb/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/java-mongodb/README.md b/persistence-modules/java-mongodb/README.md index b79cea6781..f632e7c662 100644 --- a/persistence-modules/java-mongodb/README.md +++ b/persistence-modules/java-mongodb/README.md @@ -10,5 +10,4 @@ This module contains articles about MongoDB in Java. - [Geospatial Support in MongoDB](https://www.baeldung.com/mongodb-geospatial-support) - [Introduction to Morphia – Java ODM for MongoDB](https://www.baeldung.com/mongodb-morphia) - [MongoDB Aggregations Using Java](https://www.baeldung.com/java-mongodb-aggregations) -- [MongoDB BSON to JSON](https://www.baeldung.com/bson-to-json) - [BSON to JSON Document Conversion in Java](https://www.baeldung.com/java-convert-bson-to-json) From 3af2698305a0238366f1b8a9b7144729d5c3cd64 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 19 Nov 2021 17:11:47 +0200 Subject: [PATCH 50/78] BAEL-5112 delete moved code --- junit5/README.md | 6 --- junit5/pom.xml | 21 --------- .../java/com/baeldung/junit5/A_UnitTest.java | 21 --------- .../java/com/baeldung/junit5/B_UnitTest.java | 23 ---------- .../java/com/baeldung/junit5/C_UnitTest.java | 45 ------------------- .../test/resources/junit-platform.properties | 4 -- 6 files changed, 120 deletions(-) delete mode 100644 junit5/README.md delete mode 100644 junit5/pom.xml delete mode 100644 junit5/src/test/java/com/baeldung/junit5/A_UnitTest.java delete mode 100644 junit5/src/test/java/com/baeldung/junit5/B_UnitTest.java delete mode 100644 junit5/src/test/java/com/baeldung/junit5/C_UnitTest.java delete mode 100644 junit5/src/test/resources/junit-platform.properties diff --git a/junit5/README.md b/junit5/README.md deleted file mode 100644 index ad16ad164d..0000000000 --- a/junit5/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## JUnit5 - -This module contains articles about the JUnit 5 - -### Relevant Articles: - diff --git a/junit5/pom.xml b/junit5/pom.xml deleted file mode 100644 index 00b04ea292..0000000000 --- a/junit5/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - 4.0.0 - junit5 - junit5 - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - 8 - 8 - - - \ No newline at end of file diff --git a/junit5/src/test/java/com/baeldung/junit5/A_UnitTest.java b/junit5/src/test/java/com/baeldung/junit5/A_UnitTest.java deleted file mode 100644 index e4ba59b22d..0000000000 --- a/junit5/src/test/java/com/baeldung/junit5/A_UnitTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.junit5; - -import org.junit.jupiter.api.Test; - -public class A_UnitTest { - - @Test - public void first() throws Exception{ - System.out.println("Test A first() start => " + Thread.currentThread().getName()); - Thread.sleep(500); - System.out.println("Test A first() end => " + Thread.currentThread().getName()); - } - - @Test - public void second() throws Exception{ - System.out.println("Test A second() start => " + Thread.currentThread().getName()); - Thread.sleep(500); - System.out.println("Test A second() end => " + Thread.currentThread().getName()); - } - -} diff --git a/junit5/src/test/java/com/baeldung/junit5/B_UnitTest.java b/junit5/src/test/java/com/baeldung/junit5/B_UnitTest.java deleted file mode 100644 index 2b195d2551..0000000000 --- a/junit5/src/test/java/com/baeldung/junit5/B_UnitTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.junit5; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.parallel.Execution; -import org.junit.jupiter.api.parallel.ExecutionMode; - -public class B_UnitTest { - - @Test - public void first() throws Exception{ - System.out.println("Test B first() start => " + Thread.currentThread().getName()); - Thread.sleep(500); - System.out.println("Test B first() end => " + Thread.currentThread().getName()); - } - - @Test - public void second() throws Exception{ - System.out.println("Test B second() start => " + Thread.currentThread().getName()); - Thread.sleep(500); - System.out.println("Test B second() end => " + Thread.currentThread().getName()); - } - -} diff --git a/junit5/src/test/java/com/baeldung/junit5/C_UnitTest.java b/junit5/src/test/java/com/baeldung/junit5/C_UnitTest.java deleted file mode 100644 index ce545f6bee..0000000000 --- a/junit5/src/test/java/com/baeldung/junit5/C_UnitTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.junit5; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.parallel.ResourceLock; - -import java.util.ArrayList; -import java.util.List; - -public class C_UnitTest { - - private List resources; - - @BeforeEach - void before() { - resources = new ArrayList<>(); - resources.add("test"); - } - - @AfterEach - void after() { - resources.clear(); - } - - @Test - @ResourceLock(value = "resources") - public void first() throws Exception { - System.out.println("Test C first() start => " + Thread.currentThread().getName()); - resources.add("first"); - System.out.println(resources); - Thread.sleep(500); - System.out.println("Test C first() end => " + Thread.currentThread().getName()); - } - - @Test - @ResourceLock(value = "resources") - public void second() throws Exception { - System.out.println("Test C second() start => " + Thread.currentThread().getName()); - resources.add("second"); - System.out.println(resources); - Thread.sleep(500); - System.out.println("Test C second() end => " + Thread.currentThread().getName()); - } -} diff --git a/junit5/src/test/resources/junit-platform.properties b/junit5/src/test/resources/junit-platform.properties deleted file mode 100644 index 42100f85da..0000000000 --- a/junit5/src/test/resources/junit-platform.properties +++ /dev/null @@ -1,4 +0,0 @@ -junit.jupiter.execution.parallel.enabled = true -junit.jupiter.execution.parallel.config.strategy=dynamic -junit.jupiter.execution.parallel.mode.default = concurrent -junit.jupiter.execution.parallel.mode.classes.default = concurrent From b8aaced8cb7eb661967cae8ab0e5875133c6ee40 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 19 Nov 2021 17:13:36 +0200 Subject: [PATCH 51/78] BAEL-5112 delete moved code --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6d10dcb668..3bd5ba1180 100644 --- a/pom.xml +++ b/pom.xml @@ -473,7 +473,6 @@ json-path jsoup jta - junit5 kubernetes ksqldb From b79a73875610ba50af72e2fc60d186cf42fe1120 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Fri, 19 Nov 2021 20:51:24 +0000 Subject: [PATCH 52/78] [JAVA-8335] Fix intermittent unit test failure --- .../java/com/baeldung/abaproblem/Account.java | 17 ++++---- .../baeldung/abaproblem/AccountUnitTest.java | 40 +++++++++++-------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java index ee1bdcd55b..2af3113549 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java @@ -3,17 +3,18 @@ package com.baeldung.abaproblem; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; + public class Account { - private AtomicInteger balance; - private AtomicInteger transactionCount; - private ThreadLocal currentThreadCASFailureCount; + private final AtomicInteger balance; + private final AtomicInteger transactionCount; + private final ThreadLocal currentThreadCASFailureCount; public Account() { this.balance = new AtomicInteger(0); this.transactionCount = new AtomicInteger(0); - this.currentThreadCASFailureCount = new ThreadLocal<>(); - this.currentThreadCASFailureCount.set(0); + this.currentThreadCASFailureCount = ThreadLocal.withInitial(() -> 0); } public int getBalance() { @@ -43,11 +44,7 @@ public class Account { private void maybeWait() { if ("thread1".equals(Thread.currentThread().getName())) { - try { - TimeUnit.SECONDS.sleep(2); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + sleepUninterruptibly(2, TimeUnit.SECONDS); } } diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java index aa5f0f7997..3e188d682e 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java @@ -1,8 +1,13 @@ package com.baeldung.abaproblem; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -30,45 +35,39 @@ public class AccountUnitTest { assertTrue(account.deposit(moneyToDeposit)); assertEquals(moneyToDeposit, account.getBalance()); + assertEquals(1, account.getTransactionCount()); } @Test - public void withdrawTest() throws InterruptedException { + public void withdrawTest() { final int defaultBalance = 50; final int moneyToWithdraw = 20; account.deposit(defaultBalance); assertTrue(account.withdraw(moneyToWithdraw)); - assertEquals(defaultBalance - moneyToWithdraw, account.getBalance()); } @Test - public void abaProblemTest() throws InterruptedException { + public void abaProblemTest() throws Exception { final int defaultBalance = 50; final int amountToWithdrawByThread1 = 20; final int amountToWithdrawByThread2 = 10; final int amountToDepositByThread2 = 10; - assertEquals(0, account.getTransactionCount()); - assertEquals(0, account.getCurrentThreadCASFailureCount()); account.deposit(defaultBalance); - assertEquals(1, account.getTransactionCount()); - - Thread thread1 = new Thread(() -> { + Runnable thread1 = () -> { // this will take longer due to the name of the thread assertTrue(account.withdraw(amountToWithdrawByThread1)); // thread 1 fails to capture ABA problem assertNotEquals(1, account.getCurrentThreadCASFailureCount()); + }; - }, "thread1"); - - Thread thread2 = new Thread(() -> { - + Runnable thread2 = () -> { assertTrue(account.deposit(amountToDepositByThread2)); assertEquals(defaultBalance + amountToDepositByThread2, account.getBalance()); @@ -79,12 +78,13 @@ public class AccountUnitTest { assertEquals(defaultBalance, account.getBalance()); assertEquals(0, account.getCurrentThreadCASFailureCount()); - }, "thread2"); + }; - thread1.start(); - thread2.start(); - thread1.join(); - thread2.join(); + Future future1 = getSingleThreadExecutorService("thread1").submit(thread1); + Future future2 = getSingleThreadExecutorService("thread2").submit(thread2); + + future1.get(); + future2.get(); // compareAndSet operation succeeds for thread 1 assertEquals(defaultBalance - amountToWithdrawByThread1, account.getBalance()); @@ -95,4 +95,10 @@ public class AccountUnitTest { // thread 2 did two modifications as well assertEquals(4, account.getTransactionCount()); } + + private static ExecutorService getSingleThreadExecutorService(String threadName) { + return Executors.newSingleThreadExecutor( + new ThreadFactoryBuilder().setNameFormat(threadName).build() + ); + } } From 6f6d862f79d6ad636b626936ffeece26b7836ff3 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 20 Nov 2021 14:00:47 +0530 Subject: [PATCH 53/78] JAVA-8398: Align module names, folder names and artifact id --- persistence-modules/spring-data-cassandra-2/pom.xml | 4 ++-- .../custom-validations-opeanpi-codegen/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/persistence-modules/spring-data-cassandra-2/pom.xml b/persistence-modules/spring-data-cassandra-2/pom.xml index 8202471d19..1e6412dc17 100644 --- a/persistence-modules/spring-data-cassandra-2/pom.xml +++ b/persistence-modules/spring-data-cassandra-2/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.baeldung - spring-cassandra + spring-data-cassandra-2 0.0.1-SNAPSHOT - spring-cassandra + spring-data-cassandra-2 Demo project for Spring Data Cassandra diff --git a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml index 53e5006bf4..70b9e2acd5 100644 --- a/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml +++ b/spring-swagger-codegen/custom-validations-opeanpi-codegen/pom.xml @@ -9,9 +9,9 @@ com.example - petstore + custom-validations-opeanpi-codegen 0.0.1-SNAPSHOT - petstore + custom-validations-opeanpi-codegen Demo project for Swagger Custom Validations Codegen 11 From ebb3e100f8c42d0aa616d4af0aca3edaa2ff2f3c Mon Sep 17 00:00:00 2001 From: chaos2418 <> Date: Sat, 20 Nov 2021 17:23:33 +0530 Subject: [PATCH 54/78] JAVA-7832: spring-cloud-config bootstrap.properties need to change to application.properties/yml --- .../client/src/main/resources/application.properties | 3 +++ .../client/src/main/resources/bootstrap.properties | 6 ------ .../server/src/main/resources/application.properties | 5 +++++ .../server/src/main/resources/bootstrap.properties | 4 ---- 4 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 spring-cloud/spring-cloud-config/client/src/main/resources/application.properties delete mode 100644 spring-cloud/spring-cloud-config/client/src/main/resources/bootstrap.properties delete mode 100644 spring-cloud/spring-cloud-config/server/src/main/resources/bootstrap.properties diff --git a/spring-cloud/spring-cloud-config/client/src/main/resources/application.properties b/spring-cloud/spring-cloud-config/client/src/main/resources/application.properties new file mode 100644 index 0000000000..6366bc515c --- /dev/null +++ b/spring-cloud/spring-cloud-config/client/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.application.name=config-client +spring.profiles.active=development +spring.config.import=optional:configserver:http://root:s3cr3t@localhost:8888 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-config/client/src/main/resources/bootstrap.properties b/spring-cloud/spring-cloud-config/client/src/main/resources/bootstrap.properties deleted file mode 100644 index 5dde8baa28..0000000000 --- a/spring-cloud/spring-cloud-config/client/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.application.name=config-client -spring.profiles.active=development -spring.cloud.config.uri=http://localhost:8888 -spring.cloud.config.username=root -spring.cloud.config.password=s3cr3t -spring.cloud.config.fail-fast=true diff --git a/spring-cloud/spring-cloud-config/server/src/main/resources/application.properties b/spring-cloud/spring-cloud-config/server/src/main/resources/application.properties index 18d4b3596a..366ecddf86 100644 --- a/spring-cloud/spring-cloud-config/server/src/main/resources/application.properties +++ b/spring-cloud/spring-cloud-config/server/src/main/resources/application.properties @@ -3,3 +3,8 @@ spring.cloud.config.server.git.uri= spring.cloud.config.server.git.clone-on-start=true spring.security.user.name=root spring.security.user.password=s3cr3t + +encrypt.keyStore.location=classpath:/config-server.jks +encrypt.keyStore.password=my-s70r3-s3cr3t +encrypt.keyStore.alias=config-server-key +encrypt.keyStore.secret=my-k34-s3cr3t diff --git a/spring-cloud/spring-cloud-config/server/src/main/resources/bootstrap.properties b/spring-cloud/spring-cloud-config/server/src/main/resources/bootstrap.properties deleted file mode 100644 index f2d75f5846..0000000000 --- a/spring-cloud/spring-cloud-config/server/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,4 +0,0 @@ -encrypt.keyStore.location=classpath:/config-server.jks -encrypt.keyStore.password=my-s70r3-s3cr3t -encrypt.keyStore.alias=config-server-key -encrypt.keyStore.secret=my-k34-s3cr3t From 921752346b56946e23aeaf2aa6824aece49d1d3b Mon Sep 17 00:00:00 2001 From: makapszenna <66560584+makapszenna@users.noreply.github.com> Date: Sat, 20 Nov 2021 16:57:51 +0100 Subject: [PATCH 55/78] BAEL-5135 ommiting one setter/getter in Lombok (#11386) Co-authored-by: Adrianna Zychewicz --- .../baeldung/lombok/exclusions/Employee.java | 18 ++++++++++++++++++ .../com/baeldung/lombok/exclusions/User.java | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 lombok/src/main/java/com/baeldung/lombok/exclusions/Employee.java create mode 100644 lombok/src/main/java/com/baeldung/lombok/exclusions/User.java diff --git a/lombok/src/main/java/com/baeldung/lombok/exclusions/Employee.java b/lombok/src/main/java/com/baeldung/lombok/exclusions/Employee.java new file mode 100644 index 0000000000..60625747a5 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/exclusions/Employee.java @@ -0,0 +1,18 @@ +package com.baeldung.lombok.exclusions; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +@Data +public class Employee { + + @Setter(AccessLevel.NONE) + private String name; + + private String workplace; + + @Getter(AccessLevel.NONE) + private int workLength; +} diff --git a/lombok/src/main/java/com/baeldung/lombok/exclusions/User.java b/lombok/src/main/java/com/baeldung/lombok/exclusions/User.java new file mode 100644 index 0000000000..52ebeab532 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/exclusions/User.java @@ -0,0 +1,16 @@ +package com.baeldung.lombok.exclusions; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + +public class User { + + @Setter(AccessLevel.NONE) + private long id; + + private String login; + + @Getter(AccessLevel.NONE) + private int age; +} From 48304dbbd30e119e65fd5dbe0aca192ff3a4b220 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Sat, 20 Nov 2021 22:30:23 +0000 Subject: [PATCH 56/78] [JAVA-8592] Fix email service live test --- .../MailWithAttachmentService.java | 56 ++++++------ .../src/main/resources/attachment2.txt | 1 + .../MailWithAttachmentServiceLiveTest.java | 87 ++++++++++++------- 3 files changed, 87 insertions(+), 57 deletions(-) create mode 100644 core-java-modules/core-java-networking-2/src/main/resources/attachment2.txt diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java index 7d4dc57f10..fbe8a54bbe 100644 --- a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentService.java @@ -1,8 +1,5 @@ package com.baeldung.mail.mailwithattachment; -import java.io.File; -import java.io.IOException; -import java.util.Properties; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; @@ -10,23 +7,23 @@ import javax.mail.Multipart; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; -import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.Properties; public class MailWithAttachmentService { - private String username = ""; - private String password = ""; - private String host = ""; - private String port = ""; + private final String username; + private final String password; + private final String host; + private final int port; - MailWithAttachmentService() { - } - - MailWithAttachmentService(String username, String password, String host, String port) { + MailWithAttachmentService(String username, String password, String host, int port) { this.username = username; this.password = password; this.host = host; @@ -40,15 +37,14 @@ public class MailWithAttachmentService { props.put("mail.smtp.host", this.host); props.put("mail.smtp.port", this.port); - Session session = Session.getInstance(props, new javax.mail.Authenticator() { + return Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); - return session; } - public Message createMail(Session session) throws AddressException, MessagingException, IOException { + public void sendMail(Session session) throws MessagingException, IOException { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("mail@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("mail@gmail.com")); @@ -61,23 +57,27 @@ public class MailWithAttachmentService { multipart.addBodyPart(messageBodyPart); MimeBodyPart attachmentPart = new MimeBodyPart(); - MimeBodyPart attachmentPart2 = new MimeBodyPart(); - - attachmentPart.attachFile(new File("C:\\Document1.txt")); - attachmentPart2.attachFile(new File("C:\\Document2.txt")); - + attachmentPart.attachFile(getFile("attachment.txt")); multipart.addBodyPart(attachmentPart); + + MimeBodyPart attachmentPart2 = new MimeBodyPart(); + attachmentPart2.attachFile(getFile("attachment2.txt")); multipart.addBodyPart(attachmentPart2); message.setContent(multipart); - - return message; - } - - public void sendMail(Session session) throws MessagingException, IOException { - - Message message = createMail(session); Transport.send(message); } -} \ No newline at end of file + private File getFile(String filename) { + try { + URI uri = this.getClass() + .getClassLoader() + .getResource(filename) + .toURI(); + return new File(uri); + } catch (Exception e) { + throw new IllegalArgumentException("Unable to find file from resources: " + filename); + } + } + +} diff --git a/core-java-modules/core-java-networking-2/src/main/resources/attachment2.txt b/core-java-modules/core-java-networking-2/src/main/resources/attachment2.txt new file mode 100644 index 0000000000..14c8ea9ff9 --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/main/resources/attachment2.txt @@ -0,0 +1 @@ +sample attachment content 2 \ No newline at end of file diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java index ef82657ab5..04ad47875f 100644 --- a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java +++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/mailwithattachment/MailWithAttachmentServiceLiveTest.java @@ -1,48 +1,77 @@ package com.baeldung.mail.mailwithattachment; -import static org.junit.Assert.*; -import javax.annotation.Resource; -import javax.mail.Session; - -import org.junit.After; +import com.icegreen.greenmail.configuration.GreenMailConfiguration; +import com.icegreen.greenmail.junit.GreenMailRule; +import com.icegreen.greenmail.util.GreenMailUtil; +import com.icegreen.greenmail.util.ServerSetupTest; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; -import com.baeldung.mail.mailwithattachment.MailWithAttachmentService; -import com.icegreen.greenmail.util.GreenMail; -import com.icegreen.greenmail.util.ServerSetupTest; +import javax.annotation.Resource; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; + +import static org.junit.Assert.assertEquals; public class MailWithAttachmentServiceLiveTest { + private static final String USERNAME = "testUser"; + private static final String PASSWORD = "password"; + private static final String HOSTNAME = "localhost"; + + @Rule + public final GreenMailRule greenMail = new GreenMailRule(ServerSetupTest.SMTP) + .withConfiguration( + GreenMailConfiguration.aConfig() + .withUser(USERNAME, PASSWORD) + ); + @Resource private MailWithAttachmentService emailService; - private GreenMail greenMail; @Before - public void startMailServer() { - emailService = new MailWithAttachmentService(); - greenMail = new GreenMail(ServerSetupTest.SMTP); - greenMail.start(); - } - - @After - public void stopMailServer() { - greenMail.stop(); - emailService = null; + public void setup() { + emailService = new MailWithAttachmentService( + USERNAME, PASSWORD, HOSTNAME, greenMail.getSmtp().getPort() + ); } @Test - public void canSendMail() { - try { - Session testSession = greenMail.getSmtp() - .createSession(); - emailService.sendMail(testSession); - assertEquals(1, greenMail.getReceivedMessages().length); - - } catch (Exception e) { - e.printStackTrace(); - } + public void givenEmailService_whenMessageSentWithAttachments_thenMessageIsReceived() throws Exception { + Session tlsSession = emailService.getSession(); + emailService.sendMail(tlsSession); + + MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); + assertEquals(1, receivedMessages.length); + + MimeMessage receivedMessage = receivedMessages[0]; + assertEquals("Testing Subject", subjectFrom(receivedMessage)); + assertEquals("This is message body", emailTextFrom(receivedMessage)); + assertEquals("sample attachment content", attachment1ContentsFrom(receivedMessage)); + assertEquals("sample attachment content 2", attachment2ContentsFrom(receivedMessage)); + } + + private static String subjectFrom(MimeMessage receivedMessage) throws MessagingException { + return receivedMessage.getSubject(); + } + + private static String emailTextFrom(MimeMessage receivedMessage) throws Exception { + return GreenMailUtil.getBody(((MimeMultipart) receivedMessage.getContent()) + .getBodyPart(0)); + } + + private static String attachment1ContentsFrom(MimeMessage receivedMessage) throws Exception { + return GreenMailUtil.getBody(((MimeMultipart) receivedMessage.getContent()) + .getBodyPart(1)); + } + + private static String attachment2ContentsFrom(MimeMessage receivedMessage) throws Exception { + return GreenMailUtil.getBody(((MimeMultipart) receivedMessage.getContent()) + .getBodyPart(2)); } } From fc438ba960222a5e002a9fe8daed0175182f4515 Mon Sep 17 00:00:00 2001 From: Carlos Cavero Date: Sun, 21 Nov 2021 05:19:03 +0100 Subject: [PATCH 57/78] Add val and var examples, unit tests and include flagUsage in lombok.config (#11419) --- .../baeldung/lombok/valvar/ValExample.java | 45 ++++++++++++++++++ .../baeldung/lombok/valvar/VarExample.java | 47 +++++++++++++++++++ .../com/baeldung/lombok/valvar/lombok.config | 2 + .../lombok/valvar/ValExampleUnitTest.java | 24 ++++++++++ .../lombok/valvar/VarExampleUnitTest.java | 20 ++++++++ 5 files changed, 138 insertions(+) create mode 100644 lombok/src/main/java/com/baeldung/lombok/valvar/ValExample.java create mode 100644 lombok/src/main/java/com/baeldung/lombok/valvar/VarExample.java create mode 100644 lombok/src/main/java/com/baeldung/lombok/valvar/lombok.config create mode 100644 lombok/src/test/java/com/baeldung/lombok/valvar/ValExampleUnitTest.java create mode 100644 lombok/src/test/java/com/baeldung/lombok/valvar/VarExampleUnitTest.java diff --git a/lombok/src/main/java/com/baeldung/lombok/valvar/ValExample.java b/lombok/src/main/java/com/baeldung/lombok/valvar/ValExample.java new file mode 100644 index 0000000000..b7ecd95fa8 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/valvar/ValExample.java @@ -0,0 +1,45 @@ +package com.baeldung.lombok.valvar; + +import lombok.val; +import lombok.var; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +public class ValExample { + public Class name() { + val name = "name"; + System.out.println("Name: " + name); + return name.getClass(); + } + + public Class age() { + val age = Integer.valueOf(30); + System.out.println("Age: " + age); + return age.getClass(); + } + + public Class listOf() { + val agenda = new ArrayList(); + agenda.add("Day 1"); + System.out.println("Agenda: " + agenda); + return agenda.getClass(); + } + + public Class mapOf() { + val books = new HashMap(); + books.put(1, "Book 1"); + books.put(2, "Book 2"); + System.out.println("Books:"); + for (val entry : books.entrySet()) { + System.out.printf("- %d. %s\n", entry.getKey(), entry.getValue()); + } + return books.getClass(); + } + + public Class compoundTypes(boolean isArray) { + val compound = isArray ? new ArrayList() : new HashSet(); + return compound.getClass(); + } +} diff --git a/lombok/src/main/java/com/baeldung/lombok/valvar/VarExample.java b/lombok/src/main/java/com/baeldung/lombok/valvar/VarExample.java new file mode 100644 index 0000000000..6fabf66590 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/valvar/VarExample.java @@ -0,0 +1,47 @@ +package com.baeldung.lombok.valvar; + +import lombok.var; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class VarExample { + public String name() { + var name = "name"; + name = "newName"; + System.out.println("Name: " + name); + return name; + } + + public Integer age() { + var age = Integer.valueOf(30); + age = 35; + System.out.println("Age: " + age); + return age; + } + + public ArrayList listOf() { + var agenda = new ArrayList(); + agenda.add("Day 1"); + agenda = new ArrayList(Arrays.asList("Day 2")); + System.out.println("Agenda: " + agenda); + return agenda; + } + + public Map mapOf() { + var books = new HashMap(); + books.put(1, "Book 1"); + books.put(2, "Book 2"); + books = new HashMap(); + books.put(3, "Book 3"); + books.put(4, "Book 4"); + + System.out.println("Books:"); + for (var entry : books.entrySet()) { + System.out.printf("- %d. %s\n", entry.getKey(), entry.getValue()); + } + return books; + } +} diff --git a/lombok/src/main/java/com/baeldung/lombok/valvar/lombok.config b/lombok/src/main/java/com/baeldung/lombok/valvar/lombok.config new file mode 100644 index 0000000000..be6d5d3694 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/valvar/lombok.config @@ -0,0 +1,2 @@ +lombok.var.flagUsage = warning +lombok.val.flagUsage = warning \ No newline at end of file diff --git a/lombok/src/test/java/com/baeldung/lombok/valvar/ValExampleUnitTest.java b/lombok/src/test/java/com/baeldung/lombok/valvar/ValExampleUnitTest.java new file mode 100644 index 0000000000..b8e1102e18 --- /dev/null +++ b/lombok/src/test/java/com/baeldung/lombok/valvar/ValExampleUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.lombok.valvar; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +import static org.assertj.core.api.Assertions.assertThat; + +class ValExampleUnitTest { + + @Test + void whenUsingValWithString_thenTheAssignedClassIsCorrect() { + ValExample val = new ValExample(); + assertThat(val.name()).isEqualTo(String.class); + assertThat(val.age()).isEqualTo(Integer.class); + assertThat(val.listOf()).isEqualTo(ArrayList.class); + assertThat(val.mapOf()).isEqualTo(HashMap.class); + assertThat(val.compoundTypes(true)).isEqualTo(ArrayList.class); + assertThat(val.compoundTypes(false)).isEqualTo(HashSet.class); + } + +} \ No newline at end of file diff --git a/lombok/src/test/java/com/baeldung/lombok/valvar/VarExampleUnitTest.java b/lombok/src/test/java/com/baeldung/lombok/valvar/VarExampleUnitTest.java new file mode 100644 index 0000000000..de6f76f8bb --- /dev/null +++ b/lombok/src/test/java/com/baeldung/lombok/valvar/VarExampleUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.lombok.valvar; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; + +import static org.assertj.core.api.Assertions.assertThat; + +class VarExampleUnitTest { + + @Test + void whenUsingVarWithString_thenTheAssignedClassIsCorrect() { + VarExample varExample = new VarExample(); + assertThat(varExample.name()).isEqualTo("newName"); + assertThat(varExample.age()).isEqualTo(35); + assertThat("Day 2").isIn(varExample.listOf()); + assertThat(varExample.mapOf()).containsValue("Book 3"); + } + +} \ No newline at end of file From 810d7031a6e4b6e5bec334feea9e1b1a3cb68886 Mon Sep 17 00:00:00 2001 From: priya-soni Date: Sun, 21 Nov 2021 21:56:38 +0530 Subject: [PATCH 58/78] Bael 5191 json node get all keys (#11486) * BAEL-5191-JsonNode-Get-All-Keys-From-A-Json-Structure * Added test cases for GetAllKeysFromJSON class methods * Updated test class name * BAEL - 5191 - Updated exception handling --- .../jackson/jsonnode/GetAllKeysFromJSON.java | 109 ++++++------------ .../jsonnode/GetAllKeysFromJSONUnitTest.java | 53 +++++++-- 2 files changed, 77 insertions(+), 85 deletions(-) diff --git a/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java b/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java index d740b457af..bb8e9a8646 100644 --- a/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java +++ b/jackson-modules/jackson/src/main/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSON.java @@ -8,33 +8,27 @@ import java.util.Map; import java.util.Map.Entry; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; public class GetAllKeysFromJSON { - public static List getKeysInJsonUsingMaps(String json, ObjectMapper mapper) { + public List getKeysInJsonUsingMaps(String json, ObjectMapper mapper) throws JsonMappingException, JsonProcessingException { List keys = new ArrayList<>(); - - try { - Map jsonElements = mapper.readValue(json, new TypeReference>() { - }); - getAllKeys(jsonElements, keys); - return keys; - - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - + Map jsonElements = mapper.readValue(json, new TypeReference>() { + }); + getAllKeys(jsonElements, keys); return keys; } - public static void getAllKeys(Map jsonElements, List keys) { + private void getAllKeys(Map jsonElements, List keys) { jsonElements.entrySet() .forEach(entry -> { @@ -54,51 +48,35 @@ public class GetAllKeysFromJSON { }); } - public static List getKeysInJsonUsingJsonNodeFieldNames(String json, ObjectMapper mapper) { + public List getKeysInJsonUsingJsonNodeFieldNames(String json, ObjectMapper mapper) throws JsonMappingException, JsonProcessingException { + List keys = new ArrayList<>(); - - try { - JsonNode jsonNode = mapper.readTree(json); - Iterator iterator = jsonNode.fieldNames(); - iterator.forEachRemaining(e -> keys.add(e)); - - } catch (JsonProcessingException e) { - e.printStackTrace(); - } + JsonNode jsonNode = mapper.readTree(json); + Iterator iterator = jsonNode.fieldNames(); + iterator.forEachRemaining(e -> keys.add(e)); return keys; } - public static List getAllKeysInJsonUsingJsonNodeFieldNames(String json, ObjectMapper mapper) { + public List getAllKeysInJsonUsingJsonNodeFieldNames(String json, ObjectMapper mapper) throws JsonMappingException, JsonProcessingException { + List keys = new ArrayList<>(); - - try { - JsonNode jsonNode = mapper.readTree(json); - getAllKeysUsingJsonNodeFieldNames(jsonNode, keys); - - } catch (JsonProcessingException e) { - e.printStackTrace(); - } + JsonNode jsonNode = mapper.readTree(json); + getAllKeysUsingJsonNodeFieldNames(jsonNode, keys); return keys; } - public static List getAllKeysInJsonUsingJsonNodeFields(String json, ObjectMapper mapper) { + public List getAllKeysInJsonUsingJsonNodeFields(String json, ObjectMapper mapper) throws JsonMappingException, JsonProcessingException { + List keys = new ArrayList<>(); - - try { - JsonNode jsonNode = mapper.readTree(json); - getAllKeysUsingJsonNodeFields(jsonNode, keys); - - } catch (JsonProcessingException e) { - e.printStackTrace(); - } + JsonNode jsonNode = mapper.readTree(json); + getAllKeysUsingJsonNodeFields(jsonNode, keys); return keys; } - public static void getAllKeysUsingJsonNodeFields(JsonNode jsonNode, List keys) { + private void getAllKeysUsingJsonNodeFields(JsonNode jsonNode, List keys) { if (jsonNode.isObject()) { Iterator> fields = jsonNode.fields(); - fields.forEachRemaining(field -> { keys.add(field.getKey()); getAllKeysUsingJsonNodeFieldNames((JsonNode) field.getValue(), keys); @@ -112,11 +90,10 @@ public class GetAllKeysFromJSON { } - public static void getAllKeysUsingJsonNodeFieldNames(JsonNode jsonNode, List keys) { + private void getAllKeysUsingJsonNodeFieldNames(JsonNode jsonNode, List keys) { if (jsonNode.isObject()) { Iterator fieldNames = jsonNode.fieldNames(); - fieldNames.forEachRemaining(fieldName -> { keys.add(fieldName); getAllKeysUsingJsonNodeFieldNames(jsonNode.get(fieldName), keys); @@ -130,43 +107,29 @@ public class GetAllKeysFromJSON { } - public static List getKeysInJsonUsingJsonParser(String json, ObjectMapper mapper) { + public List getKeysInJsonUsingJsonParser(String json, ObjectMapper mapper) throws IOException { + List keys = new ArrayList<>(); - - try { - JsonNode jsonNode = mapper.readTree(json); - JsonParser jsonParser = jsonNode.traverse(); - while (!jsonParser.isClosed()) { - if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { - keys.add((jsonParser.getCurrentName())); - } + JsonNode jsonNode = mapper.readTree(json); + JsonParser jsonParser = jsonNode.traverse(); + while (!jsonParser.isClosed()) { + if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { + keys.add((jsonParser.getCurrentName())); } - } catch (JsonProcessingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } - return keys; } - public static List getKeysInJsonUsingJsonParser(String json) { + public List getKeysInJsonUsingJsonParser(String json) throws JsonParseException, IOException { + List keys = new ArrayList<>(); - - try { - JsonFactory factory = new JsonFactory(); - JsonParser jsonParser = factory.createParser(json); - while (!jsonParser.isClosed()) { - if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { - keys.add((jsonParser.getCurrentName())); - } + JsonFactory factory = new JsonFactory(); + JsonParser jsonParser = factory.createParser(json); + while (!jsonParser.isClosed()) { + if (jsonParser.nextToken() == JsonToken.FIELD_NAME) { + keys.add((jsonParser.getCurrentName())); } - } catch (JsonProcessingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } - return keys; } } diff --git a/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java b/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java index b547422aad..5d0558ca63 100644 --- a/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java +++ b/jackson-modules/jackson/src/test/java/com/baeldung/jackson/jsonnode/GetAllKeysFromJSONUnitTest.java @@ -2,10 +2,12 @@ package com.baeldung.jackson.jsonnode; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.IOException; import java.util.List; import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class GetAllKeysFromJSONUnitTest { @@ -16,41 +18,68 @@ public class GetAllKeysFromJSONUnitTest { + " }\r\n" + " ]\r\n" + " }\r\n" + "}"; private static ObjectMapper mapper = new ObjectMapper(); + private static GetAllKeysFromJSON getAllKeysFromJSONUtil = new GetAllKeysFromJSON(); // Top level keys : [Name, Age, BookInterests, FoodInterests] // All keys: [Name, Age, BookInterests, Book, Author, Book, Author, FoodInterests, Breakfast, Bread, Beverage, Sandwich, Beverage] @Test public void givenAJsonNode_whenUsingFieldNamesMethod_thenWeGetTopFieldNames() { - List keys = GetAllKeysFromJSON.getKeysInJsonUsingJsonNodeFieldNames(json, mapper); - assertEquals(4, keys.size()); + List keys; + try { + keys = getAllKeysFromJSONUtil.getKeysInJsonUsingJsonNodeFieldNames(json, mapper); + assertEquals(4, keys.size()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } @Test public void givenAJsonNode_whenUsingFieldNamesMethodForAllNodes_thenWeGetAllFieldNames() { - List keys = GetAllKeysFromJSON.getAllKeysInJsonUsingJsonNodeFieldNames(json, mapper); - assertEquals(13, keys.size()); + List keys; + try { + keys = getAllKeysFromJSONUtil.getAllKeysInJsonUsingJsonNodeFieldNames(json, mapper); + assertEquals(13, keys.size()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } @Test public void givenAJsonNode_whenUsingFieldsMethod_thenWeGetAllFieldNames() { - List keys = GetAllKeysFromJSON.getAllKeysInJsonUsingJsonNodeFields(json, mapper); - assertEquals(13, keys.size()); + List keys; + try { + keys = getAllKeysFromJSONUtil.getAllKeysInJsonUsingJsonNodeFields(json, mapper); + assertEquals(13, keys.size()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } @Test public void givenAJsonNode_whenUsingJsonParserMethod_thenWeGetAllFieldNames() { - List keys = GetAllKeysFromJSON.getKeysInJsonUsingJsonParser(json, mapper); - assertEquals(13, keys.size()); + List keys; + try { + keys = getAllKeysFromJSONUtil.getKeysInJsonUsingJsonParser(json, mapper); + assertEquals(13, keys.size()); + + keys = getAllKeysFromJSONUtil.getKeysInJsonUsingJsonParser(json); + assertEquals(13, keys.size()); + } catch (IOException e) { + e.printStackTrace(); + } - keys = GetAllKeysFromJSON.getKeysInJsonUsingJsonParser(json); - assertEquals(13, keys.size()); } @Test public void givenAJsonNode_whenUsingMaps_thenWeGetAllFieldNames() { - List keys = GetAllKeysFromJSON.getKeysInJsonUsingMaps(json, mapper); - assertEquals(13, keys.size()); + List keys; + try { + keys = getAllKeysFromJSONUtil.getKeysInJsonUsingMaps(json, mapper); + assertEquals(13, keys.size()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } } From 3caa9fdbbe72193e9c1d25fb316ec74f91f68e7b Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Sun, 21 Nov 2021 20:25:21 +0100 Subject: [PATCH 59/78] add invoking static methods (#11439) --- .../access/staticmethods/GreetingAndBye.java | 12 ++++++++ .../GreetingAndByeClassUnitTest.java | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/staticmethods/GreetingAndBye.java create mode 100644 core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/GreetingAndByeClassUnitTest.java diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/staticmethods/GreetingAndBye.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/staticmethods/GreetingAndBye.java new file mode 100644 index 0000000000..471ed1ee5b --- /dev/null +++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/staticmethods/GreetingAndBye.java @@ -0,0 +1,12 @@ +package com.baeldung.reflection.access.staticmethods; + +public class GreetingAndBye { + + public static String greeting(String name) { + return String.format("Hey %s, nice to meet you!", name); + } + + private static String goodBye(String name) { + return String.format("Bye %s, see you next time.", name); + } +} diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/GreetingAndByeClassUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/GreetingAndByeClassUnitTest.java new file mode 100644 index 0000000000..da82d2370c --- /dev/null +++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/GreetingAndByeClassUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.reflection.check.abstractclass; + +import com.baeldung.reflection.access.staticmethods.GreetingAndBye; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +class GreetingAndByeUnitTest { + + @Test + void givenPublicStaticMethod_whenCallWithReflection_thenReturnExpectedResult() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Class clazz = GreetingAndBye.class; + Method method = clazz.getMethod("greeting", String.class); + Object result = method.invoke(null, "Eric"); + Assertions.assertEquals("Hey Eric, nice to meet you!", result); + } + + @Test + void givenPrivateStaticMethod_whenCallWithReflection_thenReturnExpectedResult() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Class clazz = GreetingAndBye.class; + Method method = clazz.getDeclaredMethod("goodBye", String.class); + method.setAccessible(true); + Object result = method.invoke(null, "Eric"); + Assertions.assertEquals("Bye Eric, see you next time.", result); + } +} From 6a5cc13f37bc6119329802ce8a7b560e8d34023c Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Sun, 21 Nov 2021 21:18:55 +0000 Subject: [PATCH 60/78] [JAVA-8353] Update the test to wait for assertion with timeout --- .../illegalmonitorstate/SynchronizedReceiver.java | 8 +++++--- .../illegalmonitorstate/SynchronizedSender.java | 8 +++++--- .../illegalmonitorstate/UnsynchronizedReceiver.java | 7 ++++--- .../illegalmonitorstate/UnsynchronizedSender.java | 7 ++++--- .../IllegalMonitorStateExceptionUnitTest.java | 8 +++++--- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java index ff6b926cdc..8b0aa95153 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java @@ -4,7 +4,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SynchronizedReceiver implements Runnable { - private static Logger log = LoggerFactory.getLogger(SynchronizedReceiver.class); + + private static final Logger LOG = LoggerFactory.getLogger(SynchronizedReceiver.class); + private final Data data; private String message; private boolean illegalMonitorStateExceptionOccurred; @@ -20,10 +22,10 @@ public class SynchronizedReceiver implements Runnable { data.wait(); this.message = data.receive(); } catch (InterruptedException e) { - log.error("thread was interrupted", e); + LOG.error("thread was interrupted", e); Thread.currentThread().interrupt(); } catch (IllegalMonitorStateException e) { - log.error("illegal monitor state exception occurred", e); + LOG.error("illegal monitor state exception occurred", e); illegalMonitorStateExceptionOccurred = true; } } diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java index 1618bc8efa..8317b5ade7 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java @@ -4,7 +4,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SynchronizedSender implements Runnable { - private static Logger log = LoggerFactory.getLogger(SynchronizedSender.class); + + private static final Logger LOG = LoggerFactory.getLogger(SynchronizedSender.class); + private final Data data; private boolean illegalMonitorStateExceptionOccurred; @@ -22,10 +24,10 @@ public class SynchronizedSender implements Runnable { data.notifyAll(); } catch (InterruptedException e) { - log.error("thread was interrupted", e); + LOG.error("thread was interrupted", e); Thread.currentThread().interrupt(); } catch (IllegalMonitorStateException e) { - log.error("illegal monitor state exception occurred", e); + LOG.error("illegal monitor state exception occurred", e); illegalMonitorStateExceptionOccurred = true; } } diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java index 3a0b72e6cd..69fb363731 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java @@ -4,7 +4,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class UnsynchronizedReceiver implements Runnable { - private static Logger log = LoggerFactory.getLogger(UnsynchronizedReceiver.class); + private static final Logger LOG = LoggerFactory.getLogger(UnsynchronizedReceiver.class); + private final Data data; private String message; private boolean illegalMonitorStateExceptionOccurred; @@ -19,10 +20,10 @@ public class UnsynchronizedReceiver implements Runnable { data.wait(); this.message = data.receive(); } catch (InterruptedException e) { - log.error("thread was interrupted", e); + LOG.error("thread was interrupted", e); Thread.currentThread().interrupt(); } catch (IllegalMonitorStateException e) { - log.error("illegal monitor state exception occurred", e); + LOG.error("illegal monitor state exception occurred", e); illegalMonitorStateExceptionOccurred = true; } } diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java index 7f15418bfa..b97453f655 100644 --- a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java +++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java @@ -4,7 +4,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class UnsynchronizedSender implements Runnable { - private static Logger log = LoggerFactory.getLogger(UnsynchronizedSender.class); + private static final Logger LOG = LoggerFactory.getLogger(UnsynchronizedSender.class); + private final Data data; private boolean illegalMonitorStateExceptionOccurred; @@ -21,10 +22,10 @@ public class UnsynchronizedSender implements Runnable { data.notifyAll(); } catch (InterruptedException e) { - log.error("thread was interrupted", e); + LOG.error("thread was interrupted", e); Thread.currentThread().interrupt(); } catch (IllegalMonitorStateException e) { - log.error("illegal monitor state exception occurred", e); + LOG.error("illegal monitor state exception occurred", e); illegalMonitorStateExceptionOccurred = true; } } diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java index 82c00bc72f..d19c75b2fa 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java @@ -1,7 +1,10 @@ package com.baeldung.exceptions.illegalmonitorstate; +import com.google.common.util.concurrent.Uninterruptibles; import org.junit.jupiter.api.Test; +import java.time.Duration; + import static org.junit.jupiter.api.Assertions.*; public class IllegalMonitorStateExceptionUnitTest { @@ -20,10 +23,9 @@ public class IllegalMonitorStateExceptionUnitTest { senderThread.join(1000); receiverThread.join(1000); - - Thread.sleep(2000); - assertEquals("test", receiver.getMessage()); + // we need to wait for enough time so that sender has had a chance to send the data + assertTimeout(Duration.ofSeconds(5), () -> assertEquals("test", receiver.getMessage())); assertFalse(sender.hasIllegalMonitorStateExceptionOccurred()); assertFalse(receiver.hasIllegalMonitorStateExceptionOccurred()); } From af26a72a955fd1a0a5ed10c1bee2fc7b764b25de Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Sun, 21 Nov 2021 21:24:02 +0000 Subject: [PATCH 61/78] [JAVA-8353] Increase timeout to 10s --- .../IllegalMonitorStateExceptionUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java index d19c75b2fa..28c317a1c9 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java @@ -25,7 +25,7 @@ public class IllegalMonitorStateExceptionUnitTest { receiverThread.join(1000); // we need to wait for enough time so that sender has had a chance to send the data - assertTimeout(Duration.ofSeconds(5), () -> assertEquals("test", receiver.getMessage())); + assertTimeout(Duration.ofSeconds(10), () -> assertEquals("test", receiver.getMessage())); assertFalse(sender.hasIllegalMonitorStateExceptionOccurred()); assertFalse(receiver.hasIllegalMonitorStateExceptionOccurred()); } From 6964f93f4efd276f31d8d3907eed4046967a86b6 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Mon, 22 Nov 2021 08:05:55 +0000 Subject: [PATCH 62/78] [JAVA-8353] Code clean up --- .../IllegalMonitorStateExceptionUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java index 28c317a1c9..bef90e671f 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.exceptions.illegalmonitorstate; -import com.google.common.util.concurrent.Uninterruptibles; import org.junit.jupiter.api.Test; import java.time.Duration; From dd723178259404328b54889e20945fded7f33b3d Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 22 Nov 2021 10:35:16 +0100 Subject: [PATCH 63/78] JAVA-8021: Use AssertJ 1.6.0 in the restx module --- restx/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/restx/pom.xml b/restx/pom.xml index 57736f60cd..953b56e2f3 100644 --- a/restx/pom.xml +++ b/restx/pom.xml @@ -147,6 +147,7 @@ 0.35-rc4 + 1.6.0 \ No newline at end of file From 30a22bca95844589f0ae73b220b15d3df5e5be1d Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 22 Nov 2021 11:34:09 +0100 Subject: [PATCH 64/78] JAVA-8320: Upgrade Spring version to 5.3.13 --- parent-spring-5/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index 1263a56e2b..a062084a81 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -24,7 +24,7 @@ - 5.3.9 + 5.3.13 5.2.3.RELEASE 1.5.10.RELEASE From 8e84a81250c4dbd1bbeb02a811d0c8f1b0b36f04 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 22 Nov 2021 16:23:15 +0100 Subject: [PATCH 65/78] JAVA-8320: Upgrade Spring Security to 5.6.0 --- parent-spring-5/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index a062084a81..175e8d58f9 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -25,7 +25,7 @@ 5.3.13 - 5.2.3.RELEASE + 5.6.0 1.5.10.RELEASE From 201ed945022dfc502433663444e2179d0c79c6c8 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 22 Nov 2021 21:17:12 +0100 Subject: [PATCH 66/78] JAVA-8320: Use spring.version property in the spring-di module --- spring-di/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spring-di/pom.xml b/spring-di/pom.xml index 20207663cf..a7fa65067b 100644 --- a/spring-di/pom.xml +++ b/spring-di/pom.xml @@ -20,14 +20,14 @@ org.springframework spring-framework-bom - ${org.springframework.version} + ${spring.version} pom import org.springframework spring-core - ${org.springframework.version} + ${spring.version} @@ -143,7 +143,6 @@ org.baeldung.org.baeldung.sample.App - 5.0.6.RELEASE 1.3.2 1.4.4.RELEASE 1 From 6d824ecf7ccc534211821797255d7fc46e8783e3 Mon Sep 17 00:00:00 2001 From: chaos2418 <> Date: Tue, 23 Nov 2021 09:14:57 +0530 Subject: [PATCH 67/78] JAVA-8637: addressing PR review comments. --- .../java8/lambda/exceptions/LambdaExceptionWrappers.java | 6 +++--- .../src/main/resources/application.properties | 2 +- .../src/test/java/com/baeldung/SpringContextTest.java | 1 - .../baeldung/partialupdate/PartialUpdateUnitTest.java | 1 - .../com/baeldung/ehcache/SquareCalculatorUnitTest.java | 9 +++------ 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java index ce33aaf237..db710589e7 100644 --- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java +++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappers.java @@ -14,7 +14,7 @@ public class LambdaExceptionWrappers { try { consumer.accept(i); } catch (ArithmeticException e) { - LOGGER.error("Arithmetic Exception occured : {}", e.getMessage()); + LOGGER.error("Arithmetic Exception occurred.", e); } }; } @@ -26,7 +26,7 @@ public class LambdaExceptionWrappers { } catch (Exception ex) { try { E exCast = clazz.cast(ex); - LOGGER.error("Exception occured : {}", exCast.getMessage()); + LOGGER.error("Exception occurred.", exCast); } catch (ClassCastException ccEx) { throw ex; } @@ -51,7 +51,7 @@ public class LambdaExceptionWrappers { } catch (Exception ex) { try { E exCast = exceptionClass.cast(ex); - LOGGER.error("Exception occured : {}", exCast.getMessage()); + LOGGER.error("Exception occurred.", exCast); } catch (ClassCastException ccEx) { throw new RuntimeException(ex); } diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties index 32d3e640f9..0ca1872207 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties @@ -9,7 +9,7 @@ spring.datasource.url=jdbc:h2:mem:baeldung #spring.jpa.properties.javax.persistence.schema-generation.scripts.create-source=metadata #spring.jpa.properties.hibernate.format_sql=true -spring.jpa.show-sql=true +spring.jpa.show-sql=false #hibernate.dialect=org.hibernate.dialect.H2Dialect spring.jpa.properties.hibernate.id.new_generator_mappings=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java index 67ce958c64..0c735d3599 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java @@ -10,7 +10,6 @@ import com.baeldung.boot.Application; @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) -@TestPropertySource(properties = {"spring.jpa.show-sql=false "}) public class SpringContextTest { @Test diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java index e217ef590e..4a70d409df 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java @@ -17,7 +17,6 @@ import com.baeldung.partialupdate.service.CustomerService; @RunWith(SpringRunner.class) @SpringBootTest(classes = PartialUpdateApplication.class) -@TestPropertySource(properties = {"spring.jpa.show-sql=false "}) public class PartialUpdateUnitTest { @Autowired diff --git a/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java b/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java index 311b7c575e..6a6c51bd9e 100644 --- a/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java +++ b/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java @@ -25,8 +25,7 @@ public class SquareCalculatorUnitTest { @Test public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() { for (int i = 10; i < 15; i++) { - assertFalse(cacheHelper.getSquareNumberCache() - .containsKey(i)); + assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); LOGGER.debug("Square value of {} is: {}", i, squaredCalculator.getSquareValueOfNumber(i)); } } @@ -34,14 +33,12 @@ public class SquareCalculatorUnitTest { @Test public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() { for (int i = 10; i < 15; i++) { - assertFalse(cacheHelper.getSquareNumberCache() - .containsKey(i)); + assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); LOGGER.debug("Square value of {} is: {}", i, squaredCalculator.getSquareValueOfNumber(i)); } for (int i = 10; i < 15; i++) { - assertTrue(cacheHelper.getSquareNumberCache() - .containsKey(i)); + assertTrue(cacheHelper.getSquareNumberCache().containsKey(i)); LOGGER.debug("Square value of {} is: {}", i, squaredCalculator.getSquareValueOfNumber(i) + "\n"); } } From 566c5e5b443bdd01c7836fb36d539f8cc1b5fb07 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 23 Nov 2021 06:26:31 +0100 Subject: [PATCH 68/78] BAEL-5242: Add surefire config for TestNG (#11471) * BAEL-5242: Add surefire config for TestNG * BAEL-5242: Configure surefire to run unit and integration tests --- testing-modules/testng/pom.xml | 45 +++++++++++++++++-- .../testng/src/test/resources/test_int.xml | 10 +++++ .../testng/src/test/resources/test_unit.xml | 9 ++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 testing-modules/testng/src/test/resources/test_int.xml create mode 100644 testing-modules/testng/src/test/resources/test_unit.xml diff --git a/testing-modules/testng/pom.xml b/testing-modules/testng/pom.xml index 99af6be5b4..5d3bf6b560 100644 --- a/testing-modules/testng/pom.xml +++ b/testing-modules/testng/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 testng 0.1.0-SNAPSHOT @@ -16,7 +16,6 @@ - org.testng testng @@ -41,8 +40,46 @@ + + + default-second + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src\test\resources\parametrized_testng.xml + src\test\resources\test_suite.xml + src\test\resources\test_unit.xml + + + + + + + + integration-lite-second + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src\test\resources\test_group.xml + src\test\resources\test_setup.xml + src\test\resources\test_int.xml + + + + + + + + - 7.1.0 diff --git a/testing-modules/testng/src/test/resources/test_int.xml b/testing-modules/testng/src/test/resources/test_int.xml new file mode 100644 index 0000000000..9eb86739b6 --- /dev/null +++ b/testing-modules/testng/src/test/resources/test_int.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/testing-modules/testng/src/test/resources/test_unit.xml b/testing-modules/testng/src/test/resources/test_unit.xml new file mode 100644 index 0000000000..76c97db735 --- /dev/null +++ b/testing-modules/testng/src/test/resources/test_unit.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file From 4fcedd72547ec43ebf537f309218fc0f22984ac8 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 13:56:24 +0800 Subject: [PATCH 69/78] Update README.md --- core-java-modules/core-java-string-operations-4/README.md | 1 + 1 file changed, 1 insertion(+) 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 304f604c5e..be4c9ae05f 100644 --- a/core-java-modules/core-java-string-operations-4/README.md +++ b/core-java-modules/core-java-string-operations-4/README.md @@ -1,4 +1,5 @@ ### Relevant Articles: - [Ignoring Commas in Quotes When Splitting a Comma-separated String](https://www.baeldung.com/java-split-string-commas) +- [Compare Strings While Ignoring Whitespace in Java](https://www.baeldung.com/java-compare-string-whitespace) From 305cc505e8f857ed504e590c75a56cf7cc9a9125 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 13:57:47 +0800 Subject: [PATCH 70/78] Update README.md --- core-java-modules/core-java-security-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-3/README.md b/core-java-modules/core-java-security-3/README.md index 10e9773f9b..30cfd8a947 100644 --- a/core-java-modules/core-java-security-3/README.md +++ b/core-java-modules/core-java-security-3/README.md @@ -7,4 +7,5 @@ This module contains articles about core Java Security - [Secret Key and String Conversion in Java](https://www.baeldung.com/java-secret-key-to-string) - [Enabling Unlimited Strength Cryptography in Java](https://www.baeldung.com/jce-enable-unlimited-strength) - [Initialization Vector for Encryption](https://www.baeldung.com/java-encryption-iv) +- [HMAC in Java](https://www.baeldung.com/java-hmac) - More articles: [[<-- prev]](/core-java-modules/core-java-security-2) From c6bbbe680e8350dc8c6507c0ca65583097d358be Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 13:59:36 +0800 Subject: [PATCH 71/78] Update README.md --- lombok/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lombok/README.md b/lombok/README.md index bda960a28a..e1dd58abf2 100644 --- a/lombok/README.md +++ b/lombok/README.md @@ -12,3 +12,4 @@ This module contains articles about Project Lombok. - [Setting up Lombok with Eclipse and Intellij](https://www.baeldung.com/lombok-ide) - [Using the @Singular Annotation with Lombok Builders](https://www.baeldung.com/lombok-builder-singular) - [Using Lombok’s @Accessors Annotation](https://www.baeldung.com/lombok-accessors) +- [Omitting Getter or Setter in Lombok](https://www.baeldung.com/lombok-omit-getter-setter) From 545abb7360ad83c52c39dde90a6b6c3239314421 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:01:23 +0800 Subject: [PATCH 72/78] Update README.md --- lombok/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lombok/README.md b/lombok/README.md index e1dd58abf2..b8073ff621 100644 --- a/lombok/README.md +++ b/lombok/README.md @@ -3,6 +3,7 @@ This module contains articles about Project Lombok. ### Relevant Articles: + - [Introduction to Project Lombok](https://www.baeldung.com/intro-to-project-lombok) - [Using Lombok’s @Builder Annotation](https://www.baeldung.com/lombok-builder) - [Using Lombok’s @Getter for Boolean Fields](https://www.baeldung.com/lombok-getter-boolean) @@ -13,3 +14,4 @@ This module contains articles about Project Lombok. - [Using the @Singular Annotation with Lombok Builders](https://www.baeldung.com/lombok-builder-singular) - [Using Lombok’s @Accessors Annotation](https://www.baeldung.com/lombok-accessors) - [Omitting Getter or Setter in Lombok](https://www.baeldung.com/lombok-omit-getter-setter) +- [Declaring Val and Var Variables in Lombok](https://www.baeldung.com/java-lombok-val-var) From 66cf8286da44967bc1fc5548e161a0b3daec521f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:15:26 +0800 Subject: [PATCH 73/78] Update README.md --- core-java-modules/core-java-reflection-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-reflection-2/README.md b/core-java-modules/core-java-reflection-2/README.md index 4c888bdf58..c1966dd63d 100644 --- a/core-java-modules/core-java-reflection-2/README.md +++ b/core-java-modules/core-java-reflection-2/README.md @@ -6,3 +6,4 @@ - [Checking if a Java Class is ‘abstract’ Using Reflection](https://www.baeldung.com/java-reflection-is-class-abstract) - [Invoking a Private Method in Java](https://www.baeldung.com/java-call-private-method) - [Finding All Classes in a Java Package](https://www.baeldung.com/java-find-all-classes-in-package) +- [Invoke a Static Method Using Java Reflection API](https://www.baeldung.com/java-invoke-static-method-reflection) From 3f261aee2f1841b01fbc36d730f8fe8d985b32b1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:17:59 +0800 Subject: [PATCH 74/78] Update README.md --- apache-poi/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/apache-poi/README.md b/apache-poi/README.md index 13d62eeba0..d3d60358c5 100644 --- a/apache-poi/README.md +++ b/apache-poi/README.md @@ -14,3 +14,4 @@ This module contains articles about Apache POI - [Insert a Row in Excel Using Apache POI](https://www.baeldung.com/apache-poi-insert-excel-row) - [Multiline Text in Excel Cell Using Apache POI](https://www.baeldung.com/apache-poi-write-multiline-text) - [Set Background Color of a Cell with Apache POI](https://www.baeldung.com/apache-poi-background-color) +- [Add Borders to Excel Cells With Apache POI](https://www.baeldung.com/apache-poi-add-borders) From 3bafe7774ef195ba6684be9113dc3f35c74d4f6f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:20:24 +0800 Subject: [PATCH 75/78] Update README.md --- jackson-modules/jackson/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jackson-modules/jackson/README.md b/jackson-modules/jackson/README.md index 50e13a5b75..0aa3dc5aef 100644 --- a/jackson-modules/jackson/README.md +++ b/jackson-modules/jackson/README.md @@ -6,9 +6,11 @@ This module contains articles about Jackson. The "REST With Spring" Classes: http://bit.ly/restwithspring -### Relevant Articles: +### Relevant Articles: + - [Using Optional with Jackson](https://www.baeldung.com/jackson-optional) - [Compare Two JSON Objects with Jackson](https://www.baeldung.com/jackson-compare-two-json-objects) - [Jackson vs Gson](https://www.baeldung.com/jackson-vs-gson) - [Inheritance with Jackson](https://www.baeldung.com/jackson-inheritance) - [Working with Tree Model Nodes in Jackson](https://www.baeldung.com/jackson-json-node-tree-model) +- [Get all the Keys in a JSON String Using JsonNode](https://www.baeldung.com/java-jsonnode-get-keys) From d7a99fe9aa3beaaa9440b4cb61c6fad1faf08ec5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:23:37 +0800 Subject: [PATCH 76/78] Update README.md --- testing-modules/testing-assertions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-assertions/README.md b/testing-modules/testing-assertions/README.md index bf35505211..2349834fa3 100644 --- a/testing-modules/testing-assertions/README.md +++ b/testing-modules/testing-assertions/README.md @@ -3,3 +3,4 @@ - [Asserting Log Messages With JUnit](https://www.baeldung.com/junit-asserting-logs) - [Assert Two Lists for Equality Ignoring Order in Java](https://www.baeldung.com/java-assert-lists-equality-ignore-order) - [Assert That a Java Optional Has a Certain Value](https://www.baeldung.com/java-optional-assert-value) +- [Assert that an Object is from a Specific Type](https://www.baeldung.com/java-assert-object-of-type) From af150e03017b4539aeb4550039726ae774045194 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 24 Nov 2021 09:47:43 +0100 Subject: [PATCH 77/78] JAVA-8664: Change ports numbers and cleanup the code --- .../java/com/baeldung/ctx1/Ctx1Controller.java | 14 +++++--------- .../java/com/baeldung/ctx2/Ctx2Controller.java | 7 +++---- .../src/main/resources/ctx1.properties | 2 +- .../src/main/resources/ctx2.properties | 2 +- .../test/java/com/baeldung/SpringContextTest.java | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java b/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java index 9c7667db35..2de42251e4 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java +++ b/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java @@ -1,22 +1,18 @@ package com.baeldung.ctx1; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - import com.baeldung.parent.IHomeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class Ctx1Controller { @Autowired - IHomeService homeService; + private IHomeService homeService; @GetMapping("/home") - @ResponseBody public String greeting() { - return homeService.getGreeting(); } } diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java b/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java index 850fd8021c..65790141bb 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java +++ b/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java @@ -1,18 +1,17 @@ package com.baeldung.ctx2; +import com.baeldung.parent.IHomeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.parent.IHomeService; - @RestController public class Ctx2Controller { @Autowired - IHomeService homeService; + private IHomeService homeService; - @GetMapping(value = "/greeting", produces = "application/json") + @GetMapping(value = "/greeting") public String getGreeting() { return homeService.getGreeting(); } diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx1.properties b/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx1.properties index 2b618d4177..d0af43abdd 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx1.properties +++ b/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx1.properties @@ -1,4 +1,4 @@ -server.port=8081 +server.port=8074 server.servlet.context-path=/ctx1 #logging.level=debug spring.application.admin.enabled=false diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx2.properties b/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx2.properties index f3599e17e0..7cd48d2f07 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx2.properties +++ b/spring-boot-modules/spring-boot-ctx-fluent/src/main/resources/ctx2.properties @@ -1,4 +1,4 @@ -server.port=8082 +server.port=8075 server.servlet.context-path=/ctx2 spring.application.admin.enabled=false diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java index ca8989724b..07242452bf 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/com/baeldung/SpringContextTest.java @@ -7,7 +7,7 @@ import com.baeldung.parent.App; public class SpringContextTest { @Test - public final void testMain() throws Exception { + public final void testMain() { App.main(new String[] {}); } } From 2cb6b278319333184e2f7b06b422a11d15d9cbd6 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 24 Nov 2021 09:51:22 +0100 Subject: [PATCH 78/78] JAVA-8664: Cleanup --- .../src/main/java/com/baeldung/ctx2/Ctx2Controller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java b/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java index 65790141bb..1b7edf6710 100644 --- a/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java +++ b/spring-boot-modules/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java @@ -11,7 +11,7 @@ public class Ctx2Controller { @Autowired private IHomeService homeService; - @GetMapping(value = "/greeting") + @GetMapping("/greeting") public String getGreeting() { return homeService.getGreeting(); }