How would you use Mockito to simulate the throwing of an exception by a method?
- Use doThrow(Exception.class).when(mockedObject).methodCall()
- Use expect(exception).when(mockedObject).methodCall()
- Use mockedObject.throwException(Exception.class)
- Use when(methodCall).thenThrow(Exception.class)
In Mockito, you can simulate the throwing of an exception by a method using doThrow(Exception.class).when(mockedObject).methodCall(). This sets up the behavior that when methodCall is invoked on mockedObject, it will throw the specified exception.
Loading...
Related Quiz
- The _____ annotation in Spring Boot is used to provide global exception handling across all @Controller classes.
- What is the significance of the “spring.factories” file in creating custom Auto Configuration?
- Your application needs to communicate with multiple external services, each requiring different OAuth2 credentials. How would you manage and secure these credentials and configure the OAuth2 clients in your Spring Boot application?
- The _____ annotation in Spring Boot includes several other annotations, such as @Configuration, @EnableAutoConfiguration, and @ComponentScan.
- How can you manage bean lifecycle events, such as initialization and destruction, in Spring Boot?