|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertSame; |
5 | 6 |
|
6 | 7 | import org.junit.jupiter.api.Test; |
7 | 8 |
|
@@ -144,4 +145,53 @@ void givenProblemWithSpecialCharacters_whenCreatingException_thenSpecialCharacte |
144 | 145 | "Validation Error: Required Fields Missing: Fields 'name' & 'email' are required (check docs) (code: 422)", |
145 | 146 | exception.getMessage()); |
146 | 147 | } |
| 148 | + |
| 149 | + @Test |
| 150 | + void givenCtor_whenCreatingProblemException_problemIsNotRecreated() { |
| 151 | + Problem problem = Problem.builder().title("Bad Request").status(400).build(); |
| 152 | + |
| 153 | + ProblemException exception = new ProblemException(problem); |
| 154 | + |
| 155 | + assertSame(problem, exception.getProblem()); |
| 156 | + } |
| 157 | + |
| 158 | + @Test |
| 159 | + void givenCtorWithMessage_whenCreatingProblemException_problemIsNotRecreated() { |
| 160 | + Problem problem = Problem.builder().title("Bad Request").status(400).build(); |
| 161 | + |
| 162 | + ProblemException exception = new ProblemException("this is a message", problem); |
| 163 | + |
| 164 | + assertSame(problem, exception.getProblem()); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + void givenCtorWithCause_whenCreatingProblemException_problemIsNotRecreated() { |
| 169 | + Problem problem = Problem.builder().title("Bad Request").status(400).build(); |
| 170 | + Throwable cause = new RuntimeException("root cause"); |
| 171 | + |
| 172 | + ProblemException exception = new ProblemException(problem, cause); |
| 173 | + |
| 174 | + assertSame(problem, exception.getProblem()); |
| 175 | + } |
| 176 | + |
| 177 | + @Test |
| 178 | + void givenCtorWithMessageAndCause_whenCreatingProblemException_problemIsNotRecreated() { |
| 179 | + Problem problem = Problem.builder().title("Bad Request").status(400).build(); |
| 180 | + Throwable cause = new RuntimeException("root cause"); |
| 181 | + |
| 182 | + ProblemException exception = new ProblemException("this is a message", problem, cause); |
| 183 | + |
| 184 | + assertSame(problem, exception.getProblem()); |
| 185 | + } |
| 186 | + |
| 187 | + @Test |
| 188 | + void givenCtorWithParameters_whenCreatingProblemException_problemIsNotRecreated() { |
| 189 | + Problem problem = Problem.builder().title("Bad Request").status(400).build(); |
| 190 | + Throwable cause = new RuntimeException("root cause"); |
| 191 | + |
| 192 | + ProblemException exception = |
| 193 | + new ProblemException("this is a message", problem, cause, false, true); |
| 194 | + |
| 195 | + assertSame(problem, exception.getProblem()); |
| 196 | + } |
147 | 197 | } |
0 commit comments