I have a @Component
class that contains some @Inject
components to perform some code logic. In my Test, I would like to execute that logic instead Mock the results. I don't want to import spring-boot-starter-test
because will overload the dependencies and generate conflicts.
The Service1
and Service2
doesn't use any third services, it's has just executed simple logic.
@Component
public class MainService {
@Inject
private Service1 service1;
@Inject
private Service2 service2;
}
---------------- Test Class ----------------
@RunWith(MockitoJUnitRunner.class)
public class SomeTest {
@Mock
private Service1 service1;
@Mock
private Service2 service2;
@InjectMocks
private MainService mainService;
@Before
public void startUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void test1() {
Mockito.when(service1.function).thenReturn(...);
Mockito.when(service2.function).thenReturn(...);
// How to provide real execution instead Mock the results?
mainService.start();
// asserts...
}
}