File tree Expand file tree Collapse file tree 2 files changed +38
-6
lines changed
src/test/java/org/example Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Original file line number Diff line number Diff line change 1- # 🚀 Requirements
1+ # 🚀 Java Hello World
22
3- Add requirements here
3+ This guide shows how to create a "Hello World" Java application.
44
5+ ## 1. Classic Java (All Versions)
6+
7+ ** Code:**
8+ ``` java
9+ public class Main {
10+ public static void main (String [] args ) {
11+ System . out. println(" Hello World" );
12+ }
13+ }
14+ ```
15+ ## 3. Run
16+ ``` shell
17+ java .\s rc\m ain\j ava\c om\e xample\M ain.java
18+ ```
519Maven Goals
620=========
7211 . Clean:
@@ -10,4 +24,3 @@ Maven Goals
10242 . Build:
1125 * mvn compile
1226 * mvn test
13- *
Original file line number Diff line number Diff line change 11package org .example ;
22
3+
4+ import com .example .Main ;
35import org .junit .jupiter .api .Test ;
46
7+ import java .io .ByteArrayOutputStream ;
8+ import java .io .PrintStream ;
9+
510import static org .assertj .core .api .Assertions .assertThat ;
611
712class MainTest {
13+
14+
815 @ Test
9- void test () {
10- assertThat (true ).isTrue ();
16+ void mainMethodShouldPrintHelloWorld () {
17+ // Arrange: Capture System.out
18+ ByteArrayOutputStream outContent = new ByteArrayOutputStream ();
19+ PrintStream originalOut = System .out ;
20+ System .setOut (new PrintStream (outContent ));
21+
22+ // Act: Run the main method
23+ Main .main (new String []{});
24+
25+ // Restore original System.out
26+ System .setOut (originalOut );
27+
28+ // Assert: Check output
29+ assertThat (outContent .toString ().trim ()).isEqualTo ("Hello World" );
1130 }
12- }
31+ }
You can’t perform that action at this time.
0 commit comments