- 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.Methods inherited from interface io.avaje.inject.BeanScopeBuilder
addPostConstruct, addPostConstruct, addPreDestroy, addPreDestroy, bean, bean, bean, bean, beans, build, classLoader, forTesting, modules, parent, parent, profiles, propertyPlugin, propertyPlugin, provideDefault, provideDefault, shutdownHook
-
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(); }
-
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()) { ... }
-
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(); }
-
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(); }
-
spy
Register a Mockito spy with a qualifier name.try (BeanScope scope = BeanScope.builder() .forTesting() .spy(Store.class, "red") .spy(Store.class, "blue") .build()) { ... }
-
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(); }
-