- All Superinterfaces:
BeanScopeBuilder
- Enclosing interface:
- 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
Modifier and TypeMethodDescriptionUse a mockito mock when injecting this bean type.Register as a Mockito mock with a qualifier name.Use a mockito mock when injecting this bean type additionally running setup on the mock instance.Use a mockito spy when injecting this bean type.Register a Mockito spy with a qualifier name.Use a mockito spy when injecting this bean type additionally running setup on the spy instance.default BeanScopeBuilder.ForTestingDeprecated.default BeanScopeBuilder.ForTestingDeprecated.default <D> BeanScopeBuilder.ForTestingDeprecated.default BeanScopeBuilder.ForTestingDeprecated.default BeanScopeBuilder.ForTestingDeprecated.default <D> BeanScopeBuilder.ForTestingDeprecated.Methods inherited from interface io.avaje.inject.BeanScopeBuilder
bean, bean, bean, bean, beans, build, forTesting, modules, parent, parent, shutdownHook, withBean, withBean, withBean, withBean, withBeans, withModules, withParent, withParent, withShutdownHook
-
Method Details
-
mock
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.Deprecated - migrate to mock(). -
mock
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.Deprecated - migrate to mock(). -
mock
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.Deprecated - migrate to mock(). -
spy
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.Deprecated - migrate to spy(). -
spy
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.Deprecated - migrate to spy(). -
spy
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.Deprecated - migrate to spy().
-