From 3a734b84705ccb8174e9cf24b74d7a3c3b2c1beb Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 11 Oct 2026 19:28:04 +0300 Subject: ui-fx: move the JavaFX UI into a module that sees only the api Exercise 3 asks for a new desktop client that reuses the Exercise 2 screens, and the course asks that clients depend on the DTO contract, never on the engine. ui-desktop mixed both: its views and controllers only talk to the api interfaces, but AppView and AppState each had a convenience constructor that built a ServiceEngine, which tied every UI class to the service module. Move the screens, controllers, components, FXML, skins and fonts into a new ui-fx module that depends on api alone. Packages are unchanged, so FXML controller names and resource paths keep working as they are. ui-desktop keeps only the Exercise 2 app: Launcher, App, which now builds the ServiceEngine and passes its contexts in, and ServiceEngine itself. The Exercise 3 client can then reuse ui-fx with remote contexts and never put the engine on its classpath. The build proves the split: ui-fx compiles with nothing but api visible. Tests move with the code they cover. AppStateTest drives the real engine, so it stays in ui-desktop. --- .../java/market/guess/ui/desktop/AnimTest.java | 70 ---------------------- .../java/market/guess/ui/desktop/AppStateTest.java | 4 +- .../java/market/guess/ui/desktop/ChartsTest.java | 32 ---------- .../java/market/guess/ui/desktop/FormatTest.java | 29 --------- 4 files changed, 3 insertions(+), 132 deletions(-) delete mode 100644 ui-desktop/src/test/java/market/guess/ui/desktop/AnimTest.java delete mode 100644 ui-desktop/src/test/java/market/guess/ui/desktop/ChartsTest.java delete mode 100644 ui-desktop/src/test/java/market/guess/ui/desktop/FormatTest.java (limited to 'ui-desktop/src/test/java') diff --git a/ui-desktop/src/test/java/market/guess/ui/desktop/AnimTest.java b/ui-desktop/src/test/java/market/guess/ui/desktop/AnimTest.java deleted file mode 100644 index 1a39ba1..0000000 --- a/ui-desktop/src/test/java/market/guess/ui/desktop/AnimTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package market.guess.ui.desktop; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import market.guess.ui.desktop.components.graphic.GraphicHelper; -import market.guess.ui.desktop.components.graphic.MarketChartGraphic; -import market.guess.ui.desktop.components.graphic.Motion; -import market.guess.ui.desktop.components.graphic.SparklineGraphic; -import org.junit.jupiter.api.Test; - -/** - * The handoff requires "animations off" to show the frozen final frame, fully legible and never - * blank. Since every graphic renders as a function of progress, that contract is exactly: at - * progress 1, every driver lands on its designed end value. - */ -class AnimTest { - private static final double[] BAR1 = {0, .35, .30, 1, .60, .6, 1, .35}; - - @Test - void keyframesHoldTheirEndValue() { - assertEquals(.35, GraphicHelper.at(0, BAR1), 1e-9); - assertEquals(1.0, GraphicHelper.at(.30, BAR1), 1e-9); - assertEquals(.35, GraphicHelper.at(1, BAR1), 1e-9); - assertEquals(.675, GraphicHelper.at(.15, BAR1), 1e-9); // interpolates linearly between stops - assertEquals(.35, Motion.at(0, BAR1), 1e-9); - } - - @Test - void ridersEndOnTheLastPointOfTheirPath() { - assertEquals( - MarketChartGraphic.YES_CURVE[6], - MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 1)[0], - 1e-6); - assertEquals( - MarketChartGraphic.YES_CURVE[7], - MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 1)[1], - 1e-6); - - int last = SparklineGraphic.SPARK.length; - assertEquals( - SparklineGraphic.SPARK[last - 2], - SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 1)[0], - 1e-6); - assertEquals( - SparklineGraphic.SPARK[last - 1], - SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 1)[1], - 1e-6); - } - - @Test - void ridersStartOnTheFirstPointOfTheirPath() { - assertEquals( - MarketChartGraphic.YES_CURVE[0], - MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 0)[0], - 1e-6); - assertEquals( - MarketChartGraphic.YES_CURVE[1], - MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 0)[1], - 1e-6); - - assertEquals( - SparklineGraphic.SPARK[0], - SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 0)[0], - 1e-6); - assertEquals( - SparklineGraphic.SPARK[1], - SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 0)[1], - 1e-6); - } -} diff --git a/ui-desktop/src/test/java/market/guess/ui/desktop/AppStateTest.java b/ui-desktop/src/test/java/market/guess/ui/desktop/AppStateTest.java index dbb1762..61dd854 100644 --- a/ui-desktop/src/test/java/market/guess/ui/desktop/AppStateTest.java +++ b/ui-desktop/src/test/java/market/guess/ui/desktop/AppStateTest.java @@ -28,7 +28,9 @@ class AppStateTest { var res = engine.getCatalogContext().loadEvents(path); assertTrue(res.isSuccess(), "Loading small.xml should succeed"); catalog = engine.getCatalogContext(); - state = new AppState(engine); + state = + new AppState( + engine.getCatalogContext(), engine.getMarketContext(), engine.getAccountContext()); state.setLoadedFile(path.toString()); state.refreshData(); } diff --git a/ui-desktop/src/test/java/market/guess/ui/desktop/ChartsTest.java b/ui-desktop/src/test/java/market/guess/ui/desktop/ChartsTest.java deleted file mode 100644 index c5cb280..0000000 --- a/ui-desktop/src/test/java/market/guess/ui/desktop/ChartsTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package market.guess.ui.desktop; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import market.guess.ui.desktop.util.Charts; -import org.junit.jupiter.api.Test; - -class ChartsTest { - - @Test - void testToEpochSecondFromIndex() { - double t0 = Charts.toEpochSecond(0); - double t1 = Charts.toEpochSecond(1); - double t2 = Charts.toEpochSecond(2); - - assertEquals(Charts.BASE_TIME, t0, 1e-6); - assertEquals(Charts.BASE_TIME + 1800, t1, 1e-6); - assertEquals(Charts.BASE_TIME + 3600, t2, 1e-6); - } - - @Test - void testToEpochSecondIdempotentForTimestamps() { - long epoch = 1_700_000_000L; - assertEquals(epoch, Charts.toEpochSecond(epoch), 1e-6); - } - - @Test - void testBaseTimeIsReasonable() { - assertTrue(Charts.BASE_TIME > 1_700_000_000L); - } -} diff --git a/ui-desktop/src/test/java/market/guess/ui/desktop/FormatTest.java b/ui-desktop/src/test/java/market/guess/ui/desktop/FormatTest.java deleted file mode 100644 index 956a322..0000000 --- a/ui-desktop/src/test/java/market/guess/ui/desktop/FormatTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package market.guess.ui.desktop; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.math.BigDecimal; -import market.guess.ui.desktop.util.Format; -import org.junit.jupiter.api.Test; - -class FormatTest { - - @Test - void testMoneyFormatting() { - assertEquals("$0.00", Format.money((BigDecimal) null)); - assertEquals("$0.00", Format.money(BigDecimal.ZERO)); - assertEquals("$0.50", Format.money(new BigDecimal("0.50"))); - assertEquals("$123.45", Format.money(new BigDecimal("123.45"))); - assertEquals("-$5.00", Format.money(new BigDecimal("-5.00"))); - assertEquals("$100.00", Format.money(100.0)); - assertEquals("-$2.50", Format.money(-2.50)); - } - - @Test - void testProbFormatting() { - assertEquals("0.50", Format.prob(0.50)); - assertEquals("0.75", Format.prob(0.751)); - assertEquals("0.00", Format.prob(0.00)); - assertEquals("1.00", Format.prob(1.00)); - } -} -- cgit v1.2.3