From b8c875adbd5d38ee211c35c84d7fba29b1b2dda3 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:31:48 +0530 Subject: [PATCH 01/26] Create Print2DArray.java --- .../baeldung/print2DArrays/Print2DArray.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java new file mode 100644 index 0000000000..73fc44b188 --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java @@ -0,0 +1,23 @@ +package com.baeldung.print2DArrays; + +import java.util.*; + +public class Print2DArray{ + + public static void print2DNested(int[][] myArray){ + for (int i = 0; i < myArray.length; i++) { + for (int j = 0; j < myArray[i].length; j++) { + System.out.print(myArray[i][j] + " "); + } + System.out.println(); + } + } + + public static void print2DStream(int[][] myArray){ + Arrays.stream(myArray).flatMapToInt(Arrays::stream).forEach(num -> System.out.print(num + " ")); + } + + public static void print2DDeepToString(int[][] myArray){ + System.out.println(Arrays.deepToString(myArray)); + } +} From b62e4d4baf8e3b92847af1512b92717941c9a6dd Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:35:23 +0530 Subject: [PATCH 02/26] Update Print2DArray.java --- .../com/baeldung/print2DArrays/Print2DArray.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java index 73fc44b188..35b661b671 100644 --- a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java @@ -20,4 +20,17 @@ public class Print2DArray{ public static void print2DDeepToString(int[][] myArray){ System.out.println(Arrays.deepToString(myArray)); } + + public static void printArrayAsList(int[][] myArray) { + for (int[] row : myArray) { + List rowList = Arrays.asList(Arrays.stream(row).boxed().toArray(Integer[]::new)); + System.out.println(rowList); + } + } + + public static void printArrayString(int[][] myArray) { + for (int[] row : myArray) { + System.out.println(Arrays.toString(row)); + } + } } From 6b8040ffff4488a57b66dae323722dd9f2e9c677 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Thu, 23 Nov 2023 23:00:57 +0530 Subject: [PATCH 03/26] Update Print2DArray.java --- .../main/java/com/baeldung/print2DArrays/Print2DArray.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java index 35b661b671..b381e5c85d 100644 --- a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java @@ -20,13 +20,6 @@ public class Print2DArray{ public static void print2DDeepToString(int[][] myArray){ System.out.println(Arrays.deepToString(myArray)); } - - public static void printArrayAsList(int[][] myArray) { - for (int[] row : myArray) { - List rowList = Arrays.asList(Arrays.stream(row).boxed().toArray(Integer[]::new)); - System.out.println(rowList); - } - } public static void printArrayString(int[][] myArray) { for (int[] row : myArray) { From d64976dff4622b60dc56910b20067d2c7592a75e Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Fri, 24 Nov 2023 00:28:48 +0530 Subject: [PATCH 04/26] Update Print2DArray.java --- .../baeldung/print2DArrays/Print2DArray.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java index b381e5c85d..cc54f25c06 100644 --- a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java @@ -4,26 +4,34 @@ import java.util.*; public class Print2DArray{ - public static void print2DNested(int[][] myArray){ + public static String print2DNested(int[][] myArray){ + StringBuilder result = new StringBuilder(); for (int i = 0; i < myArray.length; i++) { for (int j = 0; j < myArray[i].length; j++) { - System.out.print(myArray[i][j] + " "); + result.append(myArray[i][j]).append(" "); } - System.out.println(); + result.append("\n"); } + return result.toString(); } - public static void print2DStream(int[][] myArray){ - Arrays.stream(myArray).flatMapToInt(Arrays::stream).forEach(num -> System.out.print(num + " ")); + public static String print2DStream(int[][] myArray){ + StringBuilder result = new StringBuilder(); + Arrays.stream(myArray).flatMapToInt(Arrays::stream).forEach(num -> result.append(num).append(" ")); + return result.toString(); } - public static void print2DDeepToString(int[][] myArray){ - System.out.println(Arrays.deepToString(myArray)); + public static String print2DDeepToString(int[][] myArray){ + StringBuilder result = new StringBuilder(); + result.append(Arrays.deepToString(myArray)).append("\n"); + return result.toString(); } - public static void printArrayString(int[][] myArray) { + public static String printArrayString(int[][] myArray) { + StringBuilder result = new StringBuilder(); for (int[] row : myArray) { - System.out.println(Arrays.toString(row)); + result.append(Arrays.toString(row)).append("\n"); } + return result.toString(); } } From 990a4812dc2a48ab39d9864fc441350b4beace93 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Fri, 24 Nov 2023 00:31:59 +0530 Subject: [PATCH 05/26] Create Print2DArraysTest.java --- .../print2DArrays/Print2DArraysTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java new file mode 100644 index 0000000000..7fd8211926 --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java @@ -0,0 +1,35 @@ +package com.baeldung.print2DArrays; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ArrayPrinterTest { + + @Test + public void testPrint2DNested() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n"; + assertEquals(expectedOutput, ArrayPrinter.print2DNested(myArray)); + } + + @Test + public void testPrint2DStream() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + String expectedOutput = "1 2 3 4 5 6 7 8 9 "; + assertEquals(expectedOutput, ArrayPrinter.print2DStream(myArray)); + } + + @Test + public void testPrint2DDeepToString() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n"; + assertEquals(expectedOutput, ArrayPrinter.print2DDeepToString(myArray)); + } + + @Test + public void testPrintArrayString() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"; + assertEquals(expectedOutput, ArrayPrinter.printArrayString(myArray)); + } +} From 3210b24038de92afaf88378ba0f0f793168b3b3a Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:07:28 +0530 Subject: [PATCH 06/26] Update Print2DArraysTest.java --- .../print2DArrays/Print2DArraysTest.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java index 7fd8211926..37e08c54ab 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java @@ -4,32 +4,46 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class ArrayPrinterTest { + + @SystemStub + private SystemOut systemOut; @Test - public void testPrint2DNested() { + void whenPrint2D_thenUseNested() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + for (int i = 0; i < array.length; i++) { + for (int j = 0; j < array[i].length; j++) { + System.out.print(array[i][j] + " "); + } + System.out.println(); + } String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n"; - assertEquals(expectedOutput, ArrayPrinter.print2DNested(myArray)); + assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @Test - public void testPrint2DStream() { + public void whenPrint2D_thenUseStream() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - String expectedOutput = "1 2 3 4 5 6 7 8 9 "; - assertEquals(expectedOutput, ArrayPrinter.print2DStream(myArray)); + Arrays.stream(array) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); + String expectedOutput = "1 2 3 4 5 6 7 8 9"; + assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @Test - public void testPrint2DDeepToString() { + public void whenPrint2D_thenUseDeepToString() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n"; - assertEquals(expectedOutput, ArrayPrinter.print2DDeepToString(myArray)); + System.out.println(Arrays.deepToString(myArray)); + String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"; + assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @Test - public void testPrintArrayString() { + public void whenPrint2D_thenUseDeepToString() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + for (int[] row : myArray) { + System.out.println(Arrays.toString(row)); + } String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"; - assertEquals(expectedOutput, ArrayPrinter.printArrayString(myArray)); + assertThat(systemOut.getLines()).containsExactly(expectedOutput); } } From 4280b171962f2995f208c4200830857764639c2d Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:08:15 +0530 Subject: [PATCH 07/26] Delete core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java --- .../baeldung/print2DArrays/Print2DArray.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java deleted file mode 100644 index cc54f25c06..0000000000 --- a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/print2DArrays/Print2DArray.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.print2DArrays; - -import java.util.*; - -public class Print2DArray{ - - public static String print2DNested(int[][] myArray){ - StringBuilder result = new StringBuilder(); - for (int i = 0; i < myArray.length; i++) { - for (int j = 0; j < myArray[i].length; j++) { - result.append(myArray[i][j]).append(" "); - } - result.append("\n"); - } - return result.toString(); - } - - public static String print2DStream(int[][] myArray){ - StringBuilder result = new StringBuilder(); - Arrays.stream(myArray).flatMapToInt(Arrays::stream).forEach(num -> result.append(num).append(" ")); - return result.toString(); - } - - public static String print2DDeepToString(int[][] myArray){ - StringBuilder result = new StringBuilder(); - result.append(Arrays.deepToString(myArray)).append("\n"); - return result.toString(); - } - - public static String printArrayString(int[][] myArray) { - StringBuilder result = new StringBuilder(); - for (int[] row : myArray) { - result.append(Arrays.toString(row)).append("\n"); - } - return result.toString(); - } -} From 7e8ccf1613687b8dca388667092e5911ed9c059b Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Sun, 10 Dec 2023 23:12:46 +0530 Subject: [PATCH 08/26] Update Print2DArraysTest.java --- .../java/com/baeldung/print2DArrays/Print2DArraysTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java index 37e08c54ab..f2598396ee 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java @@ -3,6 +3,9 @@ package com.baeldung.print2DArrays; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import uk.org.webcompere.systemstubs.SystemOut; +import uk.org.webcompere.systemstubs.annotations.SystemStub; + public class ArrayPrinterTest { @SystemStub From 9dcf7b212f2ebc0408fb6a2e934577c8cdfddbb1 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Sun, 10 Dec 2023 23:13:41 +0530 Subject: [PATCH 09/26] Update pom.xml --- core-java-modules/core-java-arrays-guides/pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml index d22f6b4d7d..8294743cd8 100644 --- a/core-java-modules/core-java-arrays-guides/pom.xml +++ b/core-java-modules/core-java-arrays-guides/pom.xml @@ -24,6 +24,13 @@ jmh-generator-annprocess ${jmh-generator.version} + + com.github.stefanbirkner + system-stubs + 1.1.1 + test + + - \ No newline at end of file + From d8e96587b0a786dc2e43755c163215b1f37f25db Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:51:06 +0530 Subject: [PATCH 10/26] Update pom.xml --- core-java-modules/core-java-arrays-guides/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml index 8294743cd8..d0c0df99ea 100644 --- a/core-java-modules/core-java-arrays-guides/pom.xml +++ b/core-java-modules/core-java-arrays-guides/pom.xml @@ -25,9 +25,9 @@ ${jmh-generator.version} - com.github.stefanbirkner - system-stubs - 1.1.1 + uk.org.webcompere + system-stubs-jupiter + 1.1.0 test From f64c2b1689db2906879827bed2875cf668a307f1 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:38:59 +0530 Subject: [PATCH 11/26] Update pom.xml --- core-java-modules/core-java-arrays-guides/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml index d0c0df99ea..b0b4305ed0 100644 --- a/core-java-modules/core-java-arrays-guides/pom.xml +++ b/core-java-modules/core-java-arrays-guides/pom.xml @@ -27,7 +27,7 @@ uk.org.webcompere system-stubs-jupiter - 1.1.0 + 2.1.5 test From f2e2c0b38cf66b4217ebbd100b51a8ced14bbd53 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:44:01 +0530 Subject: [PATCH 12/26] Update Print2DArraysTest.java --- .../print2DArrays/Print2DArraysTest.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java index f2598396ee..eaf8485389 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java @@ -1,22 +1,25 @@ package com.baeldung.print2DArrays; +package com.st.tram.common; + import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Arrays; + import uk.org.webcompere.systemstubs.SystemOut; import uk.org.webcompere.systemstubs.annotations.SystemStub; -public class ArrayPrinterTest { - +public class Print2DArrayTest { @SystemStub private SystemOut systemOut; - + @Test void whenPrint2D_thenUseNested() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - for (int i = 0; i < array.length; i++) { - for (int j = 0; j < array[i].length; j++) { - System.out.print(array[i][j] + " "); + for (int i = 0; i < myArray.length; i++) { + for (int j = 0; j < myArray[i].length; j++) { + System.out.print(myArray[i][j] + " "); } System.out.println(); } @@ -27,7 +30,7 @@ public class ArrayPrinterTest { @Test public void whenPrint2D_thenUseStream() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - Arrays.stream(array) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); + Arrays.stream(myArray) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); String expectedOutput = "1 2 3 4 5 6 7 8 9"; assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @@ -41,7 +44,7 @@ public class ArrayPrinterTest { } @Test - public void whenPrint2D_thenUseDeepToString() { + public void whenPrint2D_thenUseArrayToString() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int[] row : myArray) { System.out.println(Arrays.toString(row)); @@ -50,3 +53,4 @@ public class ArrayPrinterTest { assertThat(systemOut.getLines()).containsExactly(expectedOutput); } } + From b0be5fcbaa402d7708efff434f5681b2041f6f0c Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 11 Dec 2023 22:16:51 +0530 Subject: [PATCH 13/26] Update Print2DArraysTest.java --- .../test/java/com/baeldung/print2DArrays/Print2DArraysTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java index eaf8485389..d027f00493 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java @@ -1,7 +1,5 @@ package com.baeldung.print2DArrays; -package com.st.tram.common; - import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; From a8d04d122af4cf47e4faa8983ed123fcb997142c Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:17:01 +0530 Subject: [PATCH 14/26] Update Print2DArraysTest.java --- .../test/java/com/baeldung/print2DArrays/Print2DArraysTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java index d027f00493..c89b1469ff 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java @@ -8,7 +8,7 @@ import java.util.Arrays; import uk.org.webcompere.systemstubs.SystemOut; import uk.org.webcompere.systemstubs.annotations.SystemStub; -public class Print2DArrayTest { +public class Print2DArrayUnitTest { @SystemStub private SystemOut systemOut; From 1f72aad0cc17010b876150aa45811ed597eca945 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:18:44 +0530 Subject: [PATCH 15/26] Rename Print2DArraysTest.java to Print2DArraysUnitTest.java --- .../{Print2DArraysTest.java => Print2DArraysUnitTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/{Print2DArraysTest.java => Print2DArraysUnitTest.java} (100%) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java similarity index 100% rename from core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysTest.java rename to core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java From e49112ce2bf9818f3edd76e04a7a7c2e4242433d Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:20:55 +0530 Subject: [PATCH 16/26] Update Print2DArraysUnitTest.java --- .../com/baeldung/print2DArrays/Print2DArraysUnitTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java index c89b1469ff..dcb027c715 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java @@ -5,10 +5,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; -import uk.org.webcompere.systemstubs.SystemOut; -import uk.org.webcompere.systemstubs.annotations.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.stream.SystemOut; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; -public class Print2DArrayUnitTest { +@ExtendWith(SystemStubsExtension.class) +public class Print2DArraysUnitTest { @SystemStub private SystemOut systemOut; From 47bd8d25f9dace7e4167f774c10c6d3032b4db3d Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:22:15 +0530 Subject: [PATCH 17/26] renamed folder --- .../print2darrays/Print2DArraysUnitTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java new file mode 100644 index 0000000000..c89b1469ff --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -0,0 +1,54 @@ +package com.baeldung.print2DArrays; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; + +import uk.org.webcompere.systemstubs.SystemOut; +import uk.org.webcompere.systemstubs.annotations.SystemStub; + +public class Print2DArrayUnitTest { + @SystemStub + private SystemOut systemOut; + + @Test + void whenPrint2D_thenUseNested() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + for (int i = 0; i < myArray.length; i++) { + for (int j = 0; j < myArray[i].length; j++) { + System.out.print(myArray[i][j] + " "); + } + System.out.println(); + } + String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n"; + assertThat(systemOut.getLines()).containsExactly(expectedOutput); + } + + @Test + public void whenPrint2D_thenUseStream() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + Arrays.stream(myArray) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); + String expectedOutput = "1 2 3 4 5 6 7 8 9"; + assertThat(systemOut.getLines()).containsExactly(expectedOutput); + } + + @Test + public void whenPrint2D_thenUseDeepToString() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + System.out.println(Arrays.deepToString(myArray)); + String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"; + assertThat(systemOut.getLines()).containsExactly(expectedOutput); + } + + @Test + public void whenPrint2D_thenUseArrayToString() { + int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + for (int[] row : myArray) { + System.out.println(Arrays.toString(row)); + } + String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"; + assertThat(systemOut.getLines()).containsExactly(expectedOutput); + } +} + From 6162351819d515639f6534f23950b8ae7fd316c3 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:29:46 +0530 Subject: [PATCH 18/26] Update Print2DArraysUnitTest.java --- .../print2darrays/Print2DArraysUnitTest.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index c89b1469ff..7f3045f099 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -1,19 +1,23 @@ -package com.baeldung.print2DArrays; +package com.baeldung.print2Drrays; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; -import uk.org.webcompere.systemstubs.SystemOut; -import uk.org.webcompere.systemstubs.annotations.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.stream.SystemOut; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; -public class Print2DArrayUnitTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(SystemStubsExtension.class) +public class Print2DArraysUnitTest { @SystemStub private SystemOut systemOut; @Test - void whenPrint2D_thenUseNested() { + void whenPrint2dArrayUsingNestedLoop_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int i = 0; i < myArray.length; i++) { for (int j = 0; j < myArray[i].length; j++) { @@ -26,7 +30,7 @@ public class Print2DArrayUnitTest { } @Test - public void whenPrint2D_thenUseStream() { + public void whenPrint2dArrayUsingStreams_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Arrays.stream(myArray) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); String expectedOutput = "1 2 3 4 5 6 7 8 9"; @@ -34,7 +38,7 @@ public class Print2DArrayUnitTest { } @Test - public void whenPrint2D_thenUseDeepToString() { + public void whenPrint2dArrayUsingDeepToString_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; System.out.println(Arrays.deepToString(myArray)); String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"; @@ -42,7 +46,7 @@ public class Print2DArrayUnitTest { } @Test - public void whenPrint2D_thenUseArrayToString() { + public void whenPrint2dArrayUsingArrayToString_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int[] row : myArray) { System.out.println(Arrays.toString(row)); From 523826cc0c5457b292d4caac5113c00b3969c78b Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:30:11 +0530 Subject: [PATCH 19/26] Update Print2DArraysUnitTest.java --- .../java/com/baeldung/print2darrays/Print2DArraysUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index 7f3045f099..a825c009ec 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.print2Drrays; +package com.baeldung.print2darrays; import org.junit.jupiter.api.Test; From 03949adeed403a3338bba5064b2b62af757c1212 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Wed, 27 Dec 2023 23:50:18 +0530 Subject: [PATCH 20/26] Update Print2DArraysUnitTest.java --- .../java/com/baeldung/print2darrays/Print2DArraysUnitTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index a825c009ec..687242cfe4 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -1,6 +1,7 @@ package com.baeldung.print2darrays; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.util.Arrays; From 458c3493e630a510005ccdab5d63325757ded119 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:22:23 +0530 Subject: [PATCH 21/26] Update Print2DArraysUnitTest.java --- .../print2darrays/Print2DArraysUnitTest.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index 687242cfe4..9a126d86f7 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -2,29 +2,27 @@ package com.baeldung.print2darrays; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import uk.org.webcompere.systemstubs.jupiter.SystemStub; +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import uk.org.webcompere.systemstubs.stream.SystemOut; import java.util.Arrays; -import uk.org.webcompere.systemstubs.jupiter.SystemStub; -import uk.org.webcompere.systemstubs.stream.SystemOut; -import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(SystemStubsExtension.class) -public class Print2DArraysUnitTest { +public class Print2DArrayTest { @SystemStub private SystemOut systemOut; - + @Test void whenPrint2dArrayUsingNestedLoop_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int i = 0; i < myArray.length; i++) { - for (int j = 0; j < myArray[i].length; j++) { - System.out.print(myArray[i][j] + " "); + for (int j = 0; j < myArray[i].length; j++) { + System.out.print(myArray[i][j] + " "); } - System.out.println(); + System.out.print("\n"); } String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n"; assertThat(systemOut.getLines()).containsExactly(expectedOutput); @@ -34,7 +32,7 @@ public class Print2DArraysUnitTest { public void whenPrint2dArrayUsingStreams_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Arrays.stream(myArray) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); - String expectedOutput = "1 2 3 4 5 6 7 8 9"; + String expectedOutput = "1 2 3 4 5 6 7 8 9 "; assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @@ -50,7 +48,7 @@ public class Print2DArraysUnitTest { public void whenPrint2dArrayUsingArrayToString_thenLinesAreWrittenToSystemOut() { int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; for (int[] row : myArray) { - System.out.println(Arrays.toString(row)); + System.out.print(Arrays.toString(row) + "\n"); } String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"; assertThat(systemOut.getLines()).containsExactly(expectedOutput); From cc3efa5c868b3257b6e9dbf6ea93760f20364dca Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:31:38 +0530 Subject: [PATCH 22/26] Update Print2DArraysUnitTest.java --- .../java/com/baeldung/print2darrays/Print2DArraysUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index 9a126d86f7..ed587ef59b 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -11,7 +11,7 @@ import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(SystemStubsExtension.class) -public class Print2DArrayTest { +public class Print2DArraysUnitTest { @SystemStub private SystemOut systemOut; From 5f0cc26b405c4161e1c10b63835f0cbb969fcc8a Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:33:02 +0530 Subject: [PATCH 23/26] Delete core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays directory --- .../print2DArrays/Print2DArraysUnitTest.java | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java deleted file mode 100644 index dcb027c715..0000000000 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2DArrays/Print2DArraysUnitTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.print2DArrays; - -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Arrays; - -import uk.org.webcompere.systemstubs.jupiter.SystemStub; -import uk.org.webcompere.systemstubs.stream.SystemOut; -import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; - -@ExtendWith(SystemStubsExtension.class) -public class Print2DArraysUnitTest { - @SystemStub - private SystemOut systemOut; - - @Test - void whenPrint2D_thenUseNested() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - for (int i = 0; i < myArray.length; i++) { - for (int j = 0; j < myArray[i].length; j++) { - System.out.print(myArray[i][j] + " "); - } - System.out.println(); - } - String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n"; - assertThat(systemOut.getLines()).containsExactly(expectedOutput); - } - - @Test - public void whenPrint2D_thenUseStream() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - Arrays.stream(myArray) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); - String expectedOutput = "1 2 3 4 5 6 7 8 9"; - assertThat(systemOut.getLines()).containsExactly(expectedOutput); - } - - @Test - public void whenPrint2D_thenUseDeepToString() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - System.out.println(Arrays.deepToString(myArray)); - String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"; - assertThat(systemOut.getLines()).containsExactly(expectedOutput); - } - - @Test - public void whenPrint2D_thenUseArrayToString() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - for (int[] row : myArray) { - System.out.println(Arrays.toString(row)); - } - String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"; - assertThat(systemOut.getLines()).containsExactly(expectedOutput); - } -} - From 8c9636c5c698a9dde08d2634833cc77af9a625b3 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:47:47 +0530 Subject: [PATCH 24/26] Update Print2DArraysUnitTest.java --- .../print2darrays/Print2DArraysUnitTest.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index ed587ef59b..74a910050e 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -1,23 +1,25 @@ package com.baeldung.print2darrays; +import java.util.Arrays; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; + import uk.org.webcompere.systemstubs.jupiter.SystemStub; import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; import uk.org.webcompere.systemstubs.stream.SystemOut; -import java.util.Arrays; - import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(SystemStubsExtension.class) public class Print2DArraysUnitTest { + @SystemStub private SystemOut systemOut; @Test void whenPrint2dArrayUsingNestedLoop_thenLinesAreWrittenToSystemOut() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + int[][] myArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; for (int i = 0; i < myArray.length; i++) { for (int j = 0; j < myArray[i].length; j++) { System.out.print(myArray[i][j] + " "); @@ -30,15 +32,17 @@ public class Print2DArraysUnitTest { @Test public void whenPrint2dArrayUsingStreams_thenLinesAreWrittenToSystemOut() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - Arrays.stream(myArray) .flatMapToInt(Arrays::stream) .forEach(num -> System.out.print(num + " ")); + int[][] myArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; + Arrays.stream(myArray) + .flatMapToInt(Arrays::stream) + .forEach(num -> System.out.print(num + " ")); String expectedOutput = "1 2 3 4 5 6 7 8 9 "; assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @Test public void whenPrint2dArrayUsingDeepToString_thenLinesAreWrittenToSystemOut() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + int[][] myArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; System.out.println(Arrays.deepToString(myArray)); String expectedOutput = "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"; assertThat(systemOut.getLines()).containsExactly(expectedOutput); @@ -46,7 +50,7 @@ public class Print2DArraysUnitTest { @Test public void whenPrint2dArrayUsingArrayToString_thenLinesAreWrittenToSystemOut() { - int[][] myArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + int[][] myArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; for (int[] row : myArray) { System.out.print(Arrays.toString(row) + "\n"); } @@ -54,4 +58,3 @@ public class Print2DArraysUnitTest { assertThat(systemOut.getLines()).containsExactly(expectedOutput); } } - From b57ecaab79db503776215f1776d6b11bf381af0a Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:18:33 +0530 Subject: [PATCH 25/26] Update Print2DArraysUnitTest.java --- .../com/baeldung/print2darrays/Print2DArraysUnitTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java index 74a910050e..8694f74d9b 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/print2darrays/Print2DArraysUnitTest.java @@ -24,9 +24,8 @@ public class Print2DArraysUnitTest { for (int j = 0; j < myArray[i].length; j++) { System.out.print(myArray[i][j] + " "); } - System.out.print("\n"); } - String expectedOutput = "1 2 3 \n4 5 6 \n7 8 9 \n"; + String expectedOutput = "1 2 3 4 5 6 7 8 9 "; assertThat(systemOut.getLines()).containsExactly(expectedOutput); } @@ -52,9 +51,9 @@ public class Print2DArraysUnitTest { public void whenPrint2dArrayUsingArrayToString_thenLinesAreWrittenToSystemOut() { int[][] myArray = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; for (int[] row : myArray) { - System.out.print(Arrays.toString(row) + "\n"); + System.out.print(Arrays.toString(row)); } - String expectedOutput = "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n"; + String expectedOutput = "[1, 2, 3][4, 5, 6][7, 8, 9]"; assertThat(systemOut.getLines()).containsExactly(expectedOutput); } } From 13c2b756d3b7a91efbe038fe5af84ffba39307f8 Mon Sep 17 00:00:00 2001 From: Neetika23 <42495275+Neetika23@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:54:15 +0530 Subject: [PATCH 26/26] Update pom.xml --- core-java-modules/core-java-arrays-guides/pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml index b0b4305ed0..cc67add9e3 100644 --- a/core-java-modules/core-java-arrays-guides/pom.xml +++ b/core-java-modules/core-java-arrays-guides/pom.xml @@ -7,6 +7,10 @@ core-java-arrays-guides jar + + 2.1.5 + + core-java-modules com.baeldung.core-java-modules @@ -27,7 +31,7 @@ uk.org.webcompere system-stubs-jupiter - 2.1.5 + ${system-stubs.jupiter.version} test