File tree Expand file tree Collapse file tree
problem4j-spring-webflux/src/test/java/io/github/problem4j/spring/webflux
problem4j-spring-webmvc/src/test/java/io/github/problem4j/spring/webmvc Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11distributionBase =GRADLE_USER_HOME
22distributionPath =wrapper/dists
3- distributionUrl =https\://services.gradle.org/distributions/gradle-9.4 .1-bin.zip
3+ distributionUrl =https\://services.gradle.org/distributions/gradle-9.5 .1-bin.zip
44networkTimeout =10000
5+ retries =0
6+ retryBackOffMs =500
57validateDistributionUrl =true
68zipStoreBase =GRADLE_USER_HOME
79zipStorePath =wrapper/dists
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025-2026 The Problem4J Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io .github .problem4j .spring .webflux .app .problem ;
18+
19+ import io .github .problem4j .core .ProblemMapping ;
20+ import org .springframework .http .HttpStatus ;
21+ import org .springframework .web .bind .annotation .ResponseStatus ;
22+
23+ @ ResponseStatus (HttpStatus .FORBIDDEN )
24+ @ ProblemMapping (status = 418 , title = "Both Annotated Exception" )
25+ public class BothAnnotatedException extends RuntimeException {}
Original file line number Diff line number Diff line change 1616
1717package io .github .problem4j .spring .webflux .app .rest ;
1818
19+ import io .github .problem4j .spring .webflux .app .problem .BothAnnotatedException ;
1920import io .github .problem4j .spring .webflux .app .problem .ForbiddenAnnotatedException ;
2021import io .github .problem4j .spring .webflux .app .problem .ReasonAnnotatedException ;
2122import org .springframework .web .bind .annotation .GetMapping ;
@@ -35,4 +36,9 @@ public String responseStatusAnnotated() {
3536 public String reasonAnnotated () {
3637 throw new ReasonAnnotatedException ();
3738 }
39+
40+ @ GetMapping ("/both-annotated" )
41+ public String bothAnnotated () {
42+ throw new BothAnnotatedException ();
43+ }
3844}
Original file line number Diff line number Diff line change @@ -65,4 +65,19 @@ void givenSpringNativeResponseStatusAnnotationWithReason_shouldReturnProblem() {
6565 .value (v -> assertThat (v ).isNotNull ())
6666 .isEqualTo (Problem .of (HttpStatus .FORBIDDEN .value (), "this is reason" ));
6767 }
68+
69+ @ Test
70+ void givenBothResponseStatusAndProblemMappingAnnotations_shouldPreferProblemMapping () {
71+ webTestClient
72+ .get ()
73+ .uri ("/response-status-annotated/both-annotated" )
74+ .exchange ()
75+ .expectStatus ()
76+ .isEqualTo (HttpStatus .valueOf (418 ))
77+ .expectHeader ()
78+ .contentType (Problem .CONTENT_TYPE )
79+ .expectBody (Problem .class )
80+ .value (v -> assertThat (v ).isNotNull ())
81+ .isEqualTo (Problem .builder ().status (418 ).title ("Both Annotated Exception" ).build ());
82+ }
6883}
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025-2026 The Problem4J Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io .github .problem4j .spring .webmvc .app .problem ;
18+
19+ import io .github .problem4j .core .ProblemMapping ;
20+ import org .springframework .http .HttpStatus ;
21+ import org .springframework .web .bind .annotation .ResponseStatus ;
22+
23+ @ ResponseStatus (HttpStatus .FORBIDDEN )
24+ @ ProblemMapping (status = 418 , title = "Both Annotated Exception" )
25+ public class BothAnnotatedException extends RuntimeException {}
Original file line number Diff line number Diff line change 1616
1717package io .github .problem4j .spring .webmvc .app .rest ;
1818
19+ import io .github .problem4j .spring .webmvc .app .problem .BothAnnotatedException ;
1920import io .github .problem4j .spring .webmvc .app .problem .ForbiddenAnnotatedException ;
2021import io .github .problem4j .spring .webmvc .app .problem .ReasonAnnotatedException ;
2122import org .springframework .web .bind .annotation .GetMapping ;
@@ -35,4 +36,9 @@ public String responseStatusAnnotated() {
3536 public String reasonAnnotated () {
3637 throw new ReasonAnnotatedException ();
3738 }
39+
40+ @ GetMapping ("/both-annotated" )
41+ public String bothAnnotated () {
42+ throw new BothAnnotatedException ();
43+ }
3844}
Original file line number Diff line number Diff line change @@ -65,4 +65,18 @@ void givenSpringNativeResponseStatusAnnotationWithReason_shouldReturnProblem() {
6565
6666 assertThat (problem ).isEqualTo (Problem .of (HttpStatus .FORBIDDEN .value (), "this is reason" ));
6767 }
68+
69+ @ Test
70+ void givenBothResponseStatusAndProblemMappingAnnotations_shouldPreferProblemMapping () {
71+ ResponseEntity <String > response =
72+ restTemplate .getForEntity ("/response-status-annotated/both-annotated" , String .class );
73+
74+ assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .valueOf (418 ));
75+ assertThat (response .getHeaders ().getContentType ()).hasToString (Problem .CONTENT_TYPE );
76+
77+ Problem problem = jsonMapper .readValue (response .getBody (), Problem .class );
78+
79+ assertThat (problem )
80+ .isEqualTo (Problem .builder ().status (418 ).title ("Both Annotated Exception" ).build ());
81+ }
6882}
You can’t perform that action at this time.
0 commit comments