From b2e89f35748f30ab67abf11dc8d9cb15ca25d3f8 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Mon, 29 Jan 2024 14:46:50 +0100 Subject: [PATCH 01/51] BAEL-7131 version 1 - POST REPO re-writing the commit history issue. --- .../baeldung/inputstream/InputStreamTest.java | 58 +++++++++++++++++++ .../InputStreamReaderTest.java | 40 +++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java create mode 100644 core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java new file mode 100644 index 0000000000..7aca698446 --- /dev/null +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java @@ -0,0 +1,58 @@ +package com.baeldung.inputstream; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class InputStreamTest { + + @Test + public void givenAString_whenWrittenToFileInputStream_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { + + Path sampleOut = tempDir.resolve("sample-out.txt"); + List lines = Arrays.asList("Hello. This is just a test. Good bye."); + Files.write(sampleOut, lines); + File sampleOutFile = sampleOut.toFile(); + try(InputStream inputStream = new FileInputStream(sampleOutFile)){ + Assert.assertTrue(readString(inputStream).contains(lines.get(0))); + } + } + + @Test + public void givenAString_whenWrittenToByteArrayInputStream_thenShouldMatchWhenRead() throws IOException { + byte[] byteArray = {104, 101, 108, 108,111}; + try(ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)){ + int content; + StringBuilder actualReadText = new StringBuilder(); + while ((content = bais.read()) != -1) { + actualReadText.append((char) content); + } + Assert.assertEquals( "hello",actualReadText.toString()); + } + + } + + private static String readString(InputStream inputStream) throws IOException { + String strRet = ""; + int c; + StringBuilder sb = new StringBuilder(); + while(!((c = inputStream.read()) != -1)) { + sb.append((char) c); + } + strRet = sb.toString(); + + return strRet; + } + + +} diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java new file mode 100644 index 0000000000..7009297c86 --- /dev/null +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java @@ -0,0 +1,40 @@ +package com.baeldung.inputstreamreader; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class InputStreamReaderTest { + + @Test + public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { + boolean isMatched = false; + String sampleTxt = "Good day. This is just a test. Good bye."; + Path sampleOut = tempDir.resolve("sample-out.txt"); + List lines = Arrays.asList(sampleTxt); + //create and write file + Files.write(sampleOut, lines); + try(FileInputStream fis = new FileInputStream(String.valueOf(sampleOut.toAbsolutePath())); + BufferedReader br = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8));){ + String ln; + while((ln = br.readLine())!= null){ + if(ln.contains(sampleTxt)){ + isMatched = true; + break; + } + } + Assert.assertTrue(isMatched); + } + } + +} From 8aea75fd05c3db2de07e8afacdc5e4d10d3e6913 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Sat, 10 Feb 2024 23:44:42 +0100 Subject: [PATCH 02/51] BAEL-7131 version 2 - code review comments. --- .../baeldung/inputstream/InputStreamTest.java | 29 +++++-------------- .../InputStreamReaderTest.java | 10 ++----- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java index 7aca698446..b238067654 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java @@ -13,46 +13,31 @@ import java.util.List; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - public class InputStreamTest { - @Test public void givenAString_whenWrittenToFileInputStream_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { - Path sampleOut = tempDir.resolve("sample-out.txt"); List lines = Arrays.asList("Hello. This is just a test. Good bye."); Files.write(sampleOut, lines); File sampleOutFile = sampleOut.toFile(); - try(InputStream inputStream = new FileInputStream(sampleOutFile)){ + try (InputStream inputStream = new FileInputStream(sampleOutFile)) { Assert.assertTrue(readString(inputStream).contains(lines.get(0))); } } - @Test public void givenAString_whenWrittenToByteArrayInputStream_thenShouldMatchWhenRead() throws IOException { - byte[] byteArray = {104, 101, 108, 108,111}; - try(ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)){ - int content; - StringBuilder actualReadText = new StringBuilder(); - while ((content = bais.read()) != -1) { - actualReadText.append((char) content); - } - Assert.assertEquals( "hello",actualReadText.toString()); + byte[] byteArray = { 104, 101, 108, 108, 111 }; + try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) { + String expected = readString(bais); + Assert.assertEquals("hello", expected); } - } - private static String readString(InputStream inputStream) throws IOException { - String strRet = ""; int c; StringBuilder sb = new StringBuilder(); - while(!((c = inputStream.read()) != -1)) { + while ((c = inputStream.read()) != -1) { sb.append((char) c); } - strRet = sb.toString(); - - return strRet; + return sb.toString(); } - - } diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java index 7009297c86..d14a96c9a0 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java @@ -13,9 +13,7 @@ import java.util.List; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - public class InputStreamReaderTest { - @Test public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { boolean isMatched = false; @@ -24,11 +22,10 @@ public class InputStreamReaderTest { List lines = Arrays.asList(sampleTxt); //create and write file Files.write(sampleOut, lines); - try(FileInputStream fis = new FileInputStream(String.valueOf(sampleOut.toAbsolutePath())); - BufferedReader br = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8));){ + try (FileInputStream fis = new FileInputStream(String.valueOf(sampleOut.toAbsolutePath())); BufferedReader br = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8))) { String ln; - while((ln = br.readLine())!= null){ - if(ln.contains(sampleTxt)){ + while ((ln = br.readLine()) != null) { + if (ln.contains(sampleTxt)) { isMatched = true; break; } @@ -36,5 +33,4 @@ public class InputStreamReaderTest { Assert.assertTrue(isMatched); } } - } From 94fceedf7c2de5963add1f23f6ed6bcc38baf418 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Sun, 11 Feb 2024 19:11:39 +0100 Subject: [PATCH 03/51] BAEL-7131 version 3 - code review comments. --- .../baeldung/inputstream/InputStreamTest.java | 24 +++++++++++++++++++ .../InputStreamReaderTest.java | 1 + 2 files changed, 25 insertions(+) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java index b238067654..553085d2fe 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java @@ -13,6 +13,7 @@ import java.util.List; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; + public class InputStreamTest { @Test public void givenAString_whenWrittenToFileInputStream_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { @@ -24,6 +25,28 @@ public class InputStreamTest { Assert.assertTrue(readString(inputStream).contains(lines.get(0))); } } + + @Test + public void givenAString_whenWrittenToFileInputStreamWithStringConstructor_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { + Path sampleOut = tempDir.resolve("sample-out.txt"); + String expectedText = "Hello. Hi."; + List lines = Arrays.asList(expectedText); + Files.write(sampleOut, lines); + String fileAbsolutePath = sampleOut.toFile() + .getAbsolutePath(); + try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) { + int content; + int availabeBytes = fis.available(); + Assert.assertTrue(availabeBytes > 0); + StringBuilder actualReadText = new StringBuilder(); + while ((content = fis.read()) != -1) { + actualReadText.append((char) content); + } + Assert.assertTrue(actualReadText.toString() + .contains(expectedText)); + } + } + @Test public void givenAString_whenWrittenToByteArrayInputStream_thenShouldMatchWhenRead() throws IOException { byte[] byteArray = { 104, 101, 108, 108, 111 }; @@ -32,6 +55,7 @@ public class InputStreamTest { Assert.assertEquals("hello", expected); } } + private static String readString(InputStream inputStream) throws IOException { int c; StringBuilder sb = new StringBuilder(); diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java index d14a96c9a0..e52bb99363 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java @@ -13,6 +13,7 @@ import java.util.List; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; + public class InputStreamReaderTest { @Test public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { From 17172ba21ae8b2bda3f1cf2cb0ca9cff3c0029d9 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Sun, 11 Feb 2024 19:48:18 +0100 Subject: [PATCH 04/51] BAEL-7131 version 4 - code review comments. --- .../baeldung/inputstream/InputStreamTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java index 553085d2fe..0a00affbd8 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java @@ -1,14 +1,21 @@ package com.baeldung.inputstream; +import static org.junit.jupiter.api.io.CleanupMode.ALWAYS; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.junit.Assert; import org.junit.jupiter.api.Test; @@ -64,4 +71,28 @@ public class InputStreamTest { } return sb.toString(); } + + @Test + public void givenKeyValuePairs_whenWrittenInATextFile_thenSuccessWhenParsedWithObjectInputStream( + @TempDir(cleanup = ALWAYS) Path tempDir) throws IOException, ClassNotFoundException { + Path sampleOut = tempDir.resolve("sample-out.txt"); + File fileText = sampleOut.toFile(); + //Serialize a Hashmap then write it into a file. + Map kv = new HashMap<>(); + try (FileOutputStream fileOutStream = new FileOutputStream(fileText)) { + try (ObjectOutputStream objectOutStream = new ObjectOutputStream(fileOutStream)) { + kv.put("baseURL", "baeldung.com"); + kv.put("apiKey", "this_is_a_test_key"); + objectOutStream.writeObject(kv); + } + } + //Deserialize the contents of a file then transform it back into a Hashmap + try (FileInputStream fileStream = new FileInputStream(fileText)) { + try (ObjectInputStream input = new ObjectInputStream(fileStream)) { + HashMap inputKv = (HashMap) input.readObject(); + Assert.assertEquals(kv.get("baseURL"), inputKv.get("baseURL")); + Assert.assertEquals(kv.get("apiKey"), inputKv.get("apiKey")); + } + } + } } From 8a0d5939f11ddab1fe39057dd27820bcd3d1707d Mon Sep 17 00:00:00 2001 From: adalagandev Date: Mon, 12 Feb 2024 10:12:12 +0100 Subject: [PATCH 05/51] BAEL-7131 version 5 - renamed class name to end with UnitTest --- .../{InputStreamTest.java => InputStreamUnitTest.java} | 2 +- ...nputStreamReaderTest.java => InputStreamReaderUnitTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/{InputStreamTest.java => InputStreamUnitTest.java} (99%) rename core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/{InputStreamReaderTest.java => InputStreamReaderUnitTest.java} (97%) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java similarity index 99% rename from core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java rename to core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index 0a00affbd8..a1b0ef251c 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class InputStreamTest { +public class InputStreamUnitTest { @Test public void givenAString_whenWrittenToFileInputStream_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { Path sampleOut = tempDir.resolve("sample-out.txt"); diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java similarity index 97% rename from core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java rename to core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java index e52bb99363..ea4572fa5f 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java @@ -14,7 +14,7 @@ import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class InputStreamReaderTest { +public class InputStreamReaderUnitTest { @Test public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { boolean isMatched = false; From e6d37b867c74d037a685735993f955571a6883ac Mon Sep 17 00:00:00 2001 From: adalagandev Date: Tue, 20 Feb 2024 00:11:06 +0100 Subject: [PATCH 06/51] BAEL-7131 version 6 - updated for PR comments, renamed unit test method, added assertJ dependency and used that in unit tests instead. --- core-java-modules/core-java-io-apis-2/pom.xml | 9 ++- .../inputstream/InputStreamUnitTest.java | 65 +++++++++---------- .../InputStreamReaderUnitTest.java | 10 +-- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/pom.xml b/core-java-modules/core-java-io-apis-2/pom.xml index 579fa4a589..976cbd62e4 100644 --- a/core-java-modules/core-java-io-apis-2/pom.xml +++ b/core-java-modules/core-java-io-apis-2/pom.xml @@ -81,6 +81,12 @@ 7.1.0 test + + org.assertj + assertj-core + 3.4.1 + test + core-java-io-apis-2 @@ -94,4 +100,5 @@ 5.9.3 - \ No newline at end of file + + diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index a1b0ef251c..e253690762 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -1,6 +1,6 @@ package com.baeldung.inputstream; -import static org.junit.jupiter.api.io.CleanupMode.ALWAYS; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.io.File; @@ -20,21 +20,20 @@ import java.util.Map; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - public class InputStreamUnitTest { - @Test - public void givenAString_whenWrittenToFileInputStream_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { + @Test //givenAStringWrittenToAFile_whenReadByX_thenY + public void givenAStringWrittenToFile_whenReadWithFileInputStream_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { Path sampleOut = tempDir.resolve("sample-out.txt"); List lines = Arrays.asList("Hello. This is just a test. Good bye."); Files.write(sampleOut, lines); File sampleOutFile = sampleOut.toFile(); try (InputStream inputStream = new FileInputStream(sampleOutFile)) { - Assert.assertTrue(readString(inputStream).contains(lines.get(0))); + assertThat(readString(inputStream)).contains(lines.get(0)); } } @Test - public void givenAString_whenWrittenToFileInputStreamWithStringConstructor_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { + public void givenAStringWrittenToFile_whenReadWithFileInputStreamWithStringConstructor_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { Path sampleOut = tempDir.resolve("sample-out.txt"); String expectedText = "Hello. Hi."; List lines = Arrays.asList(expectedText); @@ -43,23 +42,40 @@ public class InputStreamUnitTest { .getAbsolutePath(); try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) { int content; - int availabeBytes = fis.available(); - Assert.assertTrue(availabeBytes > 0); + int availableBytes = fis.available(); + Assert.assertTrue(availableBytes > 0); StringBuilder actualReadText = new StringBuilder(); while ((content = fis.read()) != -1) { actualReadText.append((char) content); } - Assert.assertTrue(actualReadText.toString() - .contains(expectedText)); + assertThat(actualReadText.toString()).contains(expectedText); } } @Test - public void givenAString_whenWrittenToByteArrayInputStream_thenShouldMatchWhenRead() throws IOException { + public void givenAByteArray_whenReadWithByteArrayInputStream_thenTheStringValueOfTheByteArrayShouldMatchTheExpectedString() throws IOException { byte[] byteArray = { 104, 101, 108, 108, 111 }; try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) { - String expected = readString(bais); - Assert.assertEquals("hello", expected); + assertThat(readString(bais)).isEqualTo("hello"); + } + } + @Test + public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams( + @TempDir Path tempDir) throws IOException, ClassNotFoundException { + Path sampleOut = tempDir.resolve("sample-out.txt"); + File fileText = sampleOut.toFile(); + //Serialize a Hashmap then write it into a file. + Map kv = new HashMap<>(); + try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(fileText))) { + kv.put("baseURL", "baeldung.com"); + kv.put("apiKey", "this_is_a_test_key"); + objectOutStream.writeObject(kv); + } + //Deserialize the contents of a file then transform it back into a Hashmap + try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(fileText))) { + HashMap inputKv = (HashMap) input.readObject(); + assertThat(kv.get("baseURL")).isEqualTo( inputKv.get("baseURL")); + assertThat(kv.get("apiKey")).isEqualTo( inputKv.get("apiKey")); } } @@ -72,27 +88,4 @@ public class InputStreamUnitTest { return sb.toString(); } - @Test - public void givenKeyValuePairs_whenWrittenInATextFile_thenSuccessWhenParsedWithObjectInputStream( - @TempDir(cleanup = ALWAYS) Path tempDir) throws IOException, ClassNotFoundException { - Path sampleOut = tempDir.resolve("sample-out.txt"); - File fileText = sampleOut.toFile(); - //Serialize a Hashmap then write it into a file. - Map kv = new HashMap<>(); - try (FileOutputStream fileOutStream = new FileOutputStream(fileText)) { - try (ObjectOutputStream objectOutStream = new ObjectOutputStream(fileOutStream)) { - kv.put("baseURL", "baeldung.com"); - kv.put("apiKey", "this_is_a_test_key"); - objectOutStream.writeObject(kv); - } - } - //Deserialize the contents of a file then transform it back into a Hashmap - try (FileInputStream fileStream = new FileInputStream(fileText)) { - try (ObjectInputStream input = new ObjectInputStream(fileStream)) { - HashMap inputKv = (HashMap) input.readObject(); - Assert.assertEquals(kv.get("baseURL"), inputKv.get("baseURL")); - Assert.assertEquals(kv.get("apiKey"), inputKv.get("apiKey")); - } - } - } } diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java index ea4572fa5f..2dfcc4f9e7 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java @@ -1,5 +1,7 @@ package com.baeldung.inputstreamreader; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; @@ -10,10 +12,8 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; -import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - public class InputStreamReaderUnitTest { @Test public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { @@ -21,9 +21,9 @@ public class InputStreamReaderUnitTest { String sampleTxt = "Good day. This is just a test. Good bye."; Path sampleOut = tempDir.resolve("sample-out.txt"); List lines = Arrays.asList(sampleTxt); - //create and write file Files.write(sampleOut, lines); - try (FileInputStream fis = new FileInputStream(String.valueOf(sampleOut.toAbsolutePath())); BufferedReader br = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8))) { + String absolutePath = String.valueOf(sampleOut.toAbsolutePath()); + try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8))) { String ln; while ((ln = br.readLine()) != null) { if (ln.contains(sampleTxt)) { @@ -31,7 +31,7 @@ public class InputStreamReaderUnitTest { break; } } - Assert.assertTrue(isMatched); + assertThat(isMatched).isTrue(); } } } From ed1e58c45e3e0b948be7fbe9f3e3503a1e78f687 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Tue, 20 Feb 2024 15:08:05 +0100 Subject: [PATCH 07/51] BAEL-7131 version 7 --- .../com/baeldung/inputstream/InputStreamUnitTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index e253690762..6488e91c3e 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; public class InputStreamUnitTest { - @Test //givenAStringWrittenToAFile_whenReadByX_thenY + @Test public void givenAStringWrittenToFile_whenReadWithFileInputStream_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { Path sampleOut = tempDir.resolve("sample-out.txt"); List lines = Arrays.asList("Hello. This is just a test. Good bye."); @@ -60,19 +60,18 @@ public class InputStreamUnitTest { } } @Test - public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams( - @TempDir Path tempDir) throws IOException, ClassNotFoundException { + public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams(@TempDir Path tempDir) throws IOException, ClassNotFoundException { Path sampleOut = tempDir.resolve("sample-out.txt"); - File fileText = sampleOut.toFile(); + File textFile = sampleOut.toFile(); //Serialize a Hashmap then write it into a file. Map kv = new HashMap<>(); - try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(fileText))) { + try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(textFile))) { kv.put("baseURL", "baeldung.com"); kv.put("apiKey", "this_is_a_test_key"); objectOutStream.writeObject(kv); } //Deserialize the contents of a file then transform it back into a Hashmap - try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(fileText))) { + try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(textFile))) { HashMap inputKv = (HashMap) input.readObject(); assertThat(kv.get("baseURL")).isEqualTo( inputKv.get("baseURL")); assertThat(kv.get("apiKey")).isEqualTo( inputKv.get("apiKey")); From 9178b53dc94f5297cd3bb8c2fd16919c41116ae3 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Wed, 21 Feb 2024 11:10:39 +0100 Subject: [PATCH 08/51] BAEL-7131 - reapplied Baeldung Formatter, code changes from PR. --- .../inputstream/InputStreamUnitTest.java | 24 ++++++++----------- .../InputStreamReaderUnitTest.java | 3 ++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index 6488e91c3e..7fa5d760a5 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -17,9 +17,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; + public class InputStreamUnitTest { @Test public void givenAStringWrittenToFile_whenReadWithFileInputStream_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { @@ -41,14 +41,9 @@ public class InputStreamUnitTest { String fileAbsolutePath = sampleOut.toFile() .getAbsolutePath(); try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) { - int content; int availableBytes = fis.available(); - Assert.assertTrue(availableBytes > 0); - StringBuilder actualReadText = new StringBuilder(); - while ((content = fis.read()) != -1) { - actualReadText.append((char) content); - } - assertThat(actualReadText.toString()).contains(expectedText); + assertThat(availableBytes > 0); + assertThat(readString(fis)).contains(expectedText); } } @@ -59,6 +54,7 @@ public class InputStreamUnitTest { assertThat(readString(bais)).isEqualTo("hello"); } } + @Test public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams(@TempDir Path tempDir) throws IOException, ClassNotFoundException { Path sampleOut = tempDir.resolve("sample-out.txt"); @@ -66,15 +62,15 @@ public class InputStreamUnitTest { //Serialize a Hashmap then write it into a file. Map kv = new HashMap<>(); try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(textFile))) { - kv.put("baseURL", "baeldung.com"); - kv.put("apiKey", "this_is_a_test_key"); - objectOutStream.writeObject(kv); + kv.put("baseURL", "baeldung.com"); + kv.put("apiKey", "this_is_a_test_key"); + objectOutStream.writeObject(kv); } //Deserialize the contents of a file then transform it back into a Hashmap try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(textFile))) { - HashMap inputKv = (HashMap) input.readObject(); - assertThat(kv.get("baseURL")).isEqualTo( inputKv.get("baseURL")); - assertThat(kv.get("apiKey")).isEqualTo( inputKv.get("apiKey")); + HashMap inputKv = (HashMap) input.readObject(); + assertThat(kv.get("baseURL")).isEqualTo(inputKv.get("baseURL")); + assertThat(kv.get("apiKey")).isEqualTo(inputKv.get("apiKey")); } } diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java index 2dfcc4f9e7..358ed5dea0 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java @@ -14,10 +14,10 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; + public class InputStreamReaderUnitTest { @Test public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException { - boolean isMatched = false; String sampleTxt = "Good day. This is just a test. Good bye."; Path sampleOut = tempDir.resolve("sample-out.txt"); List lines = Arrays.asList(sampleTxt); @@ -25,6 +25,7 @@ public class InputStreamReaderUnitTest { String absolutePath = String.valueOf(sampleOut.toAbsolutePath()); try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8))) { String ln; + boolean isMatched = false; while ((ln = br.readLine()) != null) { if (ln.contains(sampleTxt)) { isMatched = true; From c84563ff4dc805574d8592a0963ca4a68a8c49d9 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Thu, 22 Feb 2024 11:33:25 +0100 Subject: [PATCH 09/51] BAEL-7131 - fixed incomplete Assertion --- .../test/java/com/baeldung/inputstream/InputStreamUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index 7fa5d760a5..6ad3c03d8b 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -42,7 +42,7 @@ public class InputStreamUnitTest { .getAbsolutePath(); try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) { int availableBytes = fis.available(); - assertThat(availableBytes > 0); + assertThat(availableBytes).isGreaterThan(0); assertThat(readString(fis)).contains(expectedText); } } From 069952c65c366476d35f2feeea304e75a0edaab6 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Wed, 6 Mar 2024 01:22:17 +0100 Subject: [PATCH 10/51] BAEL-7131 - updated based on review comments from Final Review. --- .../inputstream/InputStreamUnitTest.java | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index 6ad3c03d8b..e45e406f75 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -5,17 +5,12 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -32,21 +27,6 @@ public class InputStreamUnitTest { } } - @Test - public void givenAStringWrittenToFile_whenReadWithFileInputStreamWithStringConstructor_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { - Path sampleOut = tempDir.resolve("sample-out.txt"); - String expectedText = "Hello. Hi."; - List lines = Arrays.asList(expectedText); - Files.write(sampleOut, lines); - String fileAbsolutePath = sampleOut.toFile() - .getAbsolutePath(); - try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) { - int availableBytes = fis.available(); - assertThat(availableBytes).isGreaterThan(0); - assertThat(readString(fis)).contains(expectedText); - } - } - @Test public void givenAByteArray_whenReadWithByteArrayInputStream_thenTheStringValueOfTheByteArrayShouldMatchTheExpectedString() throws IOException { byte[] byteArray = { 104, 101, 108, 108, 111 }; @@ -55,25 +35,6 @@ public class InputStreamUnitTest { } } - @Test - public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams(@TempDir Path tempDir) throws IOException, ClassNotFoundException { - Path sampleOut = tempDir.resolve("sample-out.txt"); - File textFile = sampleOut.toFile(); - //Serialize a Hashmap then write it into a file. - Map kv = new HashMap<>(); - try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(textFile))) { - kv.put("baseURL", "baeldung.com"); - kv.put("apiKey", "this_is_a_test_key"); - objectOutStream.writeObject(kv); - } - //Deserialize the contents of a file then transform it back into a Hashmap - try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(textFile))) { - HashMap inputKv = (HashMap) input.readObject(); - assertThat(kv.get("baseURL")).isEqualTo(inputKv.get("baseURL")); - assertThat(kv.get("apiKey")).isEqualTo(inputKv.get("apiKey")); - } - } - private static String readString(InputStream inputStream) throws IOException { int c; StringBuilder sb = new StringBuilder(); From 03b2f8bb58e4aabe7063f1b89cfcc3ecb0dbd45d Mon Sep 17 00:00:00 2001 From: adalagandev Date: Thu, 7 Mar 2024 23:53:35 +0100 Subject: [PATCH 11/51] BAEL-7131 - Updated pom.xml under core-java-io-apis-2 --- core-java-modules/core-java-io-apis-2/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/pom.xml b/core-java-modules/core-java-io-apis-2/pom.xml index 976cbd62e4..03ec8fc6cb 100644 --- a/core-java-modules/core-java-io-apis-2/pom.xml +++ b/core-java-modules/core-java-io-apis-2/pom.xml @@ -81,12 +81,6 @@ 7.1.0 test - - org.assertj - assertj-core - 3.4.1 - test - core-java-io-apis-2 From c3b389f4dcec431fa374a1ef366af925121da2fd Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Sat, 9 Mar 2024 00:09:04 +0100 Subject: [PATCH 12/51] [happy-number] happy number --- .../happynumber/HappyNumberUnitTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java diff --git a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java b/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java new file mode 100644 index 0000000000..5cdf1a82c5 --- /dev/null +++ b/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java @@ -0,0 +1,82 @@ +package com.baeldung.algorithms.happynumber; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +class HappyNumberDecider { + + public static boolean isHappyNumber(int n) { + Set checkedNumbers = new HashSet<>(); + while (true) { + n = sumDigitsSquare(n); + if (n == 1) { + return true; + } + if (checkedNumbers.contains(n)) { + return false; + } + checkedNumbers.add(n); + } + } + + public static boolean isHappyNumber2(int n) { + int slow = n; + int fast = n; + do { + slow = sumDigitsSquare(slow); + fast = sumDigitsSquare(sumDigitsSquare(fast)); + } while (slow != fast); + + return slow == 1; + } + + private static int sumDigitsSquare(int n) { + int squareSum = 0; + while (n != 0) { + squareSum += (n % 10) * (n % 10); + n /= 10; + } + return squareSum; + } +} + +public class HappyNumberUnitTest { + + @Test + void whenUsingIsHappyNumber_thenGetTheExpectedResult() { + assertTrue(HappyNumberDecider.isHappyNumber(7)); + assertTrue(HappyNumberDecider.isHappyNumber(10)); + assertTrue(HappyNumberDecider.isHappyNumber(13)); + assertTrue(HappyNumberDecider.isHappyNumber(19)); + assertTrue(HappyNumberDecider.isHappyNumber(23)); + + assertFalse(HappyNumberDecider.isHappyNumber(4)); + assertFalse(HappyNumberDecider.isHappyNumber(6)); + assertFalse(HappyNumberDecider.isHappyNumber(11)); + assertFalse(HappyNumberDecider.isHappyNumber(15)); + assertFalse(HappyNumberDecider.isHappyNumber(20)); + + } + + @Test + void whenUsingIsHappyNumber2_thenGetTheExpectedResult() { + assertTrue(HappyNumberDecider.isHappyNumber2(7)); + assertTrue(HappyNumberDecider.isHappyNumber2(10)); + assertTrue(HappyNumberDecider.isHappyNumber2(13)); + assertTrue(HappyNumberDecider.isHappyNumber2(19)); + assertTrue(HappyNumberDecider.isHappyNumber2(23)); + + assertFalse(HappyNumberDecider.isHappyNumber2(4)); + assertFalse(HappyNumberDecider.isHappyNumber2(6)); + assertFalse(HappyNumberDecider.isHappyNumber2(11)); + assertFalse(HappyNumberDecider.isHappyNumber2(15)); + assertFalse(HappyNumberDecider.isHappyNumber2(20)); + + } + +} \ No newline at end of file From 11ee2130ccb2d084fd4385b89b47eec167d57926 Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Sun, 10 Mar 2024 18:05:49 +0100 Subject: [PATCH 13/51] [happy-number] renaming method --- .../happynumber/HappyNumberUnitTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java b/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java index 5cdf1a82c5..2056688659 100644 --- a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java +++ b/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/happynumber/HappyNumberUnitTest.java @@ -24,7 +24,7 @@ class HappyNumberDecider { } } - public static boolean isHappyNumber2(int n) { + public static boolean isHappyNumberFloyd(int n) { int slow = n; int fast = n; do { @@ -65,17 +65,17 @@ public class HappyNumberUnitTest { @Test void whenUsingIsHappyNumber2_thenGetTheExpectedResult() { - assertTrue(HappyNumberDecider.isHappyNumber2(7)); - assertTrue(HappyNumberDecider.isHappyNumber2(10)); - assertTrue(HappyNumberDecider.isHappyNumber2(13)); - assertTrue(HappyNumberDecider.isHappyNumber2(19)); - assertTrue(HappyNumberDecider.isHappyNumber2(23)); + assertTrue(HappyNumberDecider.isHappyNumberFloyd(7)); + assertTrue(HappyNumberDecider.isHappyNumberFloyd(10)); + assertTrue(HappyNumberDecider.isHappyNumberFloyd(13)); + assertTrue(HappyNumberDecider.isHappyNumberFloyd(19)); + assertTrue(HappyNumberDecider.isHappyNumberFloyd(23)); - assertFalse(HappyNumberDecider.isHappyNumber2(4)); - assertFalse(HappyNumberDecider.isHappyNumber2(6)); - assertFalse(HappyNumberDecider.isHappyNumber2(11)); - assertFalse(HappyNumberDecider.isHappyNumber2(15)); - assertFalse(HappyNumberDecider.isHappyNumber2(20)); + assertFalse(HappyNumberDecider.isHappyNumberFloyd(4)); + assertFalse(HappyNumberDecider.isHappyNumberFloyd(6)); + assertFalse(HappyNumberDecider.isHappyNumberFloyd(11)); + assertFalse(HappyNumberDecider.isHappyNumberFloyd(15)); + assertFalse(HappyNumberDecider.isHappyNumberFloyd(20)); } From 63741db3d9a38bcf741e383e2c6bd72a0bd42254 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Sun, 10 Mar 2024 22:34:19 +0100 Subject: [PATCH 14/51] BAEL-7131 - Updated for final review comments --- .../inputstreamreader/InputStreamReaderUnitTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java index 358ed5dea0..d67b56e10b 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstreamreader/InputStreamReaderUnitTest.java @@ -2,7 +2,6 @@ package com.baeldung.inputstreamreader; import static org.assertj.core.api.Assertions.assertThat; -import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -23,11 +22,13 @@ public class InputStreamReaderUnitTest { List lines = Arrays.asList(sampleTxt); Files.write(sampleOut, lines); String absolutePath = String.valueOf(sampleOut.toAbsolutePath()); - try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8))) { - String ln; + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8)) { boolean isMatched = false; - while ((ln = br.readLine()) != null) { - if (ln.contains(sampleTxt)) { + int b; + StringBuilder sb = new StringBuilder(); + while ((b = reader.read()) != -1) { + sb.append((char) b); + if (sb.toString().contains(sampleTxt)) { isMatched = true; break; } From 83cc0185150672e73ffaf3410f1e6e26fe264006 Mon Sep 17 00:00:00 2001 From: adalagandev Date: Fri, 15 Mar 2024 18:08:35 +0100 Subject: [PATCH 15/51] BAEL-7131 - Removed InputStreamUnitTest as per Final review sugestions. --- .../inputstream/InputStreamUnitTest.java | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java deleted file mode 100644 index e45e406f75..0000000000 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.inputstream; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - -public class InputStreamUnitTest { - @Test - public void givenAStringWrittenToFile_whenReadWithFileInputStream_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { - Path sampleOut = tempDir.resolve("sample-out.txt"); - List lines = Arrays.asList("Hello. This is just a test. Good bye."); - Files.write(sampleOut, lines); - File sampleOutFile = sampleOut.toFile(); - try (InputStream inputStream = new FileInputStream(sampleOutFile)) { - assertThat(readString(inputStream)).contains(lines.get(0)); - } - } - - @Test - public void givenAByteArray_whenReadWithByteArrayInputStream_thenTheStringValueOfTheByteArrayShouldMatchTheExpectedString() throws IOException { - byte[] byteArray = { 104, 101, 108, 108, 111 }; - try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) { - assertThat(readString(bais)).isEqualTo("hello"); - } - } - - private static String readString(InputStream inputStream) throws IOException { - int c; - StringBuilder sb = new StringBuilder(); - while ((c = inputStream.read()) != -1) { - sb.append((char) c); - } - return sb.toString(); - } - -} From e959114bc709ed59f445a0c569ca277168bec91b Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Sun, 17 Mar 2024 17:27:57 +0100 Subject: [PATCH 16/51] [add-to-immutable-list] wip --- .../AddElementsToImmutableListUnitTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java diff --git a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java new file mode 100644 index 0000000000..f7ad690acb --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java @@ -0,0 +1,47 @@ +package com.baeldung.addtoimmutablelist; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +public class AddElementsToImmutableListUnitTest { + + public static List appendAnElement(List immutableList, T element) { + List tmpList = new ArrayList<>(immutableList); + tmpList.add(element); + return List.copyOf(tmpList); + } + + public static List appendElements(List immutableList, T... elements) { + List tmpList = new ArrayList<>(immutableList); + tmpList.addAll(Arrays.asList(elements)); + return List.copyOf(tmpList); + } + + @Test + void whenCallingAppendAnElement_thenGetExpectedResult() { + List myList = List.of("A", "B", "C", "D", "E"); + List expected = List.of("A", "B", "C", "D", "E", "F"); + List result = appendAnElement(myList, "F"); + assertThat(result).isEqualTo(expected) + .isUnmodifiable(); + } + + @Test + void whenCallingAppendElements_thenGetExpectedResult() { + List myList = List.of("A", "B", "C", "D", "E"); + List expected1 = List.of("A", "B", "C", "D", "E", "F"); + List result1 = appendElements(myList, "F"); + assertThat(result1).isEqualTo(expected1) + .isUnmodifiable(); + + List expected2 = List.of("A", "B", "C", "D", "E", "F", "G", "H", "I"); + List result2 = appendElements(myList, "F", "G", "H", "I"); + assertThat(result2).isEqualTo(expected2) + .isUnmodifiable(); + } +} \ No newline at end of file From 614d91076694c4454f97d845757ab325faab53df Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Mon, 18 Mar 2024 20:02:15 +0100 Subject: [PATCH 17/51] [map-stream-to-map] merge a stream of maps to a single map --- .../MapStreamToMapUnitTest.java | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java diff --git a/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java b/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java new file mode 100644 index 0000000000..cbefd58396 --- /dev/null +++ b/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java @@ -0,0 +1,153 @@ +package com.baeldung.streams.mapstreamtomap; + +import static java.lang.Math.max; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; + +import com.google.common.collect.Lists; + +public class MapStreamToMapUnitTest { + + Map playerMap1 = new HashMap() {{ + put("Kai", 92); + put("Liam", 100); + }}; + Map playerMap2 = new HashMap() {{ + put("Eric", 42); + put("Kevin", 77); + }}; + Map playerMap3 = new HashMap() {{ + put("Saajan", 35); + }}; + Map playerMap4 = new HashMap() {{ + put("Kai", 76); + }}; + Map playerMap5 = new HashMap() {{ + put("Kai", null); + put("Jerry", null); + }}; + + static Stream> getMapStream(Map... playerMaps) { + List> theList = Lists.newArrayList(playerMaps); + Collections.shuffle(theList); + return theList.stream(); + } + + @Test + void givenMapsStream_whenUsingFlatMapAndToMap_thenMultipleMapsMergedIntoOneMap() { + + Map expectedMap = new HashMap() {{ + put("Saajan", 35); + put("Liam", 100); + put("Kai", 92); + put("Eric", 42); + put("Kevin", 77); + }}; + + Map mergedMap = getMapStream(playerMap1, playerMap2, playerMap3).flatMap(map -> map.entrySet() + .stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + assertEquals(expectedMap, mergedMap); + } + + @Test + void givenMapsWithDuplicateKeys_whenUsingFlatMapAndToMap_thenMultipleMapsMergedIntoOneMap() { + + Map expectedMap = new HashMap() {{ + put("Saajan", 35); + put("Liam", 100); + put("Kai", 92); // max of 76 and 92 + put("Eric", 42); + put("Kevin", 77); + }}; + + assertThrows(IllegalStateException.class, () -> getMapStream(playerMap1, playerMap2, playerMap3, playerMap4).flatMap(map -> map.entrySet() + .stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), "Duplicate key Kai (attempted merging values 92 and 76)"); + + Map mergedMap = getMapStream(playerMap1, playerMap2, playerMap3, playerMap4).flatMap(map -> map.entrySet() + .stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::max)); + + assertEquals(expectedMap, mergedMap); + } + + private Integer maxInteger(Integer int1, Integer int2) { + if (int1 == null) { + return int2; + } + if (int2 == null) { + return int1; + } + return max(int1, int2); + } + + @Test + void givenMapsWithDuplicateKeysAndNullValues_whenUsingFlatMapWithForEach_thenMultipleMapsMergedIntoOneMap() { + + Map expectedMap = new HashMap() {{ + put("Saajan", 35); + put("Liam", 100); + put("Kai", 92); // max of 92, 76, and null + put("Eric", 42); + put("Kevin", 77); + put("Jerry", null); + }}; + + assertThrows(NullPointerException.class, () -> getMapStream(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5).flatMap(map -> map.entrySet() + .stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::max))); + + Map mergedMap = new HashMap<>(); + getMapStream(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5).flatMap(map -> map.entrySet() + .stream()) + .forEach(entry -> { + String k = entry.getKey(); + Integer v = entry.getValue(); + if (mergedMap.containsKey(k)) { + mergedMap.put(k, maxInteger(mergedMap.get(k), v)); + } else { + mergedMap.put(k, v); + } + }); + assertEquals(expectedMap, mergedMap); + + } + + @Test + void givenMapsWithDuplicateKeysAndNullValues_whenUsingReduce_thenMultipleMapsMergedIntoOneMap() { + + Map expectedMap = new HashMap() {{ + put("Saajan", 35); + put("Liam", 100); + put("Kai", 92); // max of 92, 76, and null + put("Eric", 42); + put("Kevin", 77); + put("Jerry", null); + }}; + Stream> mapStream = getMapStream(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5); + Map mergedMap = mapStream.reduce(new HashMap<>(), (resultMap, theMap) -> { + theMap.forEach((k, v) -> { + if (resultMap.containsKey(k)) { + resultMap.put(k, maxInteger(resultMap.get(k), v)); + } else { + resultMap.put(k, v); + } + }); + return resultMap; + }); + + assertEquals(expectedMap, mergedMap); + + } +} \ No newline at end of file From 9456b4b953c7e95c22b85ae66a934d123d8eecfc Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Tue, 19 Mar 2024 09:32:58 +0100 Subject: [PATCH 18/51] [map-stream-to-map] updates.. 1 --- .../MapStreamToMapUnitTest.java | 46 ++++++++----------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java b/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java index cbefd58396..b23dd07fc8 100644 --- a/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java +++ b/core-java-modules/core-java-streams-maps/src/test/java/com/baeldung/streams/mapstreamtomap/MapStreamToMapUnitTest.java @@ -1,20 +1,20 @@ package com.baeldung.streams.mapstreamtomap; import static java.lang.Math.max; +import static java.util.stream.Collectors.flatMapping; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.reducing; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.jupiter.api.Test; -import com.google.common.collect.Lists; - public class MapStreamToMapUnitTest { Map playerMap1 = new HashMap() {{ @@ -36,12 +36,6 @@ public class MapStreamToMapUnitTest { put("Jerry", null); }}; - static Stream> getMapStream(Map... playerMaps) { - List> theList = Lists.newArrayList(playerMaps); - Collections.shuffle(theList); - return theList.stream(); - } - @Test void givenMapsStream_whenUsingFlatMapAndToMap_thenMultipleMapsMergedIntoOneMap() { @@ -53,7 +47,8 @@ public class MapStreamToMapUnitTest { put("Kevin", 77); }}; - Map mergedMap = getMapStream(playerMap1, playerMap2, playerMap3).flatMap(map -> map.entrySet() + Map mergedMap = Stream.of(playerMap1, playerMap2, playerMap3) + .flatMap(map -> map.entrySet() .stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); @@ -71,11 +66,13 @@ public class MapStreamToMapUnitTest { put("Kevin", 77); }}; - assertThrows(IllegalStateException.class, () -> getMapStream(playerMap1, playerMap2, playerMap3, playerMap4).flatMap(map -> map.entrySet() + assertThrows(IllegalStateException.class, () -> Stream.of(playerMap1, playerMap2, playerMap3, playerMap4) + .flatMap(map -> map.entrySet() .stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), "Duplicate key Kai (attempted merging values 92 and 76)"); - Map mergedMap = getMapStream(playerMap1, playerMap2, playerMap3, playerMap4).flatMap(map -> map.entrySet() + Map mergedMap = Stream.of(playerMap1, playerMap2, playerMap3, playerMap4) + .flatMap(map -> map.entrySet() .stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::max)); @@ -104,12 +101,14 @@ public class MapStreamToMapUnitTest { put("Jerry", null); }}; - assertThrows(NullPointerException.class, () -> getMapStream(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5).flatMap(map -> map.entrySet() + assertThrows(NullPointerException.class, () -> Stream.of(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5) + .flatMap(map -> map.entrySet() .stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::max))); Map mergedMap = new HashMap<>(); - getMapStream(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5).flatMap(map -> map.entrySet() + Stream.of(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5) + .flatMap(map -> map.entrySet() .stream()) .forEach(entry -> { String k = entry.getKey(); @@ -135,19 +134,10 @@ public class MapStreamToMapUnitTest { put("Kevin", 77); put("Jerry", null); }}; - Stream> mapStream = getMapStream(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5); - Map mergedMap = mapStream.reduce(new HashMap<>(), (resultMap, theMap) -> { - theMap.forEach((k, v) -> { - if (resultMap.containsKey(k)) { - resultMap.put(k, maxInteger(resultMap.get(k), v)); - } else { - resultMap.put(k, v); - } - }); - return resultMap; - }); - + Map mergedMap = Stream.of(playerMap1, playerMap2, playerMap3, playerMap4, playerMap5) + .flatMap(x -> x.entrySet() + .stream()) + .collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, reducing(null, this::maxInteger)))); assertEquals(expectedMap, mergedMap); - } } \ No newline at end of file From 356624bf222f79648cc4e0a74fca727150c6dc56 Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Tue, 19 Mar 2024 23:54:56 +0100 Subject: [PATCH 19/51] [add-to-immutable-list] add elements to immutable list --- .../addtoimmutablelist/AddElementsToImmutableListUnitTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java index f7ad690acb..13484b6dcb 100644 --- a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java +++ b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java @@ -16,6 +16,7 @@ public class AddElementsToImmutableListUnitTest { return List.copyOf(tmpList); } + @SafeVarargs public static List appendElements(List immutableList, T... elements) { List tmpList = new ArrayList<>(immutableList); tmpList.addAll(Arrays.asList(elements)); From 0242528345012c6300cc4463fe873c033febf077 Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Wed, 20 Mar 2024 17:20:04 +0100 Subject: [PATCH 20/51] [add-to-immutable-list] replace list.copyof with collections.unmodifiableList --- .../AddElementsToImmutableListUnitTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java index 13484b6dcb..397aca8906 100644 --- a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java +++ b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/addtoimmutablelist/AddElementsToImmutableListUnitTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; @@ -13,14 +14,14 @@ public class AddElementsToImmutableListUnitTest { public static List appendAnElement(List immutableList, T element) { List tmpList = new ArrayList<>(immutableList); tmpList.add(element); - return List.copyOf(tmpList); + return Collections.unmodifiableList(tmpList); } @SafeVarargs public static List appendElements(List immutableList, T... elements) { List tmpList = new ArrayList<>(immutableList); tmpList.addAll(Arrays.asList(elements)); - return List.copyOf(tmpList); + return Collections.unmodifiableList(tmpList); } @Test From ff12386947722dc15575b05c604ab8e75dcba422 Mon Sep 17 00:00:00 2001 From: vunamtien Date: Sun, 24 Mar 2024 23:19:00 +0700 Subject: [PATCH 21/51] [JAVA-32056] Upgrade spring-mvc-java-3 to Boot 3 (#16161) --- spring-web-modules/spring-mvc-java-3/pom.xml | 14 ++++++++++---- .../filters/CacheRequestContentFilter.java | 6 +++--- .../com/baeldung/filters/HttpRequestUnitTest.java | 10 +++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/spring-web-modules/spring-mvc-java-3/pom.xml b/spring-web-modules/spring-mvc-java-3/pom.xml index 4d669c7e7b..5999f6b118 100644 --- a/spring-web-modules/spring-mvc-java-3/pom.xml +++ b/spring-web-modules/spring-mvc-java-3/pom.xml @@ -11,15 +11,16 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api + ${jakarta.version} org.springframework @@ -37,4 +38,9 @@ + + 6.1.0-M2 + com.baeldung.Main + + \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-java-3/src/main/java/com/baeldung/filters/CacheRequestContentFilter.java b/spring-web-modules/spring-mvc-java-3/src/main/java/com/baeldung/filters/CacheRequestContentFilter.java index 907ec24700..b6f313c829 100644 --- a/spring-web-modules/spring-mvc-java-3/src/main/java/com/baeldung/filters/CacheRequestContentFilter.java +++ b/spring-web-modules/spring-mvc-java-3/src/main/java/com/baeldung/filters/CacheRequestContentFilter.java @@ -2,9 +2,9 @@ package com.baeldung.filters; import org.springframework.web.util.ContentCachingRequestWrapper; -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.*; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.http.HttpServletRequest; import java.io.IOException; @WebFilter(urlPatterns = "/*") diff --git a/spring-web-modules/spring-mvc-java-3/src/test/java/com/baeldung/filters/HttpRequestUnitTest.java b/spring-web-modules/spring-mvc-java-3/src/test/java/com/baeldung/filters/HttpRequestUnitTest.java index cd369d9118..b4a2751ea6 100644 --- a/spring-web-modules/spring-mvc-java-3/src/test/java/com/baeldung/filters/HttpRequestUnitTest.java +++ b/spring-web-modules/spring-mvc-java-3/src/test/java/com/baeldung/filters/HttpRequestUnitTest.java @@ -1,16 +1,16 @@ package com.baeldung.filters; +import jakarta.servlet.Filter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.web.util.ContentCachingRequestWrapper; -import javax.servlet.Filter; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; import java.io.IOException; import static org.junit.jupiter.api.Assertions.*; From 17cb4108d4a62e15a609ef3ea7bbc980865165dc Mon Sep 17 00:00:00 2001 From: Mo Helmy <135069400+BenHelmyBen@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:08:17 +0200 Subject: [PATCH 22/51] This PR is related to BAEL-7427 (#16028) * This commit is related to BAEL-7427 This commit aims to add a Main class. * This commit is related to BAEL-7427 This commit aims to add a myFile.gz file to the resources folder. * This commit is related to BAEL-7427 This commit aims to add a test class "ReadingGZIPUsingGZIPInputStreamUnitTest". * This commit is related to BAEL-7427 This commit aims to add a myFile.gz file to the resources folder. * Update Main.java * Update ReadingGZIPUsingGZIPInputStreamUnitTest.java * Update Main.java * Update ReadingGZIPUsingGZIPInputStreamUnitTest.java * Update ReadingGZIPUsingGZIPInputStreamUnitTest.java * Update Main.java * Update Main.java * Update ReadingGZIPUsingGZIPInputStreamUnitTest.java * Update Main.java * Update ReadingGZIPUsingGZIPInputStreamUnitTest.java * Update Main.java * Update ReadingGZIPUsingGZIPInputStreamUnitTest.java * Update Main.java --- .../baeldung/usinggzipInputstream/Main.java | 73 ++++++++++++++++++ .../src/main/resources/myFile.gz | Bin 0 -> 43 bytes ...adingGZIPUsingGZIPInputStreamUnitTest.java | 50 ++++++++++++ .../src/test/resources/myFile.gz | Bin 0 -> 43 bytes 4 files changed, 123 insertions(+) create mode 100644 core-java-modules/core-java-io-5/src/main/java/com/baeldung/usinggzipInputstream/Main.java create mode 100644 core-java-modules/core-java-io-5/src/main/resources/myFile.gz create mode 100644 core-java-modules/core-java-io-5/src/test/java/com/baeldung/usinggzipInputstream/ReadingGZIPUsingGZIPInputStreamUnitTest.java create mode 100644 core-java-modules/core-java-io-5/src/test/resources/myFile.gz diff --git a/core-java-modules/core-java-io-5/src/main/java/com/baeldung/usinggzipInputstream/Main.java b/core-java-modules/core-java-io-5/src/main/java/com/baeldung/usinggzipInputstream/Main.java new file mode 100644 index 0000000000..7065352be7 --- /dev/null +++ b/core-java-modules/core-java-io-5/src/main/java/com/baeldung/usinggzipInputstream/Main.java @@ -0,0 +1,73 @@ +package com.baeldung.usinggzipInputstream; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.stream.Stream; +import java.util.zip.GZIPInputStream; + +import static java.util.stream.Collectors.toList; + +public class Main { + static String filePath = Objects.requireNonNull(Main.class.getClassLoader().getResource("myFile.gz")).getFile(); + + public static void main(String[] args) throws IOException { + // Test readGZipFile method + List fileContents = readGZipFile(filePath); + System.out.println("Contents of GZIP file:"); + fileContents.forEach(System.out::println); + + // Test findInZipFile method + String searchTerm = "Line 1 content"; + List foundLines = findInZipFile(filePath, searchTerm); + System.out.println("Lines containing '" + searchTerm + "' in GZIP file:"); + foundLines.forEach(System.out::println); + + + // Test useContentsOfZipFile method + System.out.println("Using contents of GZIP file with consumer:"); + useContentsOfZipFile(filePath, linesStream -> { + linesStream.filter(line -> line.length() > 10).forEach(System.out::println); + }); + } + + + public static List readGZipFile(String filePath) throws IOException { + List lines = new ArrayList<>(); + try (InputStream inputStream = new FileInputStream(filePath); + GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream); + InputStreamReader inputStreamReader = new InputStreamReader(gzipInputStream); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { + + String line; + while ((line = bufferedReader.readLine()) != null) { + lines.add(line); + } + } + + return lines; + } + + public static List findInZipFile(String filePath, String toFind) throws IOException { + try (InputStream inputStream = new FileInputStream(filePath); + GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream); + InputStreamReader inputStreamReader = new InputStreamReader(gzipInputStream); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { + + return bufferedReader.lines().filter(line -> line.contains(toFind)).collect(toList()); + } + } + + public static void useContentsOfZipFile(String filePath, Consumer> consumer) throws IOException { + try (InputStream inputStream = new FileInputStream(filePath); + GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream); + InputStreamReader inputStreamReader = new InputStreamReader(gzipInputStream); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { + + consumer.accept(bufferedReader.lines()); + } + } + +} diff --git a/core-java-modules/core-java-io-5/src/main/resources/myFile.gz b/core-java-modules/core-java-io-5/src/main/resources/myFile.gz new file mode 100644 index 0000000000000000000000000000000000000000..47c3ad1e1bf21509aad3565310817853ec643c24 GIT binary patch literal 43 vcmb2|=3oGW|DR8u@eVZz@i=#0+w-jU!%vKby#YIq8R#(_ynNJC2dD-BT*DB2 literal 0 HcmV?d00001 diff --git a/core-java-modules/core-java-io-5/src/test/java/com/baeldung/usinggzipInputstream/ReadingGZIPUsingGZIPInputStreamUnitTest.java b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/usinggzipInputstream/ReadingGZIPUsingGZIPInputStreamUnitTest.java new file mode 100644 index 0000000000..51814f4581 --- /dev/null +++ b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/usinggzipInputstream/ReadingGZIPUsingGZIPInputStreamUnitTest.java @@ -0,0 +1,50 @@ +package com.baeldung.usinggzipInputstream; + +import org.junit.jupiter.api.Test; + +import java.io.*; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; + +public class ReadingGZIPUsingGZIPInputStreamUnitTest { + String testFilePath = Objects.requireNonNull(ReadingGZIPUsingGZIPInputStreamUnitTest.class.getClassLoader().getResource("myFile.gz")).getFile(); + List expectedFilteredLines = Arrays.asList("Line 1 content", "Line 2 content", "Line 3 content"); + + @Test + void givenGZFile_whenUsingGZIPInputStream_thenReadLines() throws IOException { + try (Stream lines = Main.readGZipFile(testFilePath).stream()) { + List result = lines + .filter(expectedFilteredLines::contains) + .collect(Collectors.toList()); + + assertEquals(expectedFilteredLines, result); + } + } + + @Test + void givenGZFile_whenUsingtestFindInZipFile_thenReadLines() throws IOException { + String toFind = "Line 1 content"; + + List result = Main.findInZipFile(testFilePath, toFind); + + assertEquals("Line 1 content", result.get(0)); + + } + + @Test + void givenGZFile_whenUsingContentsOfZipFile_thenReadLines() throws IOException { + AtomicInteger count = new AtomicInteger(0); + + Main.useContentsOfZipFile(testFilePath, linesStream -> { + linesStream.filter(line -> line.length() > 10).forEach(line -> count.incrementAndGet()); + }); + + assertEquals(3, count.get()); + } +} diff --git a/core-java-modules/core-java-io-5/src/test/resources/myFile.gz b/core-java-modules/core-java-io-5/src/test/resources/myFile.gz new file mode 100644 index 0000000000000000000000000000000000000000..47c3ad1e1bf21509aad3565310817853ec643c24 GIT binary patch literal 43 vcmb2|=3oGW|DR8u@eVZz@i=#0+w-jU!%vKby#YIq8R#(_ynNJC2dD-BT*DB2 literal 0 HcmV?d00001 From 42b9fb45983b9180de1ad765feaaee7d9b1c1b31 Mon Sep 17 00:00:00 2001 From: Harry9656 Date: Sun, 24 Mar 2024 23:53:37 +0100 Subject: [PATCH 23/51] [JAVA-32171] Fix missing pom.xml (#16196) --- aws-modules/aws-reactive/pom.xml | 1 + maven-modules/pom.xml | 3 +++ maven-modules/version-overriding-plugins/pom.xml | 1 + .../version-overriding-child-a/pom.xml | 1 + microservices-modules/micronaut/pom.xml | 2 ++ patterns-modules/enterprise-patterns/pom.xml | 1 + patterns-modules/intercepting-filter/pom.xml | 2 ++ patterns-modules/monkey-patching/pom.xml | 7 ++++++- persistence-modules/spring-boot-persistence-2/pom.xml | 1 + persistence-modules/spring-boot-persistence-3/pom.xml | 1 + server-modules/undertow/pom.xml | 1 + server-modules/wildfly/pom.xml | 1 + spf4j/spf4j-aspects-app/pom.xml | 1 + spf4j/spf4j-core-app/pom.xml | 1 + tensorflow-java/pom.xml | 2 ++ web-modules/blade/pom.xml | 1 + web-modules/dropwizard/pom.xml | 2 ++ 17 files changed, 28 insertions(+), 1 deletion(-) diff --git a/aws-modules/aws-reactive/pom.xml b/aws-modules/aws-reactive/pom.xml index 7a425c44b4..0ff255d960 100644 --- a/aws-modules/aws-reactive/pom.xml +++ b/aws-modules/aws-reactive/pom.xml @@ -87,6 +87,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring.version} diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 2be1309c25..956ae917ac 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -84,4 +84,7 @@ + + 3.1.0 + \ No newline at end of file diff --git a/maven-modules/version-overriding-plugins/pom.xml b/maven-modules/version-overriding-plugins/pom.xml index d38541d797..1f3106df3b 100644 --- a/maven-modules/version-overriding-plugins/pom.xml +++ b/maven-modules/version-overriding-plugins/pom.xml @@ -30,6 +30,7 @@ maven-resources-plugin + ${maven-resources-plugin.version} diff --git a/maven-modules/version-overriding-plugins/version-overriding-child-a/pom.xml b/maven-modules/version-overriding-plugins/version-overriding-child-a/pom.xml index 48b5782f72..e54768b5c3 100644 --- a/maven-modules/version-overriding-plugins/version-overriding-child-a/pom.xml +++ b/maven-modules/version-overriding-plugins/version-overriding-child-a/pom.xml @@ -16,6 +16,7 @@ maven-resources-plugin + ${maven-resources-plugin.version} diff --git a/microservices-modules/micronaut/pom.xml b/microservices-modules/micronaut/pom.xml index fa73a15ac4..641b23d5e6 100644 --- a/microservices-modules/micronaut/pom.xml +++ b/microservices-modules/micronaut/pom.xml @@ -101,6 +101,7 @@ io.micronaut.build micronaut-maven-plugin + ${micronaut-build.version} org.apache.maven.plugins @@ -154,6 +155,7 @@ jar 3.12.1 netty + 3.5.4 3.2.0 diff --git a/patterns-modules/enterprise-patterns/pom.xml b/patterns-modules/enterprise-patterns/pom.xml index a3c9da448d..45da43ba6f 100644 --- a/patterns-modules/enterprise-patterns/pom.xml +++ b/patterns-modules/enterprise-patterns/pom.xml @@ -52,6 +52,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot.version} diff --git a/patterns-modules/intercepting-filter/pom.xml b/patterns-modules/intercepting-filter/pom.xml index 60246e7838..949695afed 100644 --- a/patterns-modules/intercepting-filter/pom.xml +++ b/patterns-modules/intercepting-filter/pom.xml @@ -39,6 +39,7 @@ org.eclipse.jetty jetty-maven-plugin + ${jetty-plugin.version} / @@ -50,6 +51,7 @@ 3.3.2 + 11.0.20 \ No newline at end of file diff --git a/patterns-modules/monkey-patching/pom.xml b/patterns-modules/monkey-patching/pom.xml index e7fae87646..1d0146d990 100644 --- a/patterns-modules/monkey-patching/pom.xml +++ b/patterns-modules/monkey-patching/pom.xml @@ -29,7 +29,7 @@ org.springframework.boot spring-boot-starter-aop - 2.7.0 + ${spring-boot.version} @@ -38,7 +38,12 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot.version} + + + 2.7.0 + diff --git a/persistence-modules/spring-boot-persistence-2/pom.xml b/persistence-modules/spring-boot-persistence-2/pom.xml index 9b22e6902c..0937e76fa1 100644 --- a/persistence-modules/spring-boot-persistence-2/pom.xml +++ b/persistence-modules/spring-boot-persistence-2/pom.xml @@ -124,6 +124,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring.boot.dependencies} diff --git a/persistence-modules/spring-boot-persistence-3/pom.xml b/persistence-modules/spring-boot-persistence-3/pom.xml index fd4d354c78..2684d4dcd2 100644 --- a/persistence-modules/spring-boot-persistence-3/pom.xml +++ b/persistence-modules/spring-boot-persistence-3/pom.xml @@ -55,6 +55,7 @@ org.springframework.boot spring-boot-maven-plugin + ${spring.boot.dependencies} diff --git a/server-modules/undertow/pom.xml b/server-modules/undertow/pom.xml index a73771485c..8baf69c88a 100644 --- a/server-modules/undertow/pom.xml +++ b/server-modules/undertow/pom.xml @@ -32,6 +32,7 @@ org.apache.maven.plugins maven-jar-plugin + ${maven-jar-plugin.version} diff --git a/server-modules/wildfly/pom.xml b/server-modules/wildfly/pom.xml index fece3c9866..bc02f42b98 100644 --- a/server-modules/wildfly/pom.xml +++ b/server-modules/wildfly/pom.xml @@ -51,6 +51,7 @@ maven-failsafe-plugin + ${maven-failsafe-plugin.version} diff --git a/spf4j/spf4j-aspects-app/pom.xml b/spf4j/spf4j-aspects-app/pom.xml index 9769ff77f3..df3b0ee551 100644 --- a/spf4j/spf4j-aspects-app/pom.xml +++ b/spf4j/spf4j-aspects-app/pom.xml @@ -77,6 +77,7 @@ org.apache.maven.plugins maven-jar-plugin + ${maven-jar-plugin.version} diff --git a/spf4j/spf4j-core-app/pom.xml b/spf4j/spf4j-core-app/pom.xml index ee82ea869a..665b37583c 100644 --- a/spf4j/spf4j-core-app/pom.xml +++ b/spf4j/spf4j-core-app/pom.xml @@ -83,6 +83,7 @@ org.apache.maven.plugins maven-jar-plugin + ${maven-jar-plugin.version} diff --git a/tensorflow-java/pom.xml b/tensorflow-java/pom.xml index 4dd86d45e3..888588efe5 100644 --- a/tensorflow-java/pom.xml +++ b/tensorflow-java/pom.xml @@ -28,12 +28,14 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-maven-plugin.version} 1.12.0 + 3.2.2 \ No newline at end of file diff --git a/web-modules/blade/pom.xml b/web-modules/blade/pom.xml index fb0ca13dbe..2748c05663 100644 --- a/web-modules/blade/pom.xml +++ b/web-modules/blade/pom.xml @@ -62,6 +62,7 @@ org.apache.maven.plugins maven-failsafe-plugin + ${maven-failsafe-plugin.version} true diff --git a/web-modules/dropwizard/pom.xml b/web-modules/dropwizard/pom.xml index 03562acded..a1cc17f5bf 100644 --- a/web-modules/dropwizard/pom.xml +++ b/web-modules/dropwizard/pom.xml @@ -27,6 +27,7 @@ org.apache.maven.plugins maven-shade-plugin + ${maven-shade-plugin.version} true @@ -64,6 +65,7 @@ 2.0.0 + 3.5.0 \ No newline at end of file From e0a6bc2da39ed3b166ecf2fd09ec09ced6135e39 Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 25 Mar 2024 04:38:15 +0530 Subject: [PATCH 24/51] [JAVA-29007] - Upgrade Spring Reactive exceptions (#16208) --- spring-reactive-modules/spring-reactive-exceptions/pom.xml | 6 ++++++ .../spring/reactive/customexception/model/ErrorDetails.java | 6 +++--- .../customexception/controller/UserControllerUnitTest.java | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-reactive-modules/spring-reactive-exceptions/pom.xml b/spring-reactive-modules/spring-reactive-exceptions/pom.xml index 1f24f9cd1c..8cde579ddb 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/pom.xml +++ b/spring-reactive-modules/spring-reactive-exceptions/pom.xml @@ -61,4 +61,10 @@ + + 3.2.2 + 5.10.2 + 17 + + diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/customexception/model/ErrorDetails.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/customexception/model/ErrorDetails.java index a4ca566c71..357998dda1 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/customexception/model/ErrorDetails.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/customexception/model/ErrorDetails.java @@ -11,11 +11,11 @@ public enum ErrorDetails { API_USER_NOT_FOUND(123, "User not found", "http://example.com/123"); @Getter - private Integer errorCode; + private final Integer errorCode; @Getter - private String errorMessage; + private final String errorMessage; @Getter - private String referenceUrl; + private final String referenceUrl; ErrorDetails(Integer errorCode, String errorMessage, String referenceUrl) { this.errorCode = errorCode; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/customexception/controller/UserControllerUnitTest.java b/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/customexception/controller/UserControllerUnitTest.java index 150d0b08a6..c4306e6e62 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/customexception/controller/UserControllerUnitTest.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/customexception/controller/UserControllerUnitTest.java @@ -1,6 +1,6 @@ package com.baeldung.spring.reactive.customexception.controller; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -55,7 +55,7 @@ class UserControllerUnitTest { // Then assertNotNull(problemDetail); assertNotNull(problemDetail.getProperties().get("errors")); - List errors = (List) problemDetail.getProperties().get("errors"); + List> errors = (List>) problemDetail.getProperties().get("errors"); assertEquals(ErrorDetails.API_USER_NOT_FOUND.getErrorCode().toString(), errors.get(0).get("code")); assertEquals(ErrorDetails.API_USER_NOT_FOUND.getErrorMessage().toString(), From 7c0faeef8647c6182a33451d32b949d2423648e6 Mon Sep 17 00:00:00 2001 From: sachin <56427366+sachin071287@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:57:58 +0530 Subject: [PATCH 25/51] Prototype Scoped Bean With Runtime Arguments (#15936) * Prototype Scoped Bean With Runtime Arguments * Prototype Scoped Bean With Runtime Arguments --------- Co-authored-by: Sachin kumar --- .../dynamicarguments/Employee.java | 26 ++++++++++ .../EmployeeBeanUsingFunction.java | 17 +++++++ .../EmployeeBeanUsingLookUp.java | 14 ++++++ .../EmployeeBeanUsingObjectFactory.java | 14 ++++++ .../EmployeeBeanUsingObjectProvider.java | 14 ++++++ .../dynamicarguments/EmployeeConfig.java | 39 +++++++++++++++ .../dynamicarguments/DynamicBeanUnitTest.java | 48 +++++++++++++++++++ 7 files changed, 172 insertions(+) create mode 100644 spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/Employee.java create mode 100644 spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingFunction.java create mode 100644 spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingLookUp.java create mode 100644 spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectFactory.java create mode 100644 spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectProvider.java create mode 100644 spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeConfig.java create mode 100644 spring-di-4/src/test/java/com/baeldung/prototypebean/dynamicarguments/DynamicBeanUnitTest.java diff --git a/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/Employee.java b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/Employee.java new file mode 100644 index 0000000000..01eeb97936 --- /dev/null +++ b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/Employee.java @@ -0,0 +1,26 @@ +package com.baeldung.prototypebean.dynamicarguments; + +public class Employee { + + private String name; + + public Employee() { + } + + public Employee(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void printName() { + System.out.println(name); + } + +} diff --git a/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingFunction.java b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingFunction.java new file mode 100644 index 0000000000..02c283214c --- /dev/null +++ b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingFunction.java @@ -0,0 +1,17 @@ +package com.baeldung.prototypebean.dynamicarguments; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cglib.core.internal.Function; +import org.springframework.stereotype.Component; + +@Component +public class EmployeeBeanUsingFunction { + + @Autowired + private Function beanFactory; + + public Employee getEmployee(String name) { + Employee employee = beanFactory.apply(name); + return employee; + } +} diff --git a/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingLookUp.java b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingLookUp.java new file mode 100644 index 0000000000..2bdcc41e89 --- /dev/null +++ b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingLookUp.java @@ -0,0 +1,14 @@ +package com.baeldung.prototypebean.dynamicarguments; + +import org.springframework.beans.factory.annotation.Lookup; +import org.springframework.stereotype.Component; + +@Component +public class EmployeeBeanUsingLookUp { + + @Lookup + public Employee getEmployee(String arg) { + return null; + } + +} diff --git a/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectFactory.java b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectFactory.java new file mode 100644 index 0000000000..4fcb90de59 --- /dev/null +++ b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectFactory.java @@ -0,0 +1,14 @@ +package com.baeldung.prototypebean.dynamicarguments; + +import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.annotation.Autowired; + +public class EmployeeBeanUsingObjectFactory { + + @Autowired + private ObjectFactory employeeObjectFactory; + + public Employee getEmployee() { + return employeeObjectFactory.getObject(); + } +} \ No newline at end of file diff --git a/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectProvider.java b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectProvider.java new file mode 100644 index 0000000000..e04f98278c --- /dev/null +++ b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeBeanUsingObjectProvider.java @@ -0,0 +1,14 @@ +package com.baeldung.prototypebean.dynamicarguments; + +import org.springframework.beans.factory.annotation.Autowired; + +public class EmployeeBeanUsingObjectProvider { + + @Autowired + private org.springframework.beans.factory.ObjectProvider objectProvider; + + public Employee getEmployee(String name) { + Employee employee = objectProvider.getObject(name); + return employee; + } +} diff --git a/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeConfig.java b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeConfig.java new file mode 100644 index 0000000000..ebbd68a22b --- /dev/null +++ b/spring-di-4/src/main/java/com/baeldung/prototypebean/dynamicarguments/EmployeeConfig.java @@ -0,0 +1,39 @@ +package com.baeldung.prototypebean.dynamicarguments; + +import org.springframework.cglib.core.internal.Function; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +@Configuration +@ComponentScan(basePackages = { "com.baeldung.prototypebean.dynamicarguments" }) +public class EmployeeConfig { + + @Bean + @Scope(value = "prototype") + public Employee getEmployee(String name) { + return new Employee(name); + } + + @Bean + public EmployeeBeanUsingObjectProvider employeeBeanUsingObjectProvider() { + return new EmployeeBeanUsingObjectProvider(); + } + + @Bean + public EmployeeBeanUsingObjectFactory employeeBeanUsingObjectFactory() { + return new EmployeeBeanUsingObjectFactory(); + } + + @Bean + public Function beanFactory() { + return name -> getEmployee(name); + } + + @Bean + public EmployeeBeanUsingFunction employeeBeanUsingFunction() { + return new EmployeeBeanUsingFunction(); + } + +} diff --git a/spring-di-4/src/test/java/com/baeldung/prototypebean/dynamicarguments/DynamicBeanUnitTest.java b/spring-di-4/src/test/java/com/baeldung/prototypebean/dynamicarguments/DynamicBeanUnitTest.java new file mode 100644 index 0000000000..0c6e6a7658 --- /dev/null +++ b/spring-di-4/src/test/java/com/baeldung/prototypebean/dynamicarguments/DynamicBeanUnitTest.java @@ -0,0 +1,48 @@ +package com.baeldung.prototypebean.dynamicarguments; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import junit.framework.Assert; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = EmployeeConfig.class) +public class DynamicBeanUnitTest { + + @Test + public void givenPrototypeBean_WhenFunction_ThenNewInstanceReturn() { + + AbstractApplicationContext context = new AnnotationConfigApplicationContext(EmployeeConfig.class); + EmployeeBeanUsingFunction firstContext = context.getBean(EmployeeBeanUsingFunction.class); + EmployeeBeanUsingFunction secondContext = context.getBean(EmployeeBeanUsingFunction.class); + Employee firstInstance = firstContext.getEmployee("sachin"); + Employee secondInstance = secondContext.getEmployee("kumar"); + Assert.assertTrue(firstInstance != secondInstance); + } + + @Test + public void givenPrototypeBean_WhenLookup_ThenNewInstanceReturn() { + + AbstractApplicationContext context = new AnnotationConfigApplicationContext(EmployeeConfig.class); + EmployeeBeanUsingLookUp firstContext = context.getBean(EmployeeBeanUsingLookUp.class); + EmployeeBeanUsingLookUp secondContext = context.getBean(EmployeeBeanUsingLookUp.class); + Employee firstInstance = firstContext.getEmployee("sachin"); + Employee secondInstance = secondContext.getEmployee("kumar"); + Assert.assertTrue(firstInstance != secondInstance); + } + + @Test + public void givenPrototypeBean_WhenObjectProvider_ThenNewInstanceReturn() { + AbstractApplicationContext context = new AnnotationConfigApplicationContext(EmployeeConfig.class); + EmployeeBeanUsingObjectProvider firstContext = context.getBean(EmployeeBeanUsingObjectProvider.class); + EmployeeBeanUsingObjectProvider secondContext = context.getBean(EmployeeBeanUsingObjectProvider.class); + Employee firstInstance = firstContext.getEmployee("sachin"); + Employee secondInstance = secondContext.getEmployee("kumar"); + Assert.assertTrue(firstInstance != secondInstance); + } +} From 8d8acb9117d9f5047ab4d2ccb47aead3d2f4431d Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:51:56 +0200 Subject: [PATCH 26/51] [JAVA-31614] (#16224) --- spring-boot-modules/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 873232123b..b5fcb33ef7 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -101,7 +101,7 @@ spring-boot-resilience4j spring-boot-properties spring-boot-properties-2 - + spring-boot-properties-3 spring-boot-properties-4 spring-boot-properties-migrator-demo spring-boot-aws From 0facf5ca65b18d5e5eb00eaccb655322b40b062e Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Tue, 26 Mar 2024 03:25:56 +0530 Subject: [PATCH 27/51] [JAVA-27762] Upgrade spring-reactive-3 to boot-3 (#16214) --- .../spring-reactive-3/pom.xml | 13 +++++++++--- .../websocket/WebSocketController.java | 4 ++-- .../DataBufferToInputStreamUnitTest.java | 21 +++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/spring-reactive-modules/spring-reactive-3/pom.xml b/spring-reactive-modules/spring-reactive-3/pom.xml index 15cf80fda1..dc821b111d 100644 --- a/spring-reactive-modules/spring-reactive-3/pom.xml +++ b/spring-reactive-modules/spring-reactive-3/pom.xml @@ -10,9 +10,10 @@ spring sample project about new features - com.baeldung.spring.reactive - spring-reactive-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -74,6 +75,11 @@ kotlin-stdlib ${kotlin-stdlib.version} + + commons-io + commons-io + ${commons-io.version} + @@ -93,6 +99,7 @@ 2021.0.4 5.0.0-alpha.12 2.0.0-Beta4 + com.baeldung.custom.deserialization.Application \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/websocket/WebSocketController.java b/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/websocket/WebSocketController.java index 0c8f9debc9..22f602df86 100644 --- a/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/websocket/WebSocketController.java +++ b/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/websocket/WebSocketController.java @@ -3,8 +3,8 @@ package com.baeldung.websocket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.websocket.*; -import javax.websocket.server.ServerEndpoint; +import jakarta.websocket.*; +import jakarta.websocket.server.ServerEndpoint; import java.io.IOException; @ServerEndpoint("/event-emitter") diff --git a/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java b/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java index 975a2d8698..b6660e4214 100644 --- a/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java +++ b/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java @@ -1,11 +1,15 @@ package com.baeldung.databuffer; -import com.baeldung.databuffer.DataBufferToInputStream; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import io.restassured.internal.util.IOUtils; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.stream.Collectors; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.ExchangeFunction; @@ -13,17 +17,6 @@ import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URI; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - class DataBufferToInputStreamUnitTest { private String getResponseStub() throws IOException { InputStream inputStream = null; From c75b4b13fa54b915d7750bd6402a741b7ec9f90f Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:06:53 +0200 Subject: [PATCH 28/51] [JAVA-31545] (#16222) --- spring-boot-modules/pom.xml | 4 ++-- .../{spring-caching-2 => spring-boot-caching-2}/README.md | 1 + .../{spring-caching-2 => spring-boot-caching-2}/pom.xml | 0 .../java/com/baeldung/allkeys/config/AllKeysConfig.java | 0 .../baeldung/allkeys/service/SlowServiceWithCache.java | 0 .../main/java/com/baeldung/caching/redis/CacheConfig.java | 0 .../src/main/java/com/baeldung/caching/redis/Item.java | 0 .../java/com/baeldung/caching/redis/ItemController.java | 0 .../java/com/baeldung/caching/redis/ItemRepository.java | 0 .../main/java/com/baeldung/caching/redis/ItemService.java | 0 .../com/baeldung/caching/redis/RedisCacheApplication.java | 0 .../com/baeldung/caching/ttl/CachingTTLApplication.java | 0 .../baeldung/caching/ttl/config/SpringCachingConfig.java | 0 .../baeldung/caching/ttl/controller/HotelController.java | 0 .../baeldung/caching/ttl/exception/ControllerAdvisor.java | 0 .../caching/ttl/exception/ElementNotFoundException.java | 0 .../main/java/com/baeldung/caching/ttl/model/City.java | 0 .../main/java/com/baeldung/caching/ttl/model/Hotel.java | 0 .../baeldung/caching/ttl/repository/CityRepository.java | 0 .../baeldung/caching/ttl/repository/HotelRepository.java | 0 .../com/baeldung/caching/ttl/service/HotelService.java | 0 .../caching/ttl/service/SpringCacheCustomizer.java | 0 .../com/baeldung/caching/twolevelcache/CacheConfig.java | 0 .../java/com/baeldung/caching/twolevelcache/Customer.java | 0 .../caching/twolevelcache/CustomerCacheInterceptor.java | 0 .../caching/twolevelcache/CustomerRepository.java | 0 .../baeldung/caching/twolevelcache/CustomerService.java | 0 .../caching/twolevelcache/TwoLevelCacheApplication.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/data.sql | 0 .../allkeys/boot/GetAllCacheKeysIntegrationTest.java | 0 .../caching/redis/ItemServiceCachingIntegrationTest.java | 0 .../caching/ttl/HotelControllerIntegrationTest.java | 0 .../src/test/java/com/baeldung/caching/ttl/SlowTest.java | 0 .../CustomerServiceCachingIntegrationTest.java | 0 .../src/test/resources/application.properties | 0 .../{spring-caching => spring-boot-caching}/README.md | 1 + .../{spring-caching => spring-boot-caching}/pom.xml | 8 +++----- .../src/main/java/com/baeldung/cachetest/Application.java | 0 .../java/com/baeldung/cachetest/config/CacheConfig.java | 0 .../com/baeldung/cachetest/config/CacheEventLogger.java | 0 .../com/baeldung/cachetest/rest/NumberController.java | 0 .../com/baeldung/cachetest/service/NumberService.java | 0 .../java/com/baeldung/caching/boot/CacheApplication.java | 0 .../com/baeldung/caching/boot/SimpleCacheCustomizer.java | 0 .../baeldung/caching/config/ApplicationCacheConfig.java | 0 .../java/com/baeldung/caching/config/CachingConfig.java | 0 .../com/baeldung/caching/config/CustomKeyGenerator.java | 0 .../caching/eviction/controllers/CachingController.java | 0 .../baeldung/caching/eviction/service/CachingService.java | 0 .../com/baeldung/caching/example/AbstractService.java | 0 .../java/com/baeldung/caching/example/BookService.java | 0 .../main/java/com/baeldung/caching/example/Customer.java | 0 .../com/baeldung/caching/example/CustomerDataService.java | 0 .../caching/example/CustomerServiceWithParent.java | 0 .../src/main/java/com/baeldung/caching/model/Book.java | 0 .../baeldung/ehcache/calculator/SquaredCalculator.java | 0 .../java/com/baeldung/ehcache/config/CacheHelper.java | 0 .../multiplecachemanager/bo/CustomerDetailBO.java | 0 .../baeldung/multiplecachemanager/bo/OrderDetailBO.java | 0 .../config/MultipleCacheManagerConfig.java | 0 .../config/MultipleCacheResolver.java | 0 .../controller/MultipleCacheManagerController.java | 0 .../baeldung/multiplecachemanager/entity/Customer.java | 0 .../com/baeldung/multiplecachemanager/entity/Item.java | 0 .../com/baeldung/multiplecachemanager/entity/Order.java | 0 .../repository/CustomerDetailRepository.java | 0 .../repository/OrderDetailRepository.java | 0 .../java/com/baeldung/springdatacaching/model/Book.java | 0 .../springdatacaching/repositories/BookRepository.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/config.xml | 0 .../src/main/resources/data.sql | 0 .../src/main/resources/ehcache.xml | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/schema.sql | 0 .../boot/SimpleCacheCustomizerIntegrationTest.java | 0 .../caching/test/CacheEvictAnnotationIntegrationTest.java | 0 .../caching/test/CacheManagerEvictIntegrationTest.java | 0 .../caching/test/SpringCachingIntegrationTest.java | 0 .../com/baeldung/ehcache/SquareCalculatorUnitTest.java | 0 .../MultipleCacheManagerIntegrationTest.java | 0 .../BookRepositoryCachingIntegrationTest.java | 0 .../repositories/BookRepositoryIntegrationTest.java | 0 84 files changed, 7 insertions(+), 7 deletions(-) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/README.md (85%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/pom.xml (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/allkeys/config/AllKeysConfig.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/allkeys/service/SlowServiceWithCache.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/redis/CacheConfig.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/redis/Item.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/redis/ItemController.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/redis/ItemRepository.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/redis/ItemService.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/CachingTTLApplication.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/exception/ElementNotFoundException.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/model/City.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/model/Hotel.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/repository/CityRepository.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/repository/HotelRepository.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/service/HotelService.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/ttl/service/SpringCacheCustomizer.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/twolevelcache/Customer.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/java/com/baeldung/caching/twolevelcache/TwoLevelCacheApplication.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/resources/application.properties (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/main/resources/data.sql (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/test/java/com/baeldung/caching/allkeys/boot/GetAllCacheKeysIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/test/java/com/baeldung/caching/ttl/HotelControllerIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/test/java/com/baeldung/caching/ttl/SlowTest.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching-2 => spring-boot-caching-2}/src/test/resources/application.properties (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/README.md (89%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/pom.xml (92%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/cachetest/Application.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/cachetest/config/CacheConfig.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/cachetest/config/CacheEventLogger.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/cachetest/rest/NumberController.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/cachetest/service/NumberService.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/boot/CacheApplication.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/boot/SimpleCacheCustomizer.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/config/ApplicationCacheConfig.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/config/CachingConfig.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/config/CustomKeyGenerator.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/eviction/controllers/CachingController.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/eviction/service/CachingService.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/example/AbstractService.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/example/BookService.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/example/Customer.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/example/CustomerDataService.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/example/CustomerServiceWithParent.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/caching/model/Book.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/ehcache/config/CacheHelper.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/springdatacaching/model/Book.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/java/com/baeldung/springdatacaching/repositories/BookRepository.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/resources/application.properties (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/resources/config.xml (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/resources/data.sql (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/resources/ehcache.xml (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/resources/logback.xml (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/main/resources/schema.sql (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/caching/boot/SimpleCacheCustomizerIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/caching/test/CacheEvictAnnotationIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/caching/test/CacheManagerEvictIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/caching/test/SpringCachingIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryCachingIntegrationTest.java (100%) rename spring-boot-modules/{spring-caching => spring-boot-caching}/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryIntegrationTest.java (100%) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index b5fcb33ef7..00d6405cbf 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -27,6 +27,8 @@ spring-boot-basic-customization spring-boot-basic-customization-2 spring-boot-bootstrap + spring-boot-caching + spring-boot-caching-2 spring-boot-client spring-boot-config-jpa-error spring-boot-ctx-fluent @@ -86,8 +88,6 @@ spring-boot-data-2 spring-boot-validation - - spring-boot-cassandre spring-boot-react diff --git a/spring-boot-modules/spring-caching-2/README.md b/spring-boot-modules/spring-boot-caching-2/README.md similarity index 85% rename from spring-boot-modules/spring-caching-2/README.md rename to spring-boot-modules/spring-boot-caching-2/README.md index fffdacdfb2..a2b0c41c63 100644 --- a/spring-boot-modules/spring-caching-2/README.md +++ b/spring-boot-modules/spring-boot-caching-2/README.md @@ -3,4 +3,5 @@ - [Setting Time-To-Live Value for Caching](https://www.baeldung.com/spring-setting-ttl-value-cache) - [Get All Cached Keys with Caffeine Cache in Spring Boot](https://www.baeldung.com/spring-boot-caffeine-spring-get-all-keys) - [Implement Two-Level Cache With Spring](https://www.baeldung.com/spring-two-level-cache) +- More articles: [[<-- prev]](/spring-boot-modules/spring-boot-caching) diff --git a/spring-boot-modules/spring-caching-2/pom.xml b/spring-boot-modules/spring-boot-caching-2/pom.xml similarity index 100% rename from spring-boot-modules/spring-caching-2/pom.xml rename to spring-boot-modules/spring-boot-caching-2/pom.xml diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/allkeys/config/AllKeysConfig.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/allkeys/config/AllKeysConfig.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/allkeys/config/AllKeysConfig.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/allkeys/config/AllKeysConfig.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/allkeys/service/SlowServiceWithCache.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/allkeys/service/SlowServiceWithCache.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/allkeys/service/SlowServiceWithCache.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/allkeys/service/SlowServiceWithCache.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/CacheConfig.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/CacheConfig.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/CacheConfig.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/CacheConfig.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/Item.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/Item.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/Item.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/Item.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemController.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/ItemController.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemController.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/ItemController.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemRepository.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/ItemRepository.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemRepository.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/ItemRepository.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemService.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/ItemService.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/ItemService.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/ItemService.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/redis/RedisCacheApplication.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/CachingTTLApplication.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/CachingTTLApplication.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/CachingTTLApplication.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/CachingTTLApplication.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/config/SpringCachingConfig.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/controller/HotelController.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ControllerAdvisor.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ElementNotFoundException.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ElementNotFoundException.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ElementNotFoundException.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/exception/ElementNotFoundException.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/model/City.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/model/City.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/model/City.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/model/City.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/model/Hotel.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/model/Hotel.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/model/Hotel.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/model/Hotel.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/repository/CityRepository.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/repository/CityRepository.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/repository/CityRepository.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/repository/CityRepository.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/repository/HotelRepository.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/repository/HotelRepository.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/repository/HotelRepository.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/repository/HotelRepository.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/service/HotelService.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/service/HotelService.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/service/HotelService.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/service/HotelService.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/service/SpringCacheCustomizer.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/service/SpringCacheCustomizer.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/ttl/service/SpringCacheCustomizer.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/ttl/service/SpringCacheCustomizer.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/TwoLevelCacheApplication.java b/spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/TwoLevelCacheApplication.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/TwoLevelCacheApplication.java rename to spring-boot-modules/spring-boot-caching-2/src/main/java/com/baeldung/caching/twolevelcache/TwoLevelCacheApplication.java diff --git a/spring-boot-modules/spring-caching-2/src/main/resources/application.properties b/spring-boot-modules/spring-boot-caching-2/src/main/resources/application.properties similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/resources/application.properties rename to spring-boot-modules/spring-boot-caching-2/src/main/resources/application.properties diff --git a/spring-boot-modules/spring-caching-2/src/main/resources/data.sql b/spring-boot-modules/spring-boot-caching-2/src/main/resources/data.sql similarity index 100% rename from spring-boot-modules/spring-caching-2/src/main/resources/data.sql rename to spring-boot-modules/spring-boot-caching-2/src/main/resources/data.sql diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/allkeys/boot/GetAllCacheKeysIntegrationTest.java b/spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/allkeys/boot/GetAllCacheKeysIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/allkeys/boot/GetAllCacheKeysIntegrationTest.java rename to spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/allkeys/boot/GetAllCacheKeysIntegrationTest.java diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java b/spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java rename to spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/ttl/HotelControllerIntegrationTest.java b/spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/ttl/HotelControllerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/ttl/HotelControllerIntegrationTest.java rename to spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/ttl/HotelControllerIntegrationTest.java diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/ttl/SlowTest.java b/spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/ttl/SlowTest.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/ttl/SlowTest.java rename to spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/ttl/SlowTest.java diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java b/spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java rename to spring-boot-modules/spring-boot-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java diff --git a/spring-boot-modules/spring-caching-2/src/test/resources/application.properties b/spring-boot-modules/spring-boot-caching-2/src/test/resources/application.properties similarity index 100% rename from spring-boot-modules/spring-caching-2/src/test/resources/application.properties rename to spring-boot-modules/spring-boot-caching-2/src/test/resources/application.properties diff --git a/spring-boot-modules/spring-caching/README.md b/spring-boot-modules/spring-boot-caching/README.md similarity index 89% rename from spring-boot-modules/spring-caching/README.md rename to spring-boot-modules/spring-boot-caching/README.md index e10d6080e8..1690be8f47 100644 --- a/spring-boot-modules/spring-caching/README.md +++ b/spring-boot-modules/spring-boot-caching/README.md @@ -6,3 +6,4 @@ - [Using Multiple Cache Managers in Spring](https://www.baeldung.com/spring-multiple-cache-managers) - [Testing @Cacheable on Spring Data Repositories](https://www.baeldung.com/spring-data-testing-cacheable) - [Spring Boot Ehcache Example](https://www.baeldung.com/spring-boot-ehcache) +- More articles: [[next -->]](/spring-boot-modules/spring-boot-caching-2) \ No newline at end of file diff --git a/spring-boot-modules/spring-caching/pom.xml b/spring-boot-modules/spring-boot-caching/pom.xml similarity index 92% rename from spring-boot-modules/spring-caching/pom.xml rename to spring-boot-modules/spring-boot-caching/pom.xml index 5b4dde6e8b..36fbe6ef27 100644 --- a/spring-boot-modules/spring-caching/pom.xml +++ b/spring-boot-modules/spring-boot-caching/pom.xml @@ -9,10 +9,9 @@ war - com.baeldung - parent-boot-3 - 0.0.1-SNAPSHOT - ../../parent-boot-3 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT @@ -49,7 +48,6 @@ com.github.ben-manes.caffeine caffeine - ${caffeine.version} com.h2database diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/Application.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/Application.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/Application.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/Application.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/config/CacheConfig.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/config/CacheConfig.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/config/CacheConfig.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/config/CacheConfig.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/config/CacheEventLogger.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/config/CacheEventLogger.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/config/CacheEventLogger.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/config/CacheEventLogger.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/rest/NumberController.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/rest/NumberController.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/rest/NumberController.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/rest/NumberController.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/service/NumberService.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/service/NumberService.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/cachetest/service/NumberService.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/cachetest/service/NumberService.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/boot/SimpleCacheCustomizer.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/boot/SimpleCacheCustomizer.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/boot/SimpleCacheCustomizer.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/boot/SimpleCacheCustomizer.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/config/ApplicationCacheConfig.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/config/ApplicationCacheConfig.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/config/ApplicationCacheConfig.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/config/ApplicationCacheConfig.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/config/CachingConfig.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/config/CachingConfig.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/config/CachingConfig.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/config/CachingConfig.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/config/CustomKeyGenerator.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/config/CustomKeyGenerator.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/config/CustomKeyGenerator.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/config/CustomKeyGenerator.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/eviction/controllers/CachingController.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/eviction/controllers/CachingController.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/eviction/controllers/CachingController.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/eviction/controllers/CachingController.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/eviction/service/CachingService.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/eviction/service/CachingService.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/eviction/service/CachingService.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/eviction/service/CachingService.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/AbstractService.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/AbstractService.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/AbstractService.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/AbstractService.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/BookService.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/BookService.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/BookService.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/BookService.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/Customer.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/Customer.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/Customer.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/Customer.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/CustomerDataService.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/CustomerDataService.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/CustomerDataService.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/CustomerDataService.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/CustomerServiceWithParent.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/CustomerServiceWithParent.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/example/CustomerServiceWithParent.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/example/CustomerServiceWithParent.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/model/Book.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/model/Book.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/caching/model/Book.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/caching/model/Book.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/ehcache/calculator/SquaredCalculator.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/ehcache/config/CacheHelper.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/ehcache/config/CacheHelper.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/ehcache/config/CacheHelper.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/ehcache/config/CacheHelper.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/springdatacaching/model/Book.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/springdatacaching/model/Book.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/springdatacaching/model/Book.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/springdatacaching/model/Book.java diff --git a/spring-boot-modules/spring-caching/src/main/java/com/baeldung/springdatacaching/repositories/BookRepository.java b/spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/springdatacaching/repositories/BookRepository.java similarity index 100% rename from spring-boot-modules/spring-caching/src/main/java/com/baeldung/springdatacaching/repositories/BookRepository.java rename to spring-boot-modules/spring-boot-caching/src/main/java/com/baeldung/springdatacaching/repositories/BookRepository.java diff --git a/spring-boot-modules/spring-caching/src/main/resources/application.properties b/spring-boot-modules/spring-boot-caching/src/main/resources/application.properties similarity index 100% rename from spring-boot-modules/spring-caching/src/main/resources/application.properties rename to spring-boot-modules/spring-boot-caching/src/main/resources/application.properties diff --git a/spring-boot-modules/spring-caching/src/main/resources/config.xml b/spring-boot-modules/spring-boot-caching/src/main/resources/config.xml similarity index 100% rename from spring-boot-modules/spring-caching/src/main/resources/config.xml rename to spring-boot-modules/spring-boot-caching/src/main/resources/config.xml diff --git a/spring-boot-modules/spring-caching/src/main/resources/data.sql b/spring-boot-modules/spring-boot-caching/src/main/resources/data.sql similarity index 100% rename from spring-boot-modules/spring-caching/src/main/resources/data.sql rename to spring-boot-modules/spring-boot-caching/src/main/resources/data.sql diff --git a/spring-boot-modules/spring-caching/src/main/resources/ehcache.xml b/spring-boot-modules/spring-boot-caching/src/main/resources/ehcache.xml similarity index 100% rename from spring-boot-modules/spring-caching/src/main/resources/ehcache.xml rename to spring-boot-modules/spring-boot-caching/src/main/resources/ehcache.xml diff --git a/spring-boot-modules/spring-caching/src/main/resources/logback.xml b/spring-boot-modules/spring-boot-caching/src/main/resources/logback.xml similarity index 100% rename from spring-boot-modules/spring-caching/src/main/resources/logback.xml rename to spring-boot-modules/spring-boot-caching/src/main/resources/logback.xml diff --git a/spring-boot-modules/spring-caching/src/main/resources/schema.sql b/spring-boot-modules/spring-boot-caching/src/main/resources/schema.sql similarity index 100% rename from spring-boot-modules/spring-caching/src/main/resources/schema.sql rename to spring-boot-modules/spring-boot-caching/src/main/resources/schema.sql diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/boot/SimpleCacheCustomizerIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/boot/SimpleCacheCustomizerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/boot/SimpleCacheCustomizerIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/boot/SimpleCacheCustomizerIntegrationTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/test/CacheEvictAnnotationIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/test/CacheEvictAnnotationIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/test/CacheEvictAnnotationIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/test/CacheEvictAnnotationIntegrationTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/test/CacheManagerEvictIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/test/CacheManagerEvictIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/test/CacheManagerEvictIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/test/CacheManagerEvictIntegrationTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/test/SpringCachingIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/test/SpringCachingIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/caching/test/SpringCachingIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/caching/test/SpringCachingIntegrationTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/ehcache/SquareCalculatorUnitTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryCachingIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryCachingIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryCachingIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryCachingIntegrationTest.java diff --git a/spring-boot-modules/spring-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryIntegrationTest.java rename to spring-boot-modules/spring-boot-caching/src/test/java/com/baeldung/springdatacaching/repositories/BookRepositoryIntegrationTest.java From 443512391896198f62c1629715298ba7449ca849 Mon Sep 17 00:00:00 2001 From: DiegoMarti2 <150871541+DiegoMarti2@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:07:55 +0200 Subject: [PATCH 29/51] baeldung-articles : BAEL-7644 (#16211) * baeldung-articles : BAEL-7644 Include null value in JSON serialization (Main) * baeldung-articles : BAEL-7644 Include null value in JSON serialization (Test). --- .../baeldung/includenullinjson/Customer.java | 27 +++++++++++++++++ .../IncludeNullValuesInJsonUnitTest.java | 30 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 json-modules/json-conversion/src/main/java/com/baeldung/includenullinjson/Customer.java create mode 100644 json-modules/json-conversion/src/test/java/com/baeldung/includenullinjson/IncludeNullValuesInJsonUnitTest.java diff --git a/json-modules/json-conversion/src/main/java/com/baeldung/includenullinjson/Customer.java b/json-modules/json-conversion/src/main/java/com/baeldung/includenullinjson/Customer.java new file mode 100644 index 0000000000..50855e16e9 --- /dev/null +++ b/json-modules/json-conversion/src/main/java/com/baeldung/includenullinjson/Customer.java @@ -0,0 +1,27 @@ +package com.baeldung.includenullinjson; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Customer { + @JsonProperty + private final String name; + @JsonProperty + private final String address; + @JsonProperty + private final int age; + + public Customer(String name, String address, int age) { + this.name = name; + this.address = address; + this.age = age; + } + + @Override + public String toString() { + return "Customer{" + + "name='" + name + '\'' + + ", address='" + address + '\'' + + ", age=" + age + + '}'; + } +} \ No newline at end of file diff --git a/json-modules/json-conversion/src/test/java/com/baeldung/includenullinjson/IncludeNullValuesInJsonUnitTest.java b/json-modules/json-conversion/src/test/java/com/baeldung/includenullinjson/IncludeNullValuesInJsonUnitTest.java new file mode 100644 index 0000000000..eb0d51b900 --- /dev/null +++ b/json-modules/json-conversion/src/test/java/com/baeldung/includenullinjson/IncludeNullValuesInJsonUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.includenullinjson; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class IncludeNullValuesInJsonUnitTest { + String expectedJson = "{\"name\":\"John\",\"address\":null,\"age\":25}"; + Customer obj = new Customer("John", null, 25); + + @Test + public void givenObjectWithNullField_whenJacksonUsed_thenIncludesNullValue() throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); + String json = mapper.writeValueAsString(obj); + assertEquals(expectedJson, json); + } + + @Test + public void givenObjectWithNullField_whenGsonUsed_thenIncludesNullValue() { + Gson gson = new GsonBuilder().serializeNulls().create(); + String json = gson.toJson(obj); + assertEquals(expectedJson, json); + } +} From 5fbc3a252b26a027a3719d07f36aaaf05ef3878e Mon Sep 17 00:00:00 2001 From: sam-gardner <53271849+sam-gardner@users.noreply.github.com> Date: Mon, 25 Mar 2024 22:12:47 +0000 Subject: [PATCH 30/51] [JAVA-28949] Upgrade spring-native to spring-boot 3 (#16229) --- spring-native/pom-nativeimage.xml | 80 ++++++++----------------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/spring-native/pom-nativeimage.xml b/spring-native/pom-nativeimage.xml index 4fc01e4574..08ceb09a8a 100644 --- a/spring-native/pom-nativeimage.xml +++ b/spring-native/pom-nativeimage.xml @@ -10,76 +10,41 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../parent-boot-2 + ../parent-boot-3 - spring-release - Spring release - https://repo.spring.io/release + spring-milestone + Spring Milestone + https://repo.spring.io/milestone + + + spring-snapshot + Spring Snapshot + https://repo.spring.io/snapshot - spring-release - Spring release - https://repo.spring.io/release + spring-plugins-snapshot + Spring Plugins Snapshot + https://repo.spring.io/plugins-snapshot org.springframework.boot - spring-boot-starter-parent + spring-boot-starter ${spring-boot.version} - pom - - - org.springframework.experimental - spring-native - ${spring-native.version} - - - org.springframework.experimental - spring-aot - ${spring-native.version} - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.springframework.experimental - spring-aot-maven-plugin - ${spring-native.version} - - - test-generate - - test-generate - - - - generate - - generate - - - - - - - - + native @@ -92,28 +57,21 @@ build-native - build + compile-no-fork package - - org.springframework.boot - spring-boot-maven-plugin - - exec - - - 2.7.1 - 0.12.1 - 0.9.17 + 3.2.0 + 17 + 0.10.1 From 4912f824c90c51196ce34a4396970b3d062f6a91 Mon Sep 17 00:00:00 2001 From: Mikhail Polivakha <68962645+Mikhail2048@users.noreply.github.com> Date: Tue, 26 Mar 2024 01:15:07 +0300 Subject: [PATCH 31/51] BAEL-6174 (#16213) --- .../hibernate-annotations/pom.xml | 12 ++++ .../config/HibernateAnnotationUtil.java | 2 + .../subselect/RuntimeConfiguration.java | 43 ++++++++++++ .../main/resources/migrations/V1__init.xml | 55 ++++++++++++++++ .../src/main/resources/migrations/master.xml | 7 ++ .../subselect/SubselectIntegrationTest.java | 65 +++++++++++++++++++ 6 files changed, 184 insertions(+) create mode 100644 persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/subselect/RuntimeConfiguration.java create mode 100644 persistence-modules/hibernate-annotations/src/main/resources/migrations/V1__init.xml create mode 100644 persistence-modules/hibernate-annotations/src/main/resources/migrations/master.xml create mode 100644 persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/subselect/SubselectIntegrationTest.java diff --git a/persistence-modules/hibernate-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml index 6f11888643..12a5298e95 100644 --- a/persistence-modules/hibernate-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -81,6 +81,16 @@ hypersistence-utils-hibernate-60 ${hypersistance-utils-hibernate-60.version} + + org.liquibase + liquibase-core + ${liquibase-core.version} + + + org.projectlombok + lombok + ${lombok.version} + @@ -91,6 +101,8 @@ true 9.0.0.M26 3.3.1 + 1.18.30 + 4.24.0 \ No newline at end of file diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java index 99410e1f76..0bf03e3fee 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java @@ -4,6 +4,7 @@ import com.baeldung.hibernate.oneToMany.model.Cart; import com.baeldung.hibernate.oneToMany.model.CartOIO; import com.baeldung.hibernate.oneToMany.model.Item; import com.baeldung.hibernate.oneToMany.model.ItemOIO; +import com.baeldung.hibernate.subselect.RuntimeConfiguration; import org.hibernate.SessionFactory; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; @@ -38,6 +39,7 @@ public class HibernateAnnotationUtil { .addAnnotatedClass(CartOIO.class) .addAnnotatedClass(Item.class) .addAnnotatedClass(ItemOIO.class) + .addAnnotatedClass(RuntimeConfiguration.class) .buildMetadata(); return metadata.buildSessionFactory(); diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/subselect/RuntimeConfiguration.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/subselect/RuntimeConfiguration.java new file mode 100644 index 0000000000..0f995bfe03 --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/subselect/RuntimeConfiguration.java @@ -0,0 +1,43 @@ +package com.baeldung.hibernate.subselect; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import java.time.Instant; +import lombok.Data; +import lombok.experimental.Accessors; +import org.hibernate.annotations.Subselect; + +@Data +@Accessors(chain = true) +@Entity +// language=sql +@Subselect(value = + "SELECT\n" + + " ss.id,\n" + + " ss.attr_key,\n" + + " ss.val,\n" + + " ss.created_at\n" + + " FROM system_settings AS ss\n" + + " INNER JOIN (\n" + + " SELECT\n" + + " ss2.attr_key as k2,\n" + + " MAX(ss2.created_at) as ca2\n" + + " FROM system_settings ss2\n" + + " GROUP BY ss2.attr_key\n" + + " ) AS t ON t.k2 = ss.attr_key AND t.ca2 = ss.created_at\n" + + " WHERE ss.type = 'SYSTEM' AND ss.active IS TRUE\n") +public class RuntimeConfiguration { + + @Id + private Long id; + + @Column(name = "attr_key") + private String key; + + @Column(name = "val") + private String value; + + @Column(name = "created_at") + private Instant createdAt; +} diff --git a/persistence-modules/hibernate-annotations/src/main/resources/migrations/V1__init.xml b/persistence-modules/hibernate-annotations/src/main/resources/migrations/V1__init.xml new file mode 100644 index 0000000000..5970821ccd --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/main/resources/migrations/V1__init.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + splitting.enabled + true + true + SYSTEM + + + + + 2 + splitting.enabled + false + false + SYSTEM + + + + + 3 + redelivery.enabled + false + true + ORDER + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-annotations/src/main/resources/migrations/master.xml b/persistence-modules/hibernate-annotations/src/main/resources/migrations/master.xml new file mode 100644 index 0000000000..ba16dc7b8b --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/main/resources/migrations/master.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/subselect/SubselectIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/subselect/SubselectIntegrationTest.java new file mode 100644 index 0000000000..074468ca37 --- /dev/null +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/subselect/SubselectIntegrationTest.java @@ -0,0 +1,65 @@ +package com.baeldung.hibernate.subselect; + +import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; +import jakarta.persistence.criteria.Root; +import liquibase.Contexts; +import liquibase.LabelExpression; +import liquibase.Liquibase; +import liquibase.database.DatabaseFactory; +import liquibase.database.jvm.JdbcConnection; +import liquibase.exception.LiquibaseException; +import liquibase.resource.ClassLoaderResourceAccessor; +import org.hibernate.Session; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class SubselectIntegrationTest { + + @BeforeAll + static void setUp() { + Session currentSession = HibernateAnnotationUtil.getSessionFactory().getCurrentSession(); + currentSession.beginTransaction(); + + currentSession.doWork(it -> { + Liquibase liquibase; + try { + liquibase = new Liquibase( + "migrations/master.xml", + new ClassLoaderResourceAccessor(), + DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(it)) + ); + liquibase.update(new Contexts(), new LabelExpression(),true); + } catch (LiquibaseException e) { + throw new RuntimeException(e); + } + }); + + currentSession.getTransaction().commit(); + } + + @Test + void givenEntityMarkedWithSubselect_whenSelectingRuntimeConfigByKey_thenSelectedSuccessfully() { + String key = "splitting.enabled"; + Session entityManager = HibernateAnnotationUtil.getSessionFactory().getCurrentSession(); + + entityManager.beginTransaction(); + + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + + CriteriaQuery query = criteriaBuilder.createQuery(RuntimeConfiguration.class); + + Root root = query.from(RuntimeConfiguration.class); + + RuntimeConfiguration configurationParameter = entityManager.createQuery( + query.select(root).where(criteriaBuilder.equal(root.get("key"), key)) + ).getSingleResult(); + + entityManager.getTransaction().commit(); + + Assertions.assertThat(configurationParameter.getValue()).isEqualTo("true"); + } +} + From 452cdc58c9e8bd42987d5f1e4feff9fa97533a6d Mon Sep 17 00:00:00 2001 From: MohamedHelmyKassab <137485958+MohamedHelmyKassab@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:18:39 +0200 Subject: [PATCH 32/51] This commit is related to BAEL-6972 (#16217) This commit aims to add two classes Child and Parent. --- .../com/baeldung/statementsbeforesuper/Child.java | 14 ++++++++++++++ .../com/baeldung/statementsbeforesuper/Parent.java | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Child.java create mode 100644 core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Parent.java diff --git a/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Child.java b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Child.java new file mode 100644 index 0000000000..6b8fda032c --- /dev/null +++ b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Child.java @@ -0,0 +1,14 @@ +package com.baeldung.statementsbeforesuper; + +class Child extends Parent { + Child() { + super(); // Or super(10); Correct placements + System.out.println("Child constructor"); + additionalInitialization(); + // super(); Compilation error: Constructor call must be the first statement in a constructor + } + + private void additionalInitialization() { + System.out.println("Additional initialization in Child"); + } +} diff --git a/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Parent.java b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Parent.java new file mode 100644 index 0000000000..38ed9ecd1a --- /dev/null +++ b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/statementsbeforesuper/Parent.java @@ -0,0 +1,11 @@ +package com.baeldung.statementsbeforesuper; + +public class Parent { + public Parent(int id) { + System.out.println("Parametrized Parent constructor"); + } + + public Parent() { + System.out.println("Parent constructor"); + } +} \ No newline at end of file From 76c1a02aa83d3a19b32d725d51a5affcb56aafba Mon Sep 17 00:00:00 2001 From: vunamtien Date: Tue, 26 Mar 2024 05:20:02 +0700 Subject: [PATCH 33/51] [JAVA-30997] upgrade spring-boot-mvc to boot 3 (#16190) * [JAVA-30997] upgrade spring-boot-mvc to boot 3 * [JAVA-30997] upgrade spring-boot-mvc to boot 3 --- spring-boot-modules/pom.xml | 2 +- spring-boot-modules/spring-boot-mvc/pom.xml | 12 +++++++----- .../components/AttrListener.java | 6 +++--- .../components/EchoServlet.java | 9 +++++---- .../components/HelloFilter.java | 7 ++++--- .../components/HelloServlet.java | 13 +++++++------ .../InternationalizationApp.java | 2 +- .../responseentity/CustomResponseController.java | 3 +-- .../restvalidation/config/MessageConfig.java | 3 +-- .../RecursiveLocaleContextMessageInterpolator.java | 3 +-- .../com/baeldung/restvalidation/service1/User.java | 3 +-- .../restvalidation/service1/UserService1.java | 3 +-- .../com/baeldung/restvalidation/service2/User.java | 3 +-- .../restvalidation/service2/UserService2.java | 3 +-- .../restvalidation/service3/FieldNotEmpty.java | 5 +++-- .../service3/FieldNotEmptyValidator.java | 4 ++-- .../restvalidation/service3/UserService3.java | 3 +-- .../src/main/java/com/baeldung/rss/RssFeedView.java | 5 ++--- .../MySQLAutoconfiguration.java | 2 +- .../com/baeldung/springbootmvc/LoginController.java | 3 +-- .../jsfapplication/JsfApplication.java | 3 +-- .../com/baeldung/springbootmvc/model/LoginForm.java | 6 +++--- .../main/resources/ValidationMessages.properties | 2 +- .../main/resources/ValidationMessages_zh.properties | 2 +- .../spring-boot-mvc/src/main/webapp/WEB-INF/web.xml | 2 +- ...ringBootWithServletComponentIntegrationTest.java | 5 ++--- ...gBootWithoutServletComponentIntegrationTest.java | 5 ++--- 27 files changed, 56 insertions(+), 63 deletions(-) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 00d6405cbf..2b62b3d1bc 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -56,7 +56,7 @@ spring-boot-process-automation spring-boot-logging-logback spring-boot-logging-log4j2 - + spring-boot-mvc spring-boot-mvc-2 spring-boot-mvc-3 spring-boot-mvc-4 diff --git a/spring-boot-modules/spring-boot-mvc/pom.xml b/spring-boot-modules/spring-boot-mvc/pom.xml index ab1c867d66..ec084df714 100644 --- a/spring-boot-modules/spring-boot-mvc/pom.xml +++ b/spring-boot-modules/spring-boot-mvc/pom.xml @@ -52,8 +52,8 @@ org.glassfish - javax.faces - ${javax.faces.version} + jakarta.faces + ${jakarta.faces.version} @@ -73,8 +73,9 @@ hibernate-validator - javax.validation - validation-api + jakarta.validation + jakarta.validation-api + ${jakarta.validation-api.version} org.springframework.boot @@ -112,8 +113,9 @@ 1.10.0 - 2.3.7 + 4.1.0-M1 1.9.20.1 + 3.1.0-M1 com.baeldung.springbootmvc.SpringBootMvcApplication diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/AttrListener.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/AttrListener.java index b1bdc7d781..049fcc986f 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/AttrListener.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/AttrListener.java @@ -1,8 +1,8 @@ package com.baeldung.annotation.servletcomponentscan.components; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.annotation.WebListener; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.annotation.WebListener; @WebListener public class AttrListener implements ServletContextListener { diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/EchoServlet.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/EchoServlet.java index d8192c2cb1..89b948ba87 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/EchoServlet.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/EchoServlet.java @@ -1,9 +1,10 @@ package com.baeldung.annotation.servletcomponentscan.components; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import java.io.File; import java.io.IOException; import java.nio.file.Files; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloFilter.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloFilter.java index 146e5ae386..f6472174a2 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloFilter.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloFilter.java @@ -1,8 +1,9 @@ package com.baeldung.annotation.servletcomponentscan.components; -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import javax.servlet.annotation.WebInitParam; +import jakarta.servlet.*; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.annotation.WebInitParam; + import java.io.IOException; @WebFilter(urlPatterns = "/hello", description = "a filter for hello servlet", initParams = { @WebInitParam(name = "msg", value = "filtering ") }, filterName = "hello filter", servletNames = { "echo servlet" }) diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloServlet.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloServlet.java index 5269c1bf29..8caa798e76 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloServlet.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/annotation/servletcomponentscan/components/HelloServlet.java @@ -1,11 +1,12 @@ package com.baeldung.annotation.servletcomponentscan.components; -import javax.servlet.ServletConfig; -import javax.servlet.annotation.WebInitParam; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import java.io.IOException; @WebServlet(urlPatterns = "/hello", initParams = { @WebInitParam(name = "msg", value = "hello") }) diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/internationalization/InternationalizationApp.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/internationalization/InternationalizationApp.java index c3af611f3b..2fdd79d060 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/internationalization/InternationalizationApp.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/internationalization/InternationalizationApp.java @@ -1,7 +1,7 @@ package com.baeldung.internationalization; -import javax.annotation.security.RolesAllowed; +import jakarta.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/responseentity/CustomResponseController.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/responseentity/CustomResponseController.java index 098c5e4794..19246e3014 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/responseentity/CustomResponseController.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/responseentity/CustomResponseController.java @@ -3,8 +3,7 @@ package com.baeldung.responseentity; import java.io.IOException; import java.time.Year; -import javax.servlet.http.HttpServletResponse; - +import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/MessageConfig.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/MessageConfig.java index e37e2c9d78..c0bfd641d4 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/MessageConfig.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/MessageConfig.java @@ -1,7 +1,6 @@ package com.baeldung.restvalidation.config; -import javax.validation.MessageInterpolator; - +import jakarta.validation.MessageInterpolator; import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/RecursiveLocaleContextMessageInterpolator.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/RecursiveLocaleContextMessageInterpolator.java index 003a3d79b0..a81c19148a 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/RecursiveLocaleContextMessageInterpolator.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/config/RecursiveLocaleContextMessageInterpolator.java @@ -4,8 +4,7 @@ import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.validation.MessageInterpolator; - +import jakarta.validation.MessageInterpolator; import org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator; import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/User.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/User.java index f9a7d1a9b5..eff81f6dda 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/User.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/User.java @@ -1,7 +1,6 @@ package com.baeldung.restvalidation.service1; -import javax.validation.constraints.NotEmpty; - +import jakarta.validation.constraints.NotEmpty; import lombok.*; @Data diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/UserService1.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/UserService1.java index 790b5031e6..6883e539f8 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/UserService1.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service1/UserService1.java @@ -1,5 +1,6 @@ package com.baeldung.restvalidation.service1; +import jakarta.validation.Valid; import org.springframework.http.*; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; @@ -7,8 +8,6 @@ import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.stream.Collectors; -import javax.validation.Valid; - import com.baeldung.restvalidation.response.InputFieldError; import com.baeldung.restvalidation.response.UpdateUserResponse; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/User.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/User.java index a2e567766c..dd9584e27b 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/User.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/User.java @@ -1,7 +1,6 @@ package com.baeldung.restvalidation.service2; -import javax.validation.constraints.NotEmpty; - +import jakarta.validation.constraints.NotEmpty; import lombok.*; @Data diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/UserService2.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/UserService2.java index 4593a2b1bd..78ec60720d 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/UserService2.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service2/UserService2.java @@ -3,8 +3,7 @@ package com.baeldung.restvalidation.service2; import java.util.List; import java.util.stream.Collectors; -import javax.validation.Valid; - +import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmpty.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmpty.java index 93c7052d5b..03392af45c 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmpty.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmpty.java @@ -1,5 +1,8 @@ package com.baeldung.restvalidation.service3; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.CONSTRUCTOR; import static java.lang.annotation.ElementType.FIELD; @@ -12,8 +15,6 @@ import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import javax.validation.Constraint; -import javax.validation.Payload; @Documented @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmptyValidator.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmptyValidator.java index 356efc590b..5d4b188911 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmptyValidator.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/FieldNotEmptyValidator.java @@ -1,7 +1,7 @@ package com.baeldung.restvalidation.service3; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; public class FieldNotEmptyValidator implements ConstraintValidator { diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/UserService3.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/UserService3.java index e506b63d8e..3efb88c29d 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/UserService3.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/restvalidation/service3/UserService3.java @@ -3,8 +3,7 @@ package com.baeldung.restvalidation.service3; import java.util.List; import java.util.stream.Collectors; -import javax.validation.Valid; - +import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedView.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedView.java index c9b9c51bec..8cfb9b9931 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedView.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/rss/RssFeedView.java @@ -6,9 +6,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Component; import org.springframework.web.servlet.view.feed.AbstractRssFeedView; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootannotations/MySQLAutoconfiguration.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootannotations/MySQLAutoconfiguration.java index 62b1329a54..d3d3cb44d5 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootannotations/MySQLAutoconfiguration.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootannotations/MySQLAutoconfiguration.java @@ -3,9 +3,9 @@ package com.baeldung.springbootannotations; import java.util.Arrays; import java.util.Properties; -import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; +import jakarta.persistence.EntityManagerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.condition.ConditionMessage; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/LoginController.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/LoginController.java index 589024c0bc..190e882781 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/LoginController.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/LoginController.java @@ -1,7 +1,6 @@ package com.baeldung.springbootmvc; -import javax.validation.Valid; - +import jakarta.validation.Valid; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/jsfapplication/JsfApplication.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/jsfapplication/JsfApplication.java index 5b4250d5e3..86265b0b4d 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/jsfapplication/JsfApplication.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/jsfapplication/JsfApplication.java @@ -1,7 +1,6 @@ package com.baeldung.springbootmvc.jsfapplication; -import javax.faces.webapp.FacesServlet; - +import jakarta.faces.webapp.FacesServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletRegistrationBean; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/model/LoginForm.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/model/LoginForm.java index 107cd1bbf1..274265e97b 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/model/LoginForm.java +++ b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/model/LoginForm.java @@ -1,8 +1,8 @@ package com.baeldung.springbootmvc.model; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; public class LoginForm { diff --git a/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages.properties b/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages.properties index 90d3c88a8f..f8e1a6a434 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages.properties +++ b/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages.properties @@ -1 +1 @@ -javax.validation.constraints.NotEmpty.message=The field cannot be empty \ No newline at end of file +jakarta.validation.constraints.NotEmpty.message=The field cannot be empty \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages_zh.properties b/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages_zh.properties index 04f415911c..5c7bfbcb36 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages_zh.properties +++ b/spring-boot-modules/spring-boot-mvc/src/main/resources/ValidationMessages_zh.properties @@ -1 +1 @@ -javax.validation.constraints.NotEmpty.message=本欄不能留空 \ No newline at end of file +jakarta.validation.constraints.NotEmpty.message=本欄不能留空 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc/src/main/webapp/WEB-INF/web.xml b/spring-boot-modules/spring-boot-mvc/src/main/webapp/WEB-INF/web.xml index e0cd4d8850..45d30565fe 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/webapp/WEB-INF/web.xml +++ b/spring-boot-modules/spring-boot-mvc/src/main/webapp/WEB-INF/web.xml @@ -7,7 +7,7 @@ Faces Servlet - javax.faces.webapp.FacesServlet + jakarta.faces.webapp.FacesServlet 1 diff --git a/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java b/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java index 92223892d9..230fe200e6 100644 --- a/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java +++ b/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java @@ -4,9 +4,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import javax.servlet.FilterRegistration; -import javax.servlet.ServletContext; - +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.ServletContext; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java b/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java index c29cd75e9d..0d413be91e 100644 --- a/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java +++ b/spring-boot-modules/spring-boot-mvc/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java @@ -4,9 +4,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import javax.servlet.FilterRegistration; -import javax.servlet.ServletContext; - +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.ServletContext; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; From 6776be43283bb56822d321cc6552aff47ca2c60e Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:31:11 +0200 Subject: [PATCH 34/51] [JAVA-32463] Move Dozer module to libraries-data-3 (#16227) --- dozer/README.md | 7 ---- dozer/pom.xml | 32 ------------------- dozer/src/main/resources/logback.xml | 13 -------- libraries-data-3/README.md | 1 + libraries-data-3/pom.xml | 12 +++++++ .../main/java/com/baeldung/dozer/Dest.java | 0 .../main/java/com/baeldung/dozer/Dest2.java | 0 .../com/baeldung/dozer/MyCustomConvertor.java | 0 .../main/java/com/baeldung/dozer/Person.java | 0 .../main/java/com/baeldung/dozer/Person2.java | 0 .../main/java/com/baeldung/dozer/Person3.java | 0 .../java/com/baeldung/dozer/Personne.java | 0 .../java/com/baeldung/dozer/Personne2.java | 0 .../java/com/baeldung/dozer/Personne3.java | 0 .../main/java/com/baeldung/dozer/Source.java | 0 .../main/java/com/baeldung/dozer/Source2.java | 0 .../baeldung/dozer/DozerIntegrationTest.java | 4 +-- .../test/resources/dozer_custom_convertor.xml | 0 .../src/test/resources/dozer_mapping.xml | 0 .../src/test/resources/dozer_mapping2.xml | 0 pom.xml | 2 -- 21 files changed, 15 insertions(+), 56 deletions(-) delete mode 100644 dozer/README.md delete mode 100644 dozer/pom.xml delete mode 100644 dozer/src/main/resources/logback.xml rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Dest.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Dest2.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/MyCustomConvertor.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Person.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Person2.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Person3.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Personne.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Personne2.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Personne3.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Source.java (100%) rename {dozer => libraries-data-3}/src/main/java/com/baeldung/dozer/Source2.java (100%) rename {dozer => libraries-data-3}/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java (98%) rename {dozer => libraries-data-3}/src/test/resources/dozer_custom_convertor.xml (100%) rename {dozer => libraries-data-3}/src/test/resources/dozer_mapping.xml (100%) rename {dozer => libraries-data-3}/src/test/resources/dozer_mapping2.xml (100%) diff --git a/dozer/README.md b/dozer/README.md deleted file mode 100644 index e87e889ce3..0000000000 --- a/dozer/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Dozer - -This module contains articles about Dozer - -### Relevant Articles: - -- [A Guide to Mapping With Dozer](https://www.baeldung.com/dozer) diff --git a/dozer/pom.xml b/dozer/pom.xml deleted file mode 100644 index 66f4ee8227..0000000000 --- a/dozer/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - 4.0.0 - dozer - dozer - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - net.sf.dozer - dozer - ${dozer.version} - - - - - 5.5.1 - - - \ No newline at end of file diff --git a/dozer/src/main/resources/logback.xml b/dozer/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/dozer/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/libraries-data-3/README.md b/libraries-data-3/README.md index e6f02bf2aa..3a68734fd1 100644 --- a/libraries-data-3/README.md +++ b/libraries-data-3/README.md @@ -12,4 +12,5 @@ This module contains articles about libraries for data processing in Java. - [Introduction to Eclipse Collections](https://www.baeldung.com/eclipse-collections) - [Introduction to Caffeine](https://www.baeldung.com/java-caching-caffeine) - [Guide to Using ModelMapper](https://www.baeldung.com/java-modelmapper) +- [A Guide to Mapping With Dozer](https://www.baeldung.com/dozer) - More articles: [[<-- prev]](/../libraries-data-2) diff --git a/libraries-data-3/pom.xml b/libraries-data-3/pom.xml index 536939d435..35da822e7c 100644 --- a/libraries-data-3/pom.xml +++ b/libraries-data-3/pom.xml @@ -71,6 +71,17 @@ modelmapper ${org.modelmapper.version} + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + net.sf.dozer + dozer + ${dozer.version} + + @@ -96,6 +107,7 @@ 3.1.8 3.0.2 3.2.0 + 5.5.1 diff --git a/dozer/src/main/java/com/baeldung/dozer/Dest.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Dest.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Dest.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Dest.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Dest2.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Dest2.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Dest2.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Dest2.java diff --git a/dozer/src/main/java/com/baeldung/dozer/MyCustomConvertor.java b/libraries-data-3/src/main/java/com/baeldung/dozer/MyCustomConvertor.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/MyCustomConvertor.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/MyCustomConvertor.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Person.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Person.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Person.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Person.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Person2.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Person2.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Person2.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Person2.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Person3.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Person3.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Person3.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Person3.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Personne.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Personne.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Personne.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Personne.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Personne2.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Personne2.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Personne2.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Personne2.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Personne3.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Personne3.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Personne3.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Personne3.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Source.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Source.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Source.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Source.java diff --git a/dozer/src/main/java/com/baeldung/dozer/Source2.java b/libraries-data-3/src/main/java/com/baeldung/dozer/Source2.java similarity index 100% rename from dozer/src/main/java/com/baeldung/dozer/Source2.java rename to libraries-data-3/src/main/java/com/baeldung/dozer/Source2.java diff --git a/dozer/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java b/libraries-data-3/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java similarity index 98% rename from dozer/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java rename to libraries-data-3/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java index 591189bca9..48ec5fc5e4 100644 --- a/dozer/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java +++ b/libraries-data-3/src/test/java/com/baeldung/dozer/DozerIntegrationTest.java @@ -171,7 +171,7 @@ public class DozerIntegrationTest { configureMapper("dozer_custom_convertor.xml"); String dateTime = "2007-06-26T21:22:39Z"; - long timestamp = new Long("1182882159000"); + long timestamp = Long.parseLong("1182882159000"); Person3 person = new Person3("Rich", dateTime); Personne3 person0 = mapper.map(person, Personne3.class); @@ -182,7 +182,7 @@ public class DozerIntegrationTest { @Test public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvertBidirectionally_thenCorrect() { - long timestamp = new Long("1182882159000"); + long timestamp = Long.parseLong("1182882159000"); Personne3 person = new Personne3("Rich", timestamp); configureMapper("dozer_custom_convertor.xml"); diff --git a/dozer/src/test/resources/dozer_custom_convertor.xml b/libraries-data-3/src/test/resources/dozer_custom_convertor.xml similarity index 100% rename from dozer/src/test/resources/dozer_custom_convertor.xml rename to libraries-data-3/src/test/resources/dozer_custom_convertor.xml diff --git a/dozer/src/test/resources/dozer_mapping.xml b/libraries-data-3/src/test/resources/dozer_mapping.xml similarity index 100% rename from dozer/src/test/resources/dozer_mapping.xml rename to libraries-data-3/src/test/resources/dozer_mapping.xml diff --git a/dozer/src/test/resources/dozer_mapping2.xml b/libraries-data-3/src/test/resources/dozer_mapping2.xml similarity index 100% rename from dozer/src/test/resources/dozer_mapping2.xml rename to libraries-data-3/src/test/resources/dozer_mapping2.xml diff --git a/pom.xml b/pom.xml index a9b80de9c4..c56d7d4c13 100644 --- a/pom.xml +++ b/pom.xml @@ -683,7 +683,6 @@ di-modules disruptor docker-modules - dozer drools dubbo feign @@ -931,7 +930,6 @@ di-modules disruptor docker-modules - dozer drools dubbo feign From 82120f03d7807e44716e46d08e670c167926add0 Mon Sep 17 00:00:00 2001 From: vunamtien Date: Tue, 26 Mar 2024 05:43:41 +0700 Subject: [PATCH 35/51] [JAVA-26659] Upgrade jacoco-maven-plugin (#16223) --- core-java-modules/core-java-reflection-2/pom.xml | 3 ++- core-java-modules/core-java-reflection-3/pom.xml | 3 ++- jhipster-6/bookstore-monolith/pom.xml | 2 +- jhipster-modules/jhipster-microservice/car-app/pom.xml | 2 +- jhipster-modules/jhipster-microservice/dealer-app/pom.xml | 2 +- jhipster-modules/jhipster-microservice/gateway-app/pom.xml | 2 +- jhipster-modules/jhipster-monolithic/pom.xml | 2 +- maven-modules/jacoco-coverage-aggregation/pom.xml | 2 +- spring-boot-modules/spring-boot-ci-cd/pom.xml | 2 +- testing-modules/testing-libraries-2/pom.xml | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-reflection-2/pom.xml b/core-java-modules/core-java-reflection-2/pom.xml index 69cf4f5f37..41d2b0a7ae 100644 --- a/core-java-modules/core-java-reflection-2/pom.xml +++ b/core-java-modules/core-java-reflection-2/pom.xml @@ -49,7 +49,7 @@ org.jacoco jacoco-maven-plugin - 0.8.8 + ${jacoco-maven-plugin.version} @@ -73,6 +73,7 @@ 1.8 1.8 5.3.4 + 0.8.11 \ No newline at end of file diff --git a/core-java-modules/core-java-reflection-3/pom.xml b/core-java-modules/core-java-reflection-3/pom.xml index e4111b8dda..61bc424336 100644 --- a/core-java-modules/core-java-reflection-3/pom.xml +++ b/core-java-modules/core-java-reflection-3/pom.xml @@ -49,7 +49,7 @@ org.jacoco jacoco-maven-plugin - 0.8.8 + ${jacoco-maven-plugin.version} @@ -73,6 +73,7 @@ 1.8 1.8 5.3.4 + 0.8.11 \ No newline at end of file diff --git a/jhipster-6/bookstore-monolith/pom.xml b/jhipster-6/bookstore-monolith/pom.xml index 97bfbe7550..a4f334fc1c 100644 --- a/jhipster-6/bookstore-monolith/pom.xml +++ b/jhipster-6/bookstore-monolith/pom.xml @@ -1168,7 +1168,7 @@ 3.2.2 0.9.11 1.7.6 - 0.8.2 + 0.8.11 1.0.0 3.4.2 3.5.0.1254 diff --git a/jhipster-modules/jhipster-microservice/car-app/pom.xml b/jhipster-modules/jhipster-microservice/car-app/pom.xml index 069a1f6848..2fee5148a0 100644 --- a/jhipster-modules/jhipster-microservice/car-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/car-app/pom.xml @@ -24,7 +24,7 @@ 1.2 5.2.8.Final 5.1.0 - 0.7.9 + 0.8.11 1.8 3.21.0-GA 1.0.0 diff --git a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml index 43f9b046c7..509651e209 100644 --- a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml @@ -24,7 +24,7 @@ 1.2 5.2.8.Final 5.1.0 - 0.7.9 + 0.8.11 3.21.0-GA 1.0.0 1.1.0 diff --git a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml index 90d703b8c7..0e80a02e2e 100644 --- a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml @@ -27,7 +27,7 @@ 1.2 5.2.8.Final 5.1.0 - 0.7.9 + 0.8.11 3.21.0-GA 1.0.0 1.1.0 diff --git a/jhipster-modules/jhipster-monolithic/pom.xml b/jhipster-modules/jhipster-monolithic/pom.xml index f1ee479756..6b06ba2e8b 100644 --- a/jhipster-modules/jhipster-monolithic/pom.xml +++ b/jhipster-modules/jhipster-monolithic/pom.xml @@ -893,7 +893,7 @@ 2.2.3 5.2.8.Final 5.1.0 - 0.7.9 + 0.8.11 3.21.0-GA 1.0.0 1.1.0 diff --git a/maven-modules/jacoco-coverage-aggregation/pom.xml b/maven-modules/jacoco-coverage-aggregation/pom.xml index bc70c60b50..274a19c723 100644 --- a/maven-modules/jacoco-coverage-aggregation/pom.xml +++ b/maven-modules/jacoco-coverage-aggregation/pom.xml @@ -38,7 +38,7 @@ - 0.8.8 + 0.8.11 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ci-cd/pom.xml b/spring-boot-modules/spring-boot-ci-cd/pom.xml index 6e58f1162d..51adb6bc1b 100644 --- a/spring-boot-modules/spring-boot-ci-cd/pom.xml +++ b/spring-boot-modules/spring-boot-ci-cd/pom.xml @@ -105,7 +105,7 @@ - 0.8.5 + 0.8.11 3.0.2 2.2.0 diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index 717ccac2b2..075e26aefa 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -166,7 +166,7 @@ - 0.8.6 + 0.8.11 1.19.0 1.0.0 2.1.3 From c25f863bb23d6a21bffe08bd52400f4646ea9a6a Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Tue, 26 Mar 2024 21:01:32 +0200 Subject: [PATCH 36/51] JAVA-32055 Upgrade spring-mvc-forms-thymeleaf to Spring Boot 3 (#16203) Co-authored-by: timis1 --- spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml | 5 ++--- .../baeldung/multipartupload/EmployeeController.java | 11 +++++------ .../TodoControllerWithSessionAttributes.java | 2 +- .../main/java/com/baeldung/sessionattrs/TodoList.java | 1 - .../EmployeeControllerIntegrationTest.java | 5 +---- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml index 9c9d6804ae..d5a2cf00f4 100644 --- a/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -43,7 +43,6 @@ - 3.0.9.RELEASE com.baeldung.sessionattrs.SessionAttrsApplication diff --git a/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/multipartupload/EmployeeController.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/multipartupload/EmployeeController.java index e02844233e..5069f1739c 100644 --- a/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/multipartupload/EmployeeController.java +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/multipartupload/EmployeeController.java @@ -1,18 +1,17 @@ package com.baeldung.multipartupload; -import lombok.AllArgsConstructor; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; -import static org.springframework.web.bind.annotation.RequestMethod.POST; +import lombok.AllArgsConstructor; @Controller @AllArgsConstructor @@ -26,20 +25,20 @@ public class EmployeeController { return "employee/createEmployeeForm"; } - @RequestMapping(path = "/employee", method = POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) + @PostMapping(path = "/employee", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) public String saveEmployee(@ModelAttribute Employee employee) { employeeService.save(employee); return "employee/success"; } - @RequestMapping(path = "/requestpart/employee", method = POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) + @PostMapping(path = "/requestpart/employee", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) public ResponseEntity saveEmployee(@RequestPart Employee employee, @RequestPart MultipartFile document) { employee.setDocument(document); employeeService.save(employee); return ResponseEntity.ok().build(); } - @RequestMapping(path = "/requestparam/employee", method = POST, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) + @PostMapping(path = "/requestparam/employee", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) public ResponseEntity saveEmployee(@RequestParam String name, @RequestPart MultipartFile document) { Employee employee = new Employee(name, document); employeeService.save(employee); diff --git a/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java index 99e0b46fc2..e8c3b30265 100644 --- a/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoControllerWithSessionAttributes.java @@ -13,7 +13,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; @Controller -@RequestMapping("/sessionattributes") +@RequestMapping(value = "/sessionattributes") @SessionAttributes("todos") public class TodoControllerWithSessionAttributes { diff --git a/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java index 02c05f4282..cf2aba6280 100644 --- a/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/sessionattrs/TodoList.java @@ -2,7 +2,6 @@ package com.baeldung.sessionattrs; import java.util.ArrayDeque; -@SuppressWarnings("serial") public class TodoList extends ArrayDeque{ } diff --git a/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/multipartupload/EmployeeControllerIntegrationTest.java b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/multipartupload/EmployeeControllerIntegrationTest.java index 73cf905a34..f70cb21102 100644 --- a/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/multipartupload/EmployeeControllerIntegrationTest.java +++ b/spring-web-modules/spring-mvc-forms-thymeleaf/src/test/java/com/baeldung/multipartupload/EmployeeControllerIntegrationTest.java @@ -1,8 +1,6 @@ package com.baeldung.multipartupload; import org.junit.jupiter.api.Test; -import org.mockito.BDDMockito; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -10,7 +8,6 @@ import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import static org.apache.http.entity.ContentType.DEFAULT_BINARY; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -18,7 +15,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @EnableWebMvc public class EmployeeControllerIntegrationTest { - private static final MockMultipartFile A_FILE = new MockMultipartFile("document", null, DEFAULT_BINARY.toString(), "Employee Record".getBytes()); + private static final MockMultipartFile A_FILE = new MockMultipartFile("document", null, "application/octet-stream", "Employee Record".getBytes()); @Autowired private MockMvc mockMvc; From c957410b7eabc54a8f19412b0da476cc78b3c132 Mon Sep 17 00:00:00 2001 From: Wynn Teo <49014791+wynnteo@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:19:44 +0800 Subject: [PATCH 37/51] Bael 7648 (#16176) * BAEL-7490 read write file in separate thread * Change the to try resources * Update the code to sync with article * added new module for get list entity in hibernate * Move the code to hibernate-queries module * simplify the code --- .../listentity/entity/Department.java | 40 +++++++++ .../hibernate/listentity/entity/Employee.java | 41 +++++++++ .../listentity/service/EmployeeService.java | 88 +++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Department.java create mode 100644 persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Employee.java create mode 100644 persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/service/EmployeeService.java diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Department.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Department.java new file mode 100644 index 0000000000..62a31dd344 --- /dev/null +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Department.java @@ -0,0 +1,40 @@ +package com.baeldung.hibernate.listentity.entity; + +import java.util.List; +import jakarta.persistence.*; + +@Entity +public class Department { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + @OneToMany(mappedBy = "department", fetch = FetchType.EAGER) + private List employees; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } +} diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Employee.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Employee.java new file mode 100644 index 0000000000..6b4b0c56b1 --- /dev/null +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/entity/Employee.java @@ -0,0 +1,41 @@ +package com.baeldung.hibernate.listentity.entity; + +import jakarta.persistence.*; + +@Entity +@NamedQuery(name = "findAllEmployees", query = "SELECT e FROM Employee e") +@NamedQuery(name = "findEmployeesByDepartment", query = "SELECT e FROM Employee e WHERE e.department = :department ORDER BY e.lastName ASC") +public class Employee { + + @Id + @GeneratedValue + private Long id; + + private String lastName; + + private String department; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } +} diff --git a/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/service/EmployeeService.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/service/EmployeeService.java new file mode 100644 index 0000000000..b336fb1691 --- /dev/null +++ b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/listentity/service/EmployeeService.java @@ -0,0 +1,88 @@ +package com.baeldung.hibernate.listentity.service; + +import java.util.Collections; +import java.util.List; + +import jakarta.persistence.*; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Path; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; + +import org.springframework.stereotype.Service; + +import com.baeldung.hibernate.listentity.entity.Department; +import com.baeldung.hibernate.listentity.entity.Employee; + +@Service +public class EmployeeService { + + @PersistenceContext + private EntityManager entityManager; + + public List getAllEmployeesUsingJPQL() { + String jpqlQuery = "SELECT e FROM Employee e"; + Query query = entityManager.createQuery(jpqlQuery, Employee.class); + return query.getResultList(); + } + + public List getAllEmployeesByDepartmentUsingJPQL() { + String jpqlQuery = "SELECT e FROM Employee e WHERE e.department = 'Engineering' ORDER BY e.lastName ASC"; + Query query = entityManager.createQuery(jpqlQuery, Employee.class); + + return query.getResultList(); + } + + public List getAllEmployeesUsingNamedQuery() { + Query query = entityManager.createNamedQuery("findAllEmployees", Employee.class); + + return query.getResultList(); + } + + public List getAllEmployeesByDepartmentUsingNamedQuery(String department) { + Query query = entityManager.createNamedQuery("findEmployeesByDepartment", Employee.class); + query.setParameter("department", department); + + return query.getResultList(); + } + + public List getAllEmployeesUsingCriteriaAPI() { + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Employee.class); + Root employeeRoot = criteriaQuery.from(Employee.class); + + criteriaQuery.select(employeeRoot); + Query query = entityManager.createQuery(criteriaQuery); + + return query.getResultList(); + } + + public List getAllEmployeesByDepartmentUsingCriteriaAPI(String department) { + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Employee.class); + Root employeeRoot = criteriaQuery.from(Employee.class); + Predicate departmentPredicate = criteriaBuilder.equal(employeeRoot.get("department"), department); + Path sortByPath = employeeRoot.get("lastName"); + criteriaQuery.orderBy(criteriaBuilder.asc(sortByPath)); + criteriaQuery.select(employeeRoot) + .where(departmentPredicate); + Query query = entityManager.createQuery(criteriaQuery); + + return query.getResultList(); + } + + public List getAllEmployeesByDepartmentUsingOneToManyAnnotations(String departmentName) { + try { + // Retrieve the department by its name + Department department = entityManager.createQuery("SELECT d FROM Department d WHERE d.name = :name", Department.class) + .setParameter("name", departmentName) + .getSingleResult(); + + // Return the list of employees associated with the department + return department.getEmployees(); + } catch (NoResultException e) { + return Collections.emptyList(); + } + } +} From 57613dec3da11d5fe6690526e54ae1d70fc613e1 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:57:41 +0800 Subject: [PATCH 38/51] Update README.md --- json-modules/json-conversion/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/json-modules/json-conversion/README.md b/json-modules/json-conversion/README.md index bfcadfe1f5..f2f6ec7d28 100644 --- a/json-modules/json-conversion/README.md +++ b/json-modules/json-conversion/README.md @@ -8,3 +8,4 @@ This module contains articles about JSON Conversions - [Convert Byte Array to JSON and Vice Versa in Java](https://www.baeldung.com/java-json-byte-array-conversion) - [Preventing Gson from Expressing Integers as Floats](https://www.baeldung.com/java-gson-prevent-expressing-integers-as-floats) - [Simplified Array Operations on JsonNode Without Typecasting in Jackson](https://www.baeldung.com/java-jsonnode-persistence-simplified-array-operations) +- [How to Convert Excel to JSON in Java](https://www.baeldung.com/java-excel-json-conversion) From e84bf3717a769ded194f4835c72a2be8fac23ff3 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:59:25 +0800 Subject: [PATCH 39/51] Update README.md --- xml-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xml-2/README.md b/xml-2/README.md index 1075f34e1f..6040137dc1 100644 --- a/xml-2/README.md +++ b/xml-2/README.md @@ -11,4 +11,5 @@ This module contains articles about eXtensible Markup Language (XML) - [Convert String Containing XML to org.w3c.dom.Document](https://www.baeldung.com/java-convert-string-xml-dom) - [How to Parse XML to HashMap in Java](https://www.baeldung.com/java-xml-read-into-hashmap) - [Convert an XML File to CSV File](https://www.baeldung.com/java-convert-xml-csv) -- - More articles: [[prev -->]](../xml) \ No newline at end of file +- [Invalid Characters in XML](https://www.baeldung.com/java-xml-invalid-characters) +- - More articles: [[prev -->]](../xml) From 3b44d659c505fd9bd2d61463f767cab44c975d41 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:01:08 +0800 Subject: [PATCH 40/51] Update README.md --- spring-security-modules/spring-security-core-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-modules/spring-security-core-2/README.md b/spring-security-modules/spring-security-core-2/README.md index 922c473b75..069861ca9b 100644 --- a/spring-security-modules/spring-security-core-2/README.md +++ b/spring-security-modules/spring-security-core-2/README.md @@ -11,6 +11,7 @@ This module contains articles about core Spring Security - [HttpSecurity vs. WebSecurity in Spring Security](https://www.baeldung.com/spring-security-httpsecurity-vs-websecurity) - [Migrate Application from Spring Security 5 to Spring Security 6/Spring Boot 3](https://www.baeldung.com/spring-security-migrate-5-to-6) - [Spring Security AuthorizationManager](https://www.baeldung.com/spring-security-authorizationmanager) +- [Creating a Spring Security Key for Signing a JWT Token](https://www.baeldung.com/spring-security-sign-jwt-token) ### Build the Project From d1ca5d3866a9d0cbd06c37d27ea3d11d1db2b1bb Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:03:34 +0800 Subject: [PATCH 41/51] Update README.md --- spring-di-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-di-4/README.md b/spring-di-4/README.md index bed8b5a78d..7301339d33 100644 --- a/spring-di-4/README.md +++ b/spring-di-4/README.md @@ -8,4 +8,5 @@ This module contains articles about dependency injection with Spring - [Spring @Component Annotation](https://www.baeldung.com/spring-component-annotation) - [Why Is Field Injection Not Recommended?](https://www.baeldung.com/java-spring-field-injection-cons) - [Setting a Spring Bean to Null](https://www.baeldung.com/spring-setting-bean-null) +- [Dynamically Register Spring Beans Based on Properties](https://www.baeldung.com/spring-beans-dynamic-registration-properties) - More articles: [[<-- prev]](../spring-di-3) From dede5abc9714bea11c6b8284a574a3807723cd39 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:10:31 +0800 Subject: [PATCH 42/51] Update README.md --- core-java-modules/core-java-collections-list-6/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-list-6/README.md b/core-java-modules/core-java-collections-list-6/README.md index 8a8ed181c6..c66a611caf 100644 --- a/core-java-modules/core-java-collections-list-6/README.md +++ b/core-java-modules/core-java-collections-list-6/README.md @@ -5,3 +5,4 @@ - [Sorting One List Based on Another List in Java](https://www.baeldung.com/java-sorting-one-list-using-another) - [Reset ListIterator to First Element of the List in Java](https://www.baeldung.com/java-reset-listiterator) - [Modify and Print List Items With Java Streams](https://www.baeldung.com/java-stream-list-update-print-elements) +- [Add One Element to an Immutable List in Java](https://www.baeldung.com/java-immutable-list-add-element) From 8da755ff7a2a7e8c5a666e1b26d150aa249fef5c Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:12:36 +0800 Subject: [PATCH 43/51] Update README.md --- core-java-modules/core-java-streams-maps/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-streams-maps/README.md b/core-java-modules/core-java-streams-maps/README.md index 8f311d91a5..0f6796f262 100644 --- a/core-java-modules/core-java-streams-maps/README.md +++ b/core-java-modules/core-java-streams-maps/README.md @@ -1,3 +1,4 @@ ## Relevant Articles: - [Handle Duplicate Keys When Producing Map Using Java Stream](https://www.baeldung.com/java-duplicate-keys-when-producing-map-using-stream) -- [Convert a Stream into a Map or Multimap in Java](https://www.baeldung.com/java-convert-stream-map-multimap) \ No newline at end of file +- [Convert a Stream into a Map or Multimap in Java](https://www.baeldung.com/java-convert-stream-map-multimap) +- [Flatten a Stream of Maps to a Single Map in Java](https://www.baeldung.com/java-flatten-stream-map) From ee28b0f7e75408af68d1725ea22045aea81b7f07 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:15:28 +0800 Subject: [PATCH 44/51] Update README.md --- persistence-modules/liquibase/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/liquibase/README.md b/persistence-modules/liquibase/README.md index 0e5bfcb8a6..4b68b8b995 100644 --- a/persistence-modules/liquibase/README.md +++ b/persistence-modules/liquibase/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Introduction to Liquibase Rollback](http://www.baeldung.com/liquibase-rollback) +- [Creating PostgreSQL Schema Before Liquibase Execution](https://www.baeldung.com/java-postgresql-create-schema-before-liquibase) From 68047700d86fdda68acc1260833f1eb61113c7eb Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:18:35 +0800 Subject: [PATCH 45/51] Create README.md --- algorithms-modules/algorithms-miscellaneous-8/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 algorithms-modules/algorithms-miscellaneous-8/README.md diff --git a/algorithms-modules/algorithms-miscellaneous-8/README.md b/algorithms-modules/algorithms-miscellaneous-8/README.md new file mode 100644 index 0000000000..c3d689fa13 --- /dev/null +++ b/algorithms-modules/algorithms-miscellaneous-8/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Vigenère Cipher in Java](https://www.baeldung.com/java-vigenere-cipher) From 5792231765c5d57a292c3c03682a1b505be76313 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:20:22 +0800 Subject: [PATCH 46/51] Update README.md --- core-java-modules/core-java-io-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-io-5/README.md b/core-java-modules/core-java-io-5/README.md index fb050ab2d2..d596a7a3a7 100644 --- a/core-java-modules/core-java-io-5/README.md +++ b/core-java-modules/core-java-io-5/README.md @@ -10,5 +10,6 @@ This module contains articles about core Java input and output (IO) - [Read a File and Split It Into Multiple Files in Java](https://www.baeldung.com/java-read-file-split-into-several) - [Read and Write Files in Java Using Separate Threads](https://www.baeldung.com/java-read-write-files-different-threads) - [Convert an OutputStream to a Byte Array in Java](https://www.baeldung.com/java-outputstream-byte-array) +- [Reading a .gz File Line by Line Using GZIPInputStream](https://www.baeldung.com/java-gzipinputstream-read-gz-file-line-by-line) - [[<-- Prev]](/core-java-modules/core-java-io-4) From 8cb77a1a886269e0f2ff810bac71028f532daa73 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:23:41 +0800 Subject: [PATCH 47/51] Update README.md --- core-java-modules/core-java-string-operations-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-string-operations-8/README.md b/core-java-modules/core-java-string-operations-8/README.md index 22407a5961..6765aa9461 100644 --- a/core-java-modules/core-java-string-operations-8/README.md +++ b/core-java-modules/core-java-string-operations-8/README.md @@ -6,3 +6,4 @@ - [Get First n Characters in a String in Java](https://www.baeldung.com/get-first-n-characters-in-a-string-in-java) - [Remove Only Trailing Spaces or Whitespace From a String in Java](https://www.baeldung.com/java-string-remove-only-trailing-whitespace) - [Get the Initials of a Name in Java](https://www.baeldung.com/java-shorten-name-initials) +- [Normalizing the EOL Character in Java](https://www.baeldung.com/java-normalize-end-of-line-character) From dd622e250d19b2a83c26f592cca4a089fd5dc7c6 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:26:12 +0800 Subject: [PATCH 48/51] Update README.md --- core-java-modules/core-java-string-operations-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-string-operations-8/README.md b/core-java-modules/core-java-string-operations-8/README.md index 6765aa9461..2515e07be4 100644 --- a/core-java-modules/core-java-string-operations-8/README.md +++ b/core-java-modules/core-java-string-operations-8/README.md @@ -7,3 +7,4 @@ - [Remove Only Trailing Spaces or Whitespace From a String in Java](https://www.baeldung.com/java-string-remove-only-trailing-whitespace) - [Get the Initials of a Name in Java](https://www.baeldung.com/java-shorten-name-initials) - [Normalizing the EOL Character in Java](https://www.baeldung.com/java-normalize-end-of-line-character) +- [Converting UTF-8 to ISO-8859-1 in Java](https://www.baeldung.com/java-utf-8-iso-8859-1-conversion) From cfcbac873c6434f1bbf6644c8ad07ed08eb34ef9 Mon Sep 17 00:00:00 2001 From: rcalago <149600319+rcalago@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:28:57 +0800 Subject: [PATCH 49/51] Update README.md --- core-java-modules/core-java-lang-oop-constructors-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-lang-oop-constructors-2/README.md b/core-java-modules/core-java-lang-oop-constructors-2/README.md index d9b162c7a6..1357dfc1c5 100644 --- a/core-java-modules/core-java-lang-oop-constructors-2/README.md +++ b/core-java-modules/core-java-lang-oop-constructors-2/README.md @@ -4,4 +4,5 @@ This module contains article about constructors in Java ### Relevant Articles: - [Different Ways to Create an Object in Java](https://www.baeldung.com/java-different-ways-to-create-objects) -- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-oop-constructors) \ No newline at end of file +- [When to Use Setter Methods or Constructors for Setting a Variable’s Value in Java](https://www.baeldung.com/java-setter-method-vs-constructor) +- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-oop-constructors) From 2a7b672000333c29ec4752f12908837a8e9d3bbc Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:54:57 +0200 Subject: [PATCH 50/51] JAVA-32052 Upgrade spring-5-mvc to Spring Boot 3 (#16212) --- spring-web-modules/spring-5-mvc/pom.xml | 18 +++--------------- .../java/com/baeldung/idc/BookRepository.java | 2 +- .../src/main/java/com/baeldung/model/Foo.java | 8 ++++---- .../java/com/baeldung/web/FooController.java | 4 ++-- .../web/ResponseBodyEmitterController.java | 4 ++-- .../com/baeldung/web/SseEmitterController.java | 2 +- .../web/StreamingResponseBodyController.java | 2 +- .../src/test/java/com/baeldung/LiveTest.java | 8 +++----- 8 files changed, 17 insertions(+), 31 deletions(-) diff --git a/spring-web-modules/spring-5-mvc/pom.xml b/spring-web-modules/spring-5-mvc/pom.xml index 23bcb00801..ca5698462f 100644 --- a/spring-web-modules/spring-5-mvc/pom.xml +++ b/spring-web-modules/spring-5-mvc/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -52,19 +52,14 @@ h2 runtime - - org.springframework - spring-test - org.springframework.boot spring-boot-starter-test test - com.jayway.restassured + io.rest-assured rest-assured - ${jayway-rest-assured.version} test @@ -72,11 +67,6 @@ javafaker ${javafaker.version} - - org.apache.httpcomponents - httpclient - ${httpclient.version} - @@ -84,8 +74,6 @@ - 2.9.0 - 4.5.8 com.baeldung.Spring5Application 0.18 diff --git a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java index 0550b3b79a..eebfbedc19 100644 --- a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/idc/BookRepository.java @@ -6,7 +6,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import org.springframework.stereotype.Component; diff --git a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java index b06f50b742..187ad5c3bf 100644 --- a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/model/Foo.java @@ -1,9 +1,9 @@ package com.baeldung.model; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; @Entity public class Foo { diff --git a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java index 8d8e03bbaf..78d1591575 100644 --- a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/FooController.java @@ -2,8 +2,8 @@ package com.baeldung.web; import java.util.List; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; diff --git a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java index c5f63486fe..c6bb1a3abf 100644 --- a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/ResponseBodyEmitterController.java @@ -13,7 +13,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter @Controller public class ResponseBodyEmitterController { - private ExecutorService nonBlockingService = Executors.newCachedThreadPool(); + private final ExecutorService nonBlockingService = Executors.newCachedThreadPool(); @GetMapping(Constants.API_RBE) public ResponseEntity handleRbe() { @@ -29,7 +29,7 @@ public class ResponseBodyEmitterController { } }); - return new ResponseEntity(emitter, HttpStatus.OK); + return new ResponseEntity<>(emitter, HttpStatus.OK); } } diff --git a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java index 00113c5ff7..45eed6bb3e 100644 --- a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/SseEmitterController.java @@ -14,7 +14,7 @@ import com.baeldung.Constants; @Controller public class SseEmitterController { - private ExecutorService nonBlockingService = Executors.newCachedThreadPool(); + private final ExecutorService nonBlockingService = Executors.newCachedThreadPool(); @GetMapping(Constants.API_SSE) public SseEmitter handleSse() { diff --git a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java index 1722ad85cd..00f168824a 100644 --- a/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java +++ b/spring-web-modules/spring-5-mvc/src/main/java/com/baeldung/web/StreamingResponseBodyController.java @@ -17,7 +17,7 @@ public class StreamingResponseBodyController { String msg = Constants.API_SRB_MSG + " @ " + new Date(); out.write(msg.getBytes()); }; - return new ResponseEntity(stream, HttpStatus.OK); + return new ResponseEntity<>(stream, HttpStatus.OK); } } diff --git a/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java index b2f2852dbe..8b43bc79bc 100644 --- a/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java +++ b/spring-web-modules/spring-5-mvc/src/test/java/com/baeldung/LiveTest.java @@ -6,9 +6,9 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.springframework.http.MediaType; -import com.jayway.restassured.RestAssured; -import com.jayway.restassured.response.Response; -import com.jayway.restassured.specification.RequestSpecification; +import io.restassured.RestAssured; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; public class LiveTest { @@ -36,8 +36,6 @@ public class LiveTest { assertEquals(200, response.getStatusCode()); }*/ - // - private final String resourceWithNullName() { return "{\"name\":null}"; } From 9e21e95e6fc6dbf8ce6503b23a7324fa750bc2ef Mon Sep 17 00:00:00 2001 From: Muhammad Asif Date: Wed, 27 Mar 2024 21:57:34 +0500 Subject: [PATCH 51/51] BAEL-7030 Added the example code (#16085) * BAEL-7030 Added the example code * Removed public modifier --- .../ImmutableCollectionsUnitTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 core-java-modules/core-java-collections-5/src/test/java/com/baeldung/immutables/ImmutableCollectionsUnitTest.java diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/immutables/ImmutableCollectionsUnitTest.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/immutables/ImmutableCollectionsUnitTest.java new file mode 100644 index 0000000000..6daec6d959 --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/immutables/ImmutableCollectionsUnitTest.java @@ -0,0 +1,54 @@ +package com.baeldung.immutables; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +class ImmutableCollectionsUnitTest { + + @Test + void givenUnmodifiableMap_whenPutNewEntry_thenThrowsUnsupportedOperationException() { + Map modifiableMap = new HashMap<>(); + modifiableMap.put("name1", "Michael"); + modifiableMap.put("name2", "Harry"); + + Map unmodifiableMap = Collections.unmodifiableMap(modifiableMap); + + assertThrows(UnsupportedOperationException.class, () -> unmodifiableMap.put("name3", "Micky")); + } + + @Test + void givenUnmodifiableMap_whenPutNewEntryUsingOriginalReference_thenSuccess() { + Map modifiableMap = new HashMap<>(); + modifiableMap.put("name1", "Michael"); + modifiableMap.put("name2", "Harry"); + + Map unmodifiableMap = Collections.unmodifiableMap(modifiableMap); + modifiableMap.put("name3", "Micky"); + + assertEquals(modifiableMap, unmodifiableMap); + assertTrue(unmodifiableMap.containsKey("name3")); + } + + @Test + void givenImmutableMap_whenPutNewEntry_thenThrowsUnsupportedOperationException() { + Map immutableMap = Map.of("name1", "Michael", "name2", "Harry"); + + assertThrows(UnsupportedOperationException.class, () -> immutableMap.put("name3", "Micky")); + } + + @Test + void givenImmutableMap_whenUsecopyOf_thenExceptionOnPut() { + Map immutableMap = Map.of("name1", "Michael", "name2", "Harry"); + Map copyOfImmutableMap = Map.copyOf(immutableMap); + + assertThrows(UnsupportedOperationException.class, () -> copyOfImmutableMap.put("name3", "Micky")); + } +} +