View Javadoc
1   package com.guinetik.hexafun.testing;
2   
3   import com.guinetik.hexafun.HexaApp;
4   
5   /**
6    * Entry point for the HexaFun testing DSL.
7    * Provides a fluent API for testing use cases in a HexaApp.
8    */
9   public class HexaTest {
10      private final HexaApp app;
11  
12      private HexaTest(HexaApp app) {
13          this.app = app;
14      }
15  
16      /**
17       * Create a new HexaTest for the given app.
18       * @param app The HexaApp to test
19       * @return A new HexaTest instance
20       */
21      public static HexaTest forApp(HexaApp app) {
22          return new HexaTest(app);
23      }
24  
25      /**
26       * Start testing a use case.
27       * @param useCaseName Name of the use case to test
28       * @param <I> Input type of the use case
29       * @param <O> Output type of the use case
30       * @return A new UseCaseTest instance
31       */
32      public <I, O> UseCaseTest<I, O> useCase(String useCaseName) {
33          return new UseCaseTest<>(app, useCaseName);
34      }
35      
36      /**
37       * Start a test for the specified use case.
38       * Simply a shorter method name for useCase() to better match the example in the README.
39       * @param useCaseName Name of the use case to test
40       * @param <I> Input type of the use case
41       * @param <O> Output type of the use case
42       * @return A new UseCaseTest instance
43       */
44      public <I, O> UseCaseTest<I, O> test(String useCaseName) {
45          return useCase(useCaseName);
46      }
47  
48      /**
49       * Verify that a use case exists in the app.
50       * @param useCaseName Name of the use case to check
51       * @return This HexaTest instance
52       * @throws AssertionError if the use case doesn't exist
53       */
54      public HexaTest hasUseCase(String useCaseName) {
55          if (!app.registeredUseCases().contains(useCaseName)) {
56              throw new AssertionError("Expected use case '" + useCaseName + "' to exist, but it doesn't");
57          }
58          return this;
59      }
60  
61      /**
62       * Verify that a use case does not exist in the app.
63       * @param useCaseName Name of the use case to check
64       * @return This HexaTest instance
65       * @throws AssertionError if the use case exists
66       */
67      public HexaTest doesNotHaveUseCase(String useCaseName) {
68          if (app.registeredUseCases().contains(useCaseName)) {
69              throw new AssertionError("Expected use case '" + useCaseName + "' to not exist, but it does");
70          }
71          return this;
72      }
73  }