-
- All Superinterfaces:
BeanScopeBuilder
- Enclosing interface:
- BeanScopeBuilder
public static interface BeanScopeBuilder.ForTesting extends BeanScopeBuilder
Extends the building with testing specific support for mocks and spies.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.avaje.inject.BeanScopeBuilder
BeanScopeBuilder.ForTesting
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description BeanScopeBuilder.ForTestingmock(Class<?> type)Use a mockito mock when injecting this bean type.BeanScopeBuilder.ForTestingmock(Class<?> type, String name)Register as a Mockito mock with a qualifier name.<D> BeanScopeBuilder.ForTestingmock(Class<D> type, Consumer<D> consumer)Use a mockito mock when injecting this bean type additionally running setup on the mock instance.BeanScopeBuilder.ForTestingspy(Class<?> type)Use a mockito spy when injecting this bean type.BeanScopeBuilder.ForTestingspy(Class<?> type, String name)Register a Mockito spy with a qualifier name.<D> BeanScopeBuilder.ForTestingspy(Class<D> type, Consumer<D> consumer)Use a mockito spy when injecting this bean type additionally running setup on the spy instance.default BeanScopeBuilder.ForTestingwithMock(Class<?> type)Deprecated.default BeanScopeBuilder.ForTestingwithMock(Class<?> type, String name)Deprecated.default <D> BeanScopeBuilder.ForTestingwithMock(Class<D> type, Consumer<D> consumer)Deprecated.default BeanScopeBuilder.ForTestingwithSpy(Class<?> type)Deprecated.default BeanScopeBuilder.ForTestingwithSpy(Class<?> type, String name)Deprecated.default <D> BeanScopeBuilder.ForTestingwithSpy(Class<D> type, Consumer<D> consumer)Deprecated.-
Methods inherited from interface io.avaje.inject.BeanScopeBuilder
bean, bean, bean, bean, beans, build, classLoader, forTesting, modules, parent, parent, provideDefault, provideDefault, shutdownHook, withBean, withBean, withBean, withBean, withBeans, withModules, withParent, withParent, withShutdownHook
-
-
-
-
Method Detail
-
mock
BeanScopeBuilder.ForTesting mock(Class<?> type)
Use a mockito mock when injecting this bean type.try (BeanScope scope = BeanScope.builder() .forTesting() .mock(Pump.class) .mock(Grinder.class) .build()) { CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class); coffeeMaker.makeIt(); // this is a mockito mock Grinder grinder = scope.get(Grinder.class); verify(grinder).grindBeans(); }
-
withMock
@Deprecated default BeanScopeBuilder.ForTesting withMock(Class<?> type)
Deprecated.Deprecated - migrate to mock().
-
mock
BeanScopeBuilder.ForTesting mock(Class<?> type, String name)
Register as a Mockito mock with a qualifier name.try (BeanScope scope = BeanScope.builder() .forTesting() .mock(Store.class, "red") .mock(Store.class, "blue") .build()) { ... }
-
withMock
@Deprecated default BeanScopeBuilder.ForTesting withMock(Class<?> type, String name)
Deprecated.Deprecated - migrate to mock().
-
mock
<D> BeanScopeBuilder.ForTesting mock(Class<D> type, Consumer<D> consumer)
Use a mockito mock when injecting this bean type additionally running setup on the mock instance.try (BeanScope scope = BeanScope.builder() .forTesting() .mock(Pump.class) .mock(Grinder.class, grinder -> { // setup the mock when(grinder.grindBeans()).thenReturn("stub response"); }) .build()) { CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class); coffeeMaker.makeIt(); // this is a mockito mock Grinder grinder = scope.get(Grinder.class); verify(grinder).grindBeans(); }
-
withMock
@Deprecated default <D> BeanScopeBuilder.ForTesting withMock(Class<D> type, Consumer<D> consumer)
Deprecated.Deprecated - migrate to mock().
-
spy
BeanScopeBuilder.ForTesting spy(Class<?> type)
Use a mockito spy when injecting this bean type.try (BeanScope scope = BeanScope.builder() .forTesting() .spy(Pump.class) .build()) { // setup spy here ... Pump pump = scope.get(Pump.class); doNothing().when(pump).pumpSteam(); // act CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class); coffeeMaker.makeIt(); verify(pump).pumpWater(); verify(pump).pumpSteam(); }
-
withSpy
@Deprecated default BeanScopeBuilder.ForTesting withSpy(Class<?> type)
Deprecated.Deprecated - migrate to spy().
-
spy
BeanScopeBuilder.ForTesting spy(Class<?> type, String name)
Register a Mockito spy with a qualifier name.try (BeanScope scope = BeanScope.builder() .forTesting() .spy(Store.class, "red") .spy(Store.class, "blue") .build()) { ... }
-
withSpy
@Deprecated default BeanScopeBuilder.ForTesting withSpy(Class<?> type, String name)
Deprecated.Deprecated - migrate to spy().
-
spy
<D> BeanScopeBuilder.ForTesting spy(Class<D> type, Consumer<D> consumer)
Use a mockito spy when injecting this bean type additionally running setup on the spy instance.try (BeanScope scope = BeanScope.builder() .forTesting() .spy(Pump.class, pump -> { // setup the spy doNothing().when(pump).pumpWater(); }) .build()) { // or setup here ... Pump pump = scope.get(Pump.class); doNothing().when(pump).pumpSteam(); // act CoffeeMaker coffeeMaker = scope.get(CoffeeMaker.class); coffeeMaker.makeIt(); verify(pump).pumpWater(); verify(pump).pumpSteam(); }
-
withSpy
@Deprecated default <D> BeanScopeBuilder.ForTesting withSpy(Class<D> type, Consumer<D> consumer)
Deprecated.Deprecated - migrate to spy().
-
-