Package dev.restate.sdk.fake
Class FakeRestate
java.lang.Object
dev.restate.sdk.fake.FakeRestate
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecute(ThrowingRunnable runnable) Execute a runnable in a fake Restate context with default expectations.static <T> Texecute(ThrowingSupplier<T> runnable) Execute a supplier in a fake Restate context with default expectations and return the result.static voidexecute(ContextExpectations expectations, ThrowingRunnable runnable) Execute a runnable in a fake Restate context with custom expectations.static <T> Texecute(ContextExpectations expectations, ThrowingSupplier<T> runnable) Execute a supplier in a fake Restate context with custom expectations and return the result.
-
Constructor Details
-
FakeRestate
public FakeRestate()
-
-
Method Details
-
execute
Execute a runnable in a fake Restate context with default expectations.- Parameters:
runnable- the code to execute
-
execute
Execute a runnable in a fake Restate context with custom expectations.- Parameters:
expectations- the context expectations to userunnable- the code to execute
-
execute
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
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 userunnable- the code to execute- Returns:
- the result of the supplier
-