Package ratpack.guice
Class BindingsImposition
- java.lang.Object
-
- ratpack.guice.BindingsImposition
-
- All Implemented Interfaces:
Imposition
public final class BindingsImposition extends Object implements Imposition
Animposition
of additional and overridden Guice bindings, used byGuice.registry(Action)
and similar methods.This is typically used to override bindings at test time.
import ratpack.core.server.RatpackServer; import ratpack.guice.BindingsImposition; import ratpack.guice.Guice; import ratpack.core.impose.ImpositionsSpec; import ratpack.test.MainClassApplicationUnderTest; import static org.junit.jupiter.api.Assertions.assertEquals; public class Example { public static class App { public static void main(String[] args) throws Exception { RatpackServer.start(s -> s .registry(Guice.registry(r -> r.bindInstance(String.class, "foo") )) .handlers(c -> c .get(ctx -> ctx.render(ctx.get(String.class))) ) ); } } public static void main(String[] args) throws Exception { new MainClassApplicationUnderTest(App.class) { @Override protected void addImpositions(ImpositionsSpec impositions) { impositions.add(BindingsImposition.of(r -> r.bindInstance(String.class, "bar") )); } }.test(testHttpClient -> assertEquals("bar", testHttpClient.getText()) ); } }
- Since:
- 1.2
- See Also:
Impositions
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Action<? super BindingsSpec>
getBindings()
The bindings to add/override.static BindingsImposition
of(Action<? super BindingsSpec> bindings)
Creates a new bindings imposition of the given bindings.
-
-
-
Method Detail
-
getBindings
public Action<? super BindingsSpec> getBindings()
The bindings to add/override.- Returns:
- the bindings to add/override
-
of
public static BindingsImposition of(Action<? super BindingsSpec> bindings)
Creates a new bindings imposition of the given bindings.- Parameters:
bindings
- the bindings to impose- Returns:
- a new bindings imposition
-
-