This commit is related to BAEL-7028 (#15648)

This commit aims to add two classes:
       -  PrintMessageWithoutMainMethod
       - PrintMessageWithoutMainUnitTest
This commit is contained in:
Mo Helmy 2024-01-15 18:49:23 +02:00 committed by GitHub
parent 6818b14f15
commit 85c4162119
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package com.baeldung.printmessagewithoutmain;
public final class PrintMessageWithoutMainMethod {
//Using Static Blocks
static {
System.out.println("Hello World!!");
System.exit(0);
}
//Using Nested Classes
static {
NestedClass.printMessage();
}
//Executing Code During Class Initialization
private static final int STATUS = getStatus();
private static int getStatus() {
System.out.println("Hello World!!");
System.exit(0);
return 0;
}
public static void main(String[] args) {
}
static class NestedClass {
static void printMessage() {
System.out.println("Message from nested class");
}
}
}

View File

@ -0,0 +1,10 @@
package com.baeldung.printmessagewithoutmain;
import org.junit.jupiter.api.Test;
public class PrintMessageWithoutMainUnitTest {
@Test
public void givenMessage_whenUsingJunitTest_thenPrintMessage() {
System.out.println("Hello World!!");
}
}