Hi all I am completely new to spring-boot and Junit Mockito I am trying to check if my method is throwing a correct exception Below is the method from my service class
    public Optional<User> getUserByEmail(String emailaddress) {
    System.out.println("From DB");
    Optional<User> user = userDao.findByEmailAddress(emailaddress);
    user.orElseThrow(() -> new BadRequestException("User Not Found"));
    return user;
}
Below is my Test Method
    @Test
@DisplayName("TextCase to check if We are able to get Correct User")
public void getUserByEmailExceptionTest() {
    Mockito.when(userDao.findByEmailAddress("mokal006@gmail.com"))
    .thenThrow(UserNotFoundException.class);
     assertThrows(UserNotFoundException.class, () -> {
        LibraryUserDetailsService.getUserByEmail("mokal006@gmail.com");
    });
    
    
}
Now, this test is getting passed even if I am throwing the wrong exception in the actual method.
 
    