T
T
thereisnonickname2020-05-14 21:01:49
Java
thereisnonickname, 2020-05-14 21:01:49

Mockito. Is it possible to lock a method call inside another method?

There is an endpoint:

@PostMapping("/some/endpoint")
    public void storeData(@Valid @RequestBody SomeMessageDTO data) {
        UUID id = data.getDeviceId();
        validateDeviceAccess(id);
        this.saveData(data);
    }


The called validateDeviceAccess method throws an exception if the device with the passed id is inactive. If active, then control is transferred to this.saveData(data);

Question: Is it possible to simulate throwing an exception using the validateDeviceAccess method using Mockito?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-05-14
@thereisnonickname

You can use spy .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question