Issue
I am getting a nested exception like below for my Junit tests:
Caused by: com.exception.Test1RestException: operation failed for test1
at com.testController.tests(Test1Controller.java:123)
............................
Caused by: com.exception.Test2Exception: operation failed for test2
at com.testController.tests(Test2Controller.java:456)
.............................
Caused by: com.exception.Test3RestException: operation failed for test3
at com.testController.tests(Test2Controller.java:789)
I want to verify "operation failed for test3 " using mockmvc,used below
code for that
org.assertj.core.api.Assertions
.assertThatThrownBy(() ->
mockMvc.perform(fileUpload("/test/abc").file((MockMultipartFile) files))
.andExpect(status().isOk()))
.hasMessageContaining(operation failed for test3)
But I am getting expected error message as "operation failed for test1",any pointers to reach till bottom message here from my junit
Solution
it worked by using .hasStackTraceContaining(message) ,method call
Answered By - Anand