33import org .junit .jupiter .api .Test ;
44
55import java .io .ByteArrayInputStream ;
6+ import java .io .InputStream ;
67import java .nio .charset .StandardCharsets ;
78
89import static org .junit .jupiter .api .Assertions .*;
@@ -24,6 +25,10 @@ void loadsValuesFromYaml() {
2425 root-dir: "public"
2526 logging:
2627 level: "DEBUG"
28+ rate-limiting:
29+ enabled: true
30+ requests-per-minute: 20
31+ burst-capacity: 10
2732 """ ;
2833
2934 ConfigLoader loader = new ConfigLoader (
@@ -33,6 +38,9 @@ void loadsValuesFromYaml() {
3338 assertEquals (9090 , loader .getPort ());
3439 assertEquals ("public" , loader .getRootDirectory ());
3540 assertEquals ("DEBUG" , loader .getLogLevel ());
41+ assertTrue (loader .isRateLimitingEnabled ());
42+ assertEquals (20 , loader .getRequestsPerMinute ());
43+ assertEquals (10 , loader .getBurstCapacity ());
3644 }
3745
3846 /**
@@ -46,6 +54,7 @@ void usesDefaultsWhenServerKeysMissing() {
4654 String yaml = """
4755 server: {}
4856 logging: {}
57+ rate-limiting: {}
4958 """ ;
5059
5160 ConfigLoader loader = new ConfigLoader (
@@ -55,6 +64,7 @@ void usesDefaultsWhenServerKeysMissing() {
5564 assertEquals (8080 , loader .getPort ());
5665 assertEquals ("static" , loader .getRootDirectory ());
5766 assertEquals ("INFO" , loader .getLogLevel ());
67+ assertFalse (loader .isRateLimitingEnabled ());
5868 }
5969
6070
@@ -67,5 +77,18 @@ void usesDefaultsWhenServerKeysMissing() {
6777 @ Test void throwsWhenYamlMissing () {
6878 assertThrows (RuntimeException .class , () ->
6979 new ConfigLoader (null ) ); }
80+
81+ @ Test
82+ void shouldThrowWhenYamlIsMalformed () {
83+ String yaml = "server:\n BadYaml" ;
84+ InputStream input = new ByteArrayInputStream (yaml .getBytes (StandardCharsets .UTF_8 ));
85+
86+ RuntimeException ex = assertThrows (RuntimeException .class ,
87+ () -> new ConfigLoader (input ));
88+
89+ assertTrue (ex .getMessage ().contains ("Failed to load application config" ));
90+ }
7091}
7192
93+
94+
0 commit comments