From 1b29276c17a2810a2bcd8d4b49f09f916531a878 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:00:26 -0600 Subject: [PATCH 01/15] [BAEL-5421] by @opokharel [BAEL-5421] by @opokharel --- .../com/baeldung/jar/MySampleGUIAppn.java | 26 +++++++++++++++++++ .../baeldung/jar/MySampleGUIAppnUnitTest.java | 14 ++++++++++ 2 files changed, 40 insertions(+) create mode 100644 core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java create mode 100644 core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java new file mode 100644 index 0000000000..cc0a161d0f --- /dev/null +++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java @@ -0,0 +1,26 @@ +package com.baeldung.jar; + +import java.awt.event.*; +import java.awt.*; + +import javax.swing.*; + +public class MySampleGUIAppn extends JFrame{ + public MySampleGUIAppn() { + setSize(300,300); + setTitle("MySampleGUIAppn"); + Button b = new Button("Click Me!"); + b.setBounds(30,100,80,30); + add(b); + setVisible(true); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + dispose(); + System.exit(0); + } + }); + } + public static void main(String[] args) { + MySampleGUIAppn app=new MySampleGUIAppn(); + } +} diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java new file mode 100644 index 0000000000..af5643cf40 --- /dev/null +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -0,0 +1,14 @@ +package com.baeldung.jar; + +import org.junit.jupiter.api.Test; + +class MySampleGUIAppnUnitTest extends MySampleGUIAppn { + + @Test + void testMain() { + MySampleGUIAppn instance = new MySampleGUIAppn(); + String [] args = null; + System.exit(DO_NOTHING_ON_CLOSE); + main(args); + } +} \ No newline at end of file From c2bfe407de76d8f76208fd28435790305ca7c312 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:09:55 -0600 Subject: [PATCH 02/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index af5643cf40..7084c1468d 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; class MySampleGUIAppnUnitTest extends MySampleGUIAppn { @Test - void testMain() { + void testMain() throws IOException { MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(DO_NOTHING_ON_CLOSE); From acd0dc78946ff8d3b04a1903c457bb8fbb63f4bb Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:29:08 -0600 Subject: [PATCH 03/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 7084c1468d..2fbd6cf510 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -2,7 +2,7 @@ package com.baeldung.jar; import org.junit.jupiter.api.Test; -class MySampleGUIAppnUnitTest extends MySampleGUIAppn { +class MySampleGUIAppnUnitTest extends IOException { @Test void testMain() throws IOException { From d29b19e148bdc8e3a84193d8fd9a371cf6140823 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:30:29 -0600 Subject: [PATCH 04/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 2fbd6cf510..f13b55158c 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -2,7 +2,7 @@ package com.baeldung.jar; import org.junit.jupiter.api.Test; -class MySampleGUIAppnUnitTest extends IOException { +class MySampleGUIAppnUnitTest throws IOException { @Test void testMain() throws IOException { From ded7b0af8f215075e586a128a13caafba2aeb015 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:35:39 -0600 Subject: [PATCH 05/15] BAEL-5421 --- .../java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index f13b55158c..28bb7cc7a8 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -1,14 +1,16 @@ package com.baeldung.jar; +import java.io.IOException; + import org.junit.jupiter.api.Test; -class MySampleGUIAppnUnitTest throws IOException { +class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; - System.exit(DO_NOTHING_ON_CLOSE); - main(args); + System.exit(0); + MySampleGUIAppn.main(args); } } \ No newline at end of file From baa612d3bb687b9ac96ba8ae904fe45f55488370 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:42:18 -0600 Subject: [PATCH 06/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 28bb7cc7a8..ad1728bed8 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -8,6 +8,8 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { + System.setProperty("java.awt.headless", "false"); + System.out.println(java.awt.GraphicsEnvironment.isHeadless()); MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); From ca767321f77b4fad21d8b4305e738b7efb6cc530 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:46:51 -0600 Subject: [PATCH 07/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index ad1728bed8..86f09ccd25 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -8,7 +8,7 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { - System.setProperty("java.awt.headless", "false"); + System.setProperty("java.awt.headless", "true"); System.out.println(java.awt.GraphicsEnvironment.isHeadless()); MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; From 380b86b50edbc6229f41056a15f813a94c1cc38f Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 11:57:23 -0600 Subject: [PATCH 08/15] BAEL-5421 --- .../src/main/java/com/baeldung/jar/MySampleGUIAppn.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java index cc0a161d0f..2be8cef717 100644 --- a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java +++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java @@ -12,7 +12,9 @@ public class MySampleGUIAppn extends JFrame{ Button b = new Button("Click Me!"); b.setBounds(30,100,80,30); add(b); - setVisible(true); + if (!GraphicsEnvironment.isHeadless()) { + setVisible(true); + } addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); From 38664852dd5f8446a52a4ac8fea6e3d84adce94d Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 12:11:40 -0600 Subject: [PATCH 09/15] BAEL-5421 --- .../test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 86f09ccd25..ff534b9323 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -8,8 +8,8 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { - System.setProperty("java.awt.headless", "true"); - System.out.println(java.awt.GraphicsEnvironment.isHeadless()); + //System.setProperty("java.awt.headless", "true"); + //System.out.println(java.awt.GraphicsEnvironment.isHeadless()); MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); From db1bf15694024281339d6c5690b6bcf10cfe620e Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 12:16:04 -0600 Subject: [PATCH 10/15] BAEL-5421 --- .../test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index ff534b9323..5842a2042c 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -8,8 +8,7 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { - //System.setProperty("java.awt.headless", "true"); - //System.out.println(java.awt.GraphicsEnvironment.isHeadless()); + System.setProperty("java.awt.headless", "true"); MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); From 8991dbe2dff3de80e9a1bb2f3a9c9ab8e4e5aa18 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 12:36:55 -0600 Subject: [PATCH 11/15] BAEL-5421 --- .../com/baeldung/jar/MySampleGUIAppn.java | 26 +++++++++++-------- .../baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java index 2be8cef717..95f3fff2a3 100644 --- a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java +++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java @@ -7,20 +7,24 @@ import javax.swing.*; public class MySampleGUIAppn extends JFrame{ public MySampleGUIAppn() { - setSize(300,300); - setTitle("MySampleGUIAppn"); - Button b = new Button("Click Me!"); - b.setBounds(30,100,80,30); - add(b); if (!GraphicsEnvironment.isHeadless()) { + setSize(300,300); + setTitle("MySampleGUIAppn"); + Button b = new Button("Click Me!"); + b.setBounds(30,100,80,30); + add(b); setVisible(true); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + dispose(); + System.exit(0); + } + }); + + } + else { + System.exit(0); } - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - dispose(); - System.exit(0); - } - }); } public static void main(String[] args) { MySampleGUIAppn app=new MySampleGUIAppn(); diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 5842a2042c..ba44f24685 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -8,7 +8,7 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { - System.setProperty("java.awt.headless", "true"); + System.setProperty("java.awt.headless", "false"); MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); From fac1883733bbf2503f1517b36cb8daef533ce3fe Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 12:41:04 -0600 Subject: [PATCH 12/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index ba44f24685..5842a2042c 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -8,7 +8,7 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { - System.setProperty("java.awt.headless", "false"); + System.setProperty("java.awt.headless", "true"); MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); From 6ff0745dce6b1d582c9daa7fcbce374ba848c292 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 12:45:17 -0600 Subject: [PATCH 13/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 5842a2042c..8c53613d5a 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -9,7 +9,7 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { System.setProperty("java.awt.headless", "true"); - MySampleGUIAppn instance = new MySampleGUIAppn(); + //MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); MySampleGUIAppn.main(args); From 99a902b27b92bb83bf172d98ddcb7c8197196c0a Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 12:48:16 -0600 Subject: [PATCH 14/15] BAEL-5421 --- .../src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 8c53613d5a..878d65e01d 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -9,7 +9,6 @@ class MySampleGUIAppnUnitTest { @Test void testMain() throws IOException { System.setProperty("java.awt.headless", "true"); - //MySampleGUIAppn instance = new MySampleGUIAppn(); String [] args = null; System.exit(0); MySampleGUIAppn.main(args); From 90aa4a12395379698bb12ec857c4a865d91ef5d1 Mon Sep 17 00:00:00 2001 From: opokharel Date: Sat, 25 Jun 2022 17:21:34 -0600 Subject: [PATCH 15/15] BAEL-5421 by @opokharel BAEL-5421 by @opokharel --- .../src/main/java/com/baeldung/jar/MySampleGUIAppn.java | 3 +-- .../test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java index 95f3fff2a3..86d52eed56 100644 --- a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java +++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java @@ -5,7 +5,7 @@ import java.awt.*; import javax.swing.*; -public class MySampleGUIAppn extends JFrame{ +public class MySampleGUIAppn extends JFrame { public MySampleGUIAppn() { if (!GraphicsEnvironment.isHeadless()) { setSize(300,300); @@ -20,7 +20,6 @@ public class MySampleGUIAppn extends JFrame{ System.exit(0); } }); - } else { System.exit(0); diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java index 878d65e01d..106531008c 100644 --- a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java +++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java @@ -5,7 +5,6 @@ import java.io.IOException; import org.junit.jupiter.api.Test; class MySampleGUIAppnUnitTest { - @Test void testMain() throws IOException { System.setProperty("java.awt.headless", "true");