Skip to content

Commit 52f5b56

Browse files
committed
feat: Add Dependency record for health responses
1 parent 780a529 commit 52f5b56

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.retailsvc.http;
2+
3+
import java.util.Objects;
4+
5+
/**
6+
* A single dependency entry within a {@link HealthOutcome}.
7+
*
8+
* @param id stable identifier of the dependency (e.g. {@code "jdbc"})
9+
* @param status free-form status; {@code "Up"} (case-insensitive) is treated as healthy by {@link
10+
* HealthOutcome#isUp()}; any other value is treated as unhealthy
11+
*/
12+
public record Dependency(String id, String status) {
13+
public Dependency {
14+
Objects.requireNonNull(id, "id");
15+
Objects.requireNonNull(status, "status");
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.retailsvc.http;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class DependencyTest {
9+
10+
@Test
11+
void holdsIdAndStatus() {
12+
Dependency d = new Dependency("jdbc", "Up");
13+
assertThat(d.id()).isEqualTo("jdbc");
14+
assertThat(d.status()).isEqualTo("Up");
15+
}
16+
17+
@Test
18+
void rejectsNullId() {
19+
assertThatNullPointerException()
20+
.isThrownBy(() -> new Dependency(null, "Up"))
21+
.withMessageContaining("id");
22+
}
23+
24+
@Test
25+
void rejectsNullStatus() {
26+
assertThatNullPointerException()
27+
.isThrownBy(() -> new Dependency("jdbc", null))
28+
.withMessageContaining("status");
29+
}
30+
}

0 commit comments

Comments
 (0)