Skip to content

Commit 59c5142

Browse files
committed
Add assignment
1 parent fa08f3a commit 59c5142

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
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 .\src\main\java\com\example\Main.java
18+
```
519
Maven Goals
620
=========
721
1. Clean:
@@ -10,4 +24,3 @@ Maven Goals
1024
2. Build:
1125
* mvn compile
1226
* mvn test
13-
*
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
package org.example;
22

3+
4+
import com.example.Main;
35
import org.junit.jupiter.api.Test;
46

7+
import java.io.ByteArrayOutputStream;
8+
import java.io.PrintStream;
9+
510
import static org.assertj.core.api.Assertions.assertThat;
611

712
class 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+
}

0 commit comments

Comments
 (0)