|
| 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 java.util.ArrayList; |
| 7 | +import java.util.List; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +class HealthOutcomeTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + void exposesOutcomeAndDependencies() { |
| 14 | + HealthOutcome o = new HealthOutcome("Up", List.of(new Dependency("jdbc", "Up"))); |
| 15 | + assertThat(o.outcome()).isEqualTo("Up"); |
| 16 | + assertThat(o.dependencies()).containsExactly(new Dependency("jdbc", "Up")); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + void rejectsNullOutcome() { |
| 21 | + assertThatNullPointerException() |
| 22 | + .isThrownBy(() -> new HealthOutcome(null, List.of())) |
| 23 | + .withMessageContaining("outcome"); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + void coercesNullDependenciesToEmpty() { |
| 28 | + HealthOutcome o = new HealthOutcome("Up", null); |
| 29 | + assertThat(o.dependencies()).isEmpty(); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void copiesDependencyListDefensively() { |
| 34 | + List<Dependency> mutable = new ArrayList<>(); |
| 35 | + mutable.add(new Dependency("jdbc", "Up")); |
| 36 | + HealthOutcome o = new HealthOutcome("Up", mutable); |
| 37 | + mutable.clear(); |
| 38 | + assertThat(o.dependencies()).hasSize(1); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void isUpReturnsTrueForUpCaseInsensitive() { |
| 43 | + assertThat(new HealthOutcome("Up", List.of()).isUp()).isTrue(); |
| 44 | + assertThat(new HealthOutcome("UP", List.of()).isUp()).isTrue(); |
| 45 | + assertThat(new HealthOutcome("up", List.of()).isUp()).isTrue(); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void isUpReturnsFalseForAnythingElse() { |
| 50 | + assertThat(new HealthOutcome("Down", List.of()).isUp()).isFalse(); |
| 51 | + assertThat(new HealthOutcome("", List.of()).isUp()).isFalse(); |
| 52 | + assertThat(new HealthOutcome("Degraded", List.of()).isUp()).isFalse(); |
| 53 | + } |
| 54 | +} |
0 commit comments