Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit f6ad72f

Browse files
committed
all tests except file and exchange IO
1 parent a7284b9 commit f6ad72f

File tree

8 files changed

+106
-86
lines changed

8 files changed

+106
-86
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<div id="top" align="center">
2+
<a href="https://github.com/KatsuteDev/simplehttpserver">
3+
<img src="https://raw.githubusercontent.com/KatsuteDev/simplehttpserver/main/assets/icon.png" alt="icon" width="100" height="100">
4+
</a>
25
<h3>SimpleHttpServer</h3>
36
<h5>A simple and efficient HTTP server for Java</h5>
47
<div>
@@ -20,8 +23,7 @@
2023

2124
<br>
2225

23-
> **Warning**:
24-
> simplehttpserver5 is not compatible with any previous version of [simplehttpserver](https://github.com/Ktt-Development/simplehttpserver)
26+
> ⚠️ simplehttpserver5 is not compatible with any previous version of [simplehttpserver](https://github.com/Ktt-Development/simplehttpserver)
2527
2628
🚧 WIP
2729

assets/icon.png

915 KB
Loading

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
<exclude/>
248248
</excludes>
249249
<trimStackTrace>false</trimStackTrace>
250+
<reuseForks>false</reuseForks>
250251
</configuration>
251252
</plugin>
252253
</plugins>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dev.katsute.simplehttpserver.exchange;
2+
3+
final class ExchangeIOTests {
4+
5+
// https://github.com/Ktt-Development/simplehttpserver/tree/main/src/test/java/com/kttdevelopment/simplehttpserver/simplehttpexchange/io
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dev.katsute.simplehttpserver.handler;
2+
3+
final class FileHandlerTests {
4+
5+
// https://github.com/Ktt-Development/simplehttpserver/tree/main/src/test/java/com/kttdevelopment/simplehttpserver/handlers/file
6+
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.katsute.simplehttpserver.server;
2+
3+
import dev.katsute.simplehttpserver.SimpleHttpServer;
4+
import org.junit.jupiter.api.*;
5+
6+
import java.io.IOException;
7+
import java.net.BindException;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
final class ServerBindTests {
12+
13+
@Test
14+
final void testBind() throws IOException{
15+
final SimpleHttpServer server = SimpleHttpServer.create();
16+
assertNull(server.getAddress());
17+
assertDoesNotThrow(() -> server.bind(8080));
18+
assertTrue(server.getAddress().getAddress().isAnyLocalAddress());
19+
20+
// required to unbind
21+
server.start();
22+
server.stop();
23+
}
24+
25+
@Test
26+
final void testOccupied() throws IOException{
27+
final SimpleHttpServer server = SimpleHttpServer.create(8080);
28+
server.start();
29+
30+
Assertions.assertThrows(BindException.class, () -> SimpleHttpServer.create(8080));
31+
32+
server.stop();
33+
34+
Assertions.assertDoesNotThrow(() -> SimpleHttpServer.create(8080));
35+
}
36+
37+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dev.katsute.simplehttpserver.server;
2+
3+
import dev.katsute.simplehttpserver.SimpleHttpServer;
4+
import dev.katsute.simplehttpserver.SimpleHttpsServer;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.io.IOException;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
final class ServerCreateTests {
13+
14+
@Test
15+
final void testHttpCreate() throws IOException{
16+
final SimpleHttpServer server = SimpleHttpServer.create();
17+
18+
assertThrows(IllegalStateException.class, server::start);
19+
20+
server.bind(8080);
21+
assertEquals(8080, server.getAddress().getPort());
22+
23+
assertDoesNotThrow(server::start);
24+
assertThrows(IllegalStateException.class, server::start);
25+
26+
assertDoesNotThrow(() -> server.stop());
27+
assertDoesNotThrow(() -> server.stop(), "Second stop should not throw an exception");
28+
}
29+
30+
@Test
31+
final void testHttpsCreate() throws IOException{
32+
final SimpleHttpsServer server = SimpleHttpsServer.create();
33+
34+
assertThrows(IllegalStateException.class, server::start);
35+
36+
server.bind(8080);
37+
assertEquals(8080, server.getAddress().getPort());
38+
39+
assertDoesNotThrow(server::start);
40+
assertThrows(IllegalStateException.class, server::start);
41+
42+
assertDoesNotThrow(() -> server.stop());
43+
assertDoesNotThrow(() -> server.stop(), "Second stop should not throw an exception");
44+
}
45+
46+
}

src/test/java/dev/katsute/simplehttpserver/ServerTests.java renamed to src/test/java/dev/katsute/simplehttpserver/server/ServerTests.java

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package dev.katsute.simplehttpserver;
1+
package dev.katsute.simplehttpserver.server;
22

33
import com.sun.net.httpserver.HttpContext;
44
import com.sun.net.httpserver.HttpExchange;
55
import dev.katsute.simplehttpserver.*;
6-
import org.junit.jupiter.api.*;
6+
import org.junit.jupiter.api.Test;
77

88
import java.io.IOException;
9-
import java.net.BindException;
109

1110
import static org.junit.jupiter.api.Assertions.*;
1211

@@ -26,86 +25,9 @@ final void testProp() throws IOException{
2625
assertTrue(server.getContexts().isEmpty());
2726
}
2827

29-
@Nested
30-
final class BindTests {
28+
//
3129

32-
@BeforeEach
33-
final void beforeEach() throws InterruptedException{
34-
Thread.sleep(500);
35-
}
36-
37-
@Test
38-
final void testBind() throws IOException{
39-
final SimpleHttpServer server = SimpleHttpServer.create();
40-
assertNull(server.getAddress());
41-
assertDoesNotThrow(() -> server.bind(8080));
42-
assertTrue(server.getAddress().getAddress().isAnyLocalAddress());
43-
44-
// required to unbind
45-
server.start();
46-
server.stop();
47-
}
48-
49-
@Test
50-
final void testOccupied() throws IOException{
51-
final SimpleHttpServer server = SimpleHttpServer.create(8080);
52-
server.start();
53-
54-
Assertions.assertThrows(BindException.class, () -> SimpleHttpServer.create(8080));
55-
56-
server.stop();
57-
58-
Assertions.assertDoesNotThrow(() -> SimpleHttpServer.create(8080));
59-
}
60-
61-
}
62-
63-
@Nested
64-
final class CreateTests {
65-
66-
@BeforeEach
67-
final void beforeEach() throws InterruptedException{
68-
Thread.sleep(500);
69-
}
70-
71-
@Test
72-
final void testHttpCreate() throws IOException{
73-
final SimpleHttpServer server = SimpleHttpServer.create();
74-
75-
assertThrows(IllegalStateException.class, server::start);
76-
77-
server.bind(8080);
78-
assertEquals(8080, server.getAddress().getPort());
79-
80-
assertDoesNotThrow(server::start);
81-
assertThrows(IllegalStateException.class, server::start);
82-
83-
assertDoesNotThrow(() -> server.stop());
84-
assertDoesNotThrow(() -> server.stop(), "Second stop should not throw an exception");
85-
}
86-
87-
@Test
88-
final void testHttpsCreate() throws IOException{
89-
final SimpleHttpsServer server = SimpleHttpsServer.create();
90-
91-
assertThrows(IllegalStateException.class, server::start);
92-
93-
server.bind(8080);
94-
assertEquals(8080, server.getAddress().getPort());
95-
96-
assertDoesNotThrow(server::start);
97-
assertThrows(IllegalStateException.class, server::start);
98-
99-
assertDoesNotThrow(() -> server.stop());
100-
assertDoesNotThrow(() -> server.stop(), "Second stop should not throw an exception");
101-
}
102-
103-
}
104-
105-
@Nested
106-
final class ContextTests {
107-
108-
@Test
30+
@Test
10931
final void testRandomContext() throws IOException{
11032
final SimpleHttpServer server = SimpleHttpServer.create();
11133

@@ -192,6 +114,4 @@ final void testDuplicateContext() throws IOException{
192114
server.createContext("", HttpExchange::close); // supposed to throw an exception, docs are invalid
193115
}
194116

195-
}
196-
197117
}

0 commit comments

Comments
 (0)