Class FakeRestate

java.lang.Object
dev.restate.sdk.fake.FakeRestate

@Experimental public final class FakeRestate extends Object
Fake Restate environment for testing handlers using the new reflection API.

This class provides utility methods to execute service methods that use the new reflection API (without explicit Context parameters) in a fake Restate context for testing purposes.

Example usage:


 @Test
 public void testGreeter() {
     GreeterService greeter = new GreeterService();

     // Execute the service method in a fake Restate context
     String response = FakeRestate.execute(() -> greeter.greet(new Greeting("Francesco")));

     assertEquals("You said hi to Francesco!", response);
 }
 

For advanced scenarios, you can customize the context behavior using ContextExpectations:


 @Test
 public void testWithExpectations() {
     GreeterService greeter = new GreeterService();

     ContextExpectations expectations = new ContextExpectations()
         .withRandom(new Random(42));

     String response = FakeRestate.execute(expectations, () -> greeter.greet(new Greeting("Alice")));

     assertEquals("Expected response", response);
 }
 
  • Constructor Details

    • FakeRestate

      public FakeRestate()
  • Method Details

    • execute

      public static void execute(ThrowingRunnable runnable)
      Execute a runnable in a fake Restate context with default expectations.
      Parameters:
      runnable - the code to execute
    • execute

      public static void execute(ContextExpectations expectations, ThrowingRunnable runnable)
      Execute a runnable in a fake Restate context with custom expectations.
      Parameters:
      expectations - the context expectations to use
      runnable - the code to execute
    • execute

      public static <T> T execute(ThrowingSupplier<T> runnable)
      Execute a supplier in a fake Restate context with default expectations and return the result.
      Type Parameters:
      T - the return type
      Parameters:
      runnable - the code to execute
      Returns:
      the result of the supplier
    • execute

      public static <T> T execute(ContextExpectations expectations, ThrowingSupplier<T> runnable)
      Execute a supplier in a fake Restate context with custom expectations and return the result.
      Type Parameters:
      T - the return type
      Parameters:
      expectations - the context expectations to use
      runnable - the code to execute
      Returns:
      the result of the supplier