i want mock only one function on a real service, this is Injected via @Autowired (Integration Test) ->
@SpringBootTest(classes = OrderitBackendApp.class)
@ExtendWith(MockitoExtension.class)
@AutoConfigureMockMvc
@WithUserDetails
public class OrderResourceIT {
@Autowired
private OrderRepository orderRepository;
...mor Injections and Tests
Here the mock functionalty ->
@BeforeEach
public void initTest() {
MockitoAnnotations.initMocks(this);
order = createEntity(em);
OrderService spy = spy(orderService);
when(spy.priceIsIncorrect(any())).thenReturn(false);
}
But this and a few other things that i tried didnt work. What is the right way to do it ?
question from:
https://stackoverflow.com/questions/65887972/mockito-spring-mock-only-one-function-from-autowired-service 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…