|
| 1 | +package com.demcha.compose.engine.core; |
| 2 | + |
| 3 | +import com.demcha.compose.engine.components.content.text.TextStyle; |
| 4 | +import com.demcha.compose.engine.components.geometry.ContentSize; |
| 5 | +import com.demcha.compose.engine.measurement.TextMeasurementSystem; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | +import static org.assertj.core.api.Assertions.assertThatNullPointerException; |
| 10 | + |
| 11 | +/** |
| 12 | + * Unit coverage for the dedicated text-measurement service slot on |
| 13 | + * {@link SystemRegistry}. This seam is what lets {@code TextMeasurementSystem} |
| 14 | + * stay decoupled from {@link SystemECS}: the measurement system is a service |
| 15 | + * provider exposed on demand, not a {@code process()}-driven ECS system, so it is |
| 16 | + * held out-of-band from the {@code systems} map. |
| 17 | + */ |
| 18 | +class SystemRegistryTest { |
| 19 | + |
| 20 | + @Test |
| 21 | + void textMeasurementIsEmptyWhenNoneRegistered() { |
| 22 | + assertThat(new SystemRegistry().textMeasurement()).isEmpty(); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + void registerTextMeasurementExposesTheSameInstance() { |
| 27 | + SystemRegistry registry = new SystemRegistry(); |
| 28 | + TextMeasurementSystem service = new StubMeasurement(); |
| 29 | + |
| 30 | + registry.registerTextMeasurement(service); |
| 31 | + |
| 32 | + assertThat(registry.textMeasurement()).containsSame(service); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void registerTextMeasurementRejectsNull() { |
| 37 | + assertThatNullPointerException() |
| 38 | + .isThrownBy(() -> new SystemRegistry().registerTextMeasurement(null)) |
| 39 | + .withMessageContaining("textMeasurement"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void measurementServiceIsNotEnrolledAsAProcessDrivenSystem() { |
| 44 | + SystemRegistry registry = new SystemRegistry(); |
| 45 | + |
| 46 | + registry.registerTextMeasurement(new StubMeasurement()); |
| 47 | + |
| 48 | + // It must stay out of the SystemECS map so the processSystems() loop never |
| 49 | + // calls process() on it — that is the whole point of the dedicated slot. |
| 50 | + assertThat(registry.getStream().toList()).isEmpty(); |
| 51 | + } |
| 52 | + |
| 53 | + private static final class StubMeasurement implements TextMeasurementSystem { |
| 54 | + @Override |
| 55 | + public ContentSize measure(TextStyle style, String text) { |
| 56 | + return new ContentSize(0.0, 0.0); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public LineMetrics lineMetrics(TextStyle style) { |
| 61 | + return new LineMetrics(0.0, 0.0, 0.0); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments