Skip to content

Commit 90bd519

Browse files
Use literals in tests
1 parent 17e675b commit 90bd519

20 files changed

Lines changed: 184 additions & 277 deletions

problem4j-spring-web/src/test/java/io/github/problem4j/spring/web/DefaultBindingResultSupportTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
package io.github.problem4j.spring.web;
2323

24-
import static io.github.problem4j.spring.web.ProblemSupport.IS_NOT_VALID_ERROR;
2524
import static org.assertj.core.api.Assertions.assertThat;
2625

2726
import io.github.problem4j.spring.web.parameter.BindingResultSupport;
@@ -62,7 +61,7 @@ void givenBindingResultForBindingError_shouldResolveViolation() {
6261

6362
List<Violation> violations = support.fetchViolations(bindingResult);
6463

65-
assertThat(violations).containsExactly(new Violation("age", IS_NOT_VALID_ERROR));
64+
assertThat(violations).containsExactly(new Violation("age", "is not valid"));
6665
}
6766

6867
@Test

problem4j-spring-web/src/test/java/io/github/problem4j/spring/web/resolver/ServerWebInputProblemResolverTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import io.github.problem4j.core.Problem;
2727
import io.github.problem4j.core.ProblemContext;
28-
import io.github.problem4j.spring.web.ProblemSupport;
2928
import java.lang.reflect.Method;
3029
import org.junit.jupiter.api.BeforeEach;
3130
import org.junit.jupiter.api.Test;
@@ -68,9 +67,9 @@ void givenExceptionWithCauseAndWithoutPropertyName_shouldDelegateAndIncludeMetho
6867
.isEqualTo(
6968
Problem.builder()
7069
.status(HttpStatus.BAD_REQUEST.value())
71-
.detail(ProblemSupport.TYPE_MISMATCH_DETAIL)
72-
.extension(ProblemSupport.PROPERTY_EXTENSION, "value")
73-
.extension(ProblemSupport.KIND_EXTENSION, "boolean")
70+
.detail("Type mismatch")
71+
.extension("property", "value")
72+
.extension("kind", "boolean")
7473
.build());
7574
}
7675

@@ -92,9 +91,9 @@ void givenExceptionWithCauseAndWithoutParameter_shouldDelegateToMethodParameter(
9291
.isEqualTo(
9392
Problem.builder()
9493
.status(HttpStatus.BAD_REQUEST.value())
95-
.detail(ProblemSupport.TYPE_MISMATCH_DETAIL)
96-
.extension(ProblemSupport.PROPERTY_EXTENSION, "flag")
97-
.extension(ProblemSupport.KIND_EXTENSION, "boolean")
94+
.detail("Type mismatch")
95+
.extension("property", "flag")
96+
.extension("kind", "boolean")
9897
.build());
9998
}
10099

problem4j-spring-web/src/test/java/io/github/problem4j/spring/web/resolver/TypeMismatchProblemResolverTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import io.github.problem4j.core.Problem;
2727
import io.github.problem4j.core.ProblemContext;
28-
import io.github.problem4j.spring.web.ProblemSupport;
2928
import org.junit.jupiter.api.BeforeEach;
3029
import org.junit.jupiter.api.Test;
3130
import org.springframework.beans.TypeMismatchException;
@@ -55,9 +54,9 @@ void givenExceptionWithParameterNameAndType_shouldReturnProblemWithAll() {
5554
.isEqualTo(
5655
Problem.builder()
5756
.status(HttpStatus.BAD_REQUEST.value())
58-
.detail(ProblemSupport.TYPE_MISMATCH_DETAIL)
59-
.extension(ProblemSupport.PROPERTY_EXTENSION, "age")
60-
.extension(ProblemSupport.KIND_EXTENSION, "integer")
57+
.detail("Type mismatch")
58+
.extension("property", "age")
59+
.extension("kind", "integer")
6160
.build());
6261
}
6362

@@ -73,8 +72,8 @@ void givenExceptionWithParameterType_shouldReturnProblemWithTypeOnly() {
7372
.isEqualTo(
7473
Problem.builder()
7574
.status(HttpStatus.BAD_REQUEST.value())
76-
.detail(ProblemSupport.TYPE_MISMATCH_DETAIL)
77-
.extension(ProblemSupport.KIND_EXTENSION, "integer")
75+
.detail("Type mismatch")
76+
.extension("kind", "integer")
7877
.build());
7978
}
8079

@@ -91,8 +90,8 @@ void givenExceptionWithParameterName_shouldReturnProblemWithNameOnly() {
9190
.isEqualTo(
9291
Problem.builder()
9392
.status(HttpStatus.BAD_REQUEST.value())
94-
.detail(ProblemSupport.TYPE_MISMATCH_DETAIL)
95-
.extension(ProblemSupport.PROPERTY_EXTENSION, "field")
93+
.detail("Type mismatch")
94+
.extension("property", "field")
9695
.build());
9796
}
9897
}

problem4j-spring-webflux/src/test/java/io/github/problem4j/spring/webflux/integration/BindingPrimitiveWebFluxTest.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
package io.github.problem4j.spring.webflux.integration;
2323

24-
import static io.github.problem4j.spring.web.ProblemSupport.KIND_EXTENSION;
25-
import static io.github.problem4j.spring.web.ProblemSupport.PROPERTY_EXTENSION;
26-
import static io.github.problem4j.spring.web.ProblemSupport.TYPE_MISMATCH_DETAIL;
2724
import static org.assertj.core.api.Assertions.assertThat;
2825

2926
import io.github.problem4j.core.Problem;
@@ -139,9 +136,9 @@ void givenMalformedPrimitive_whenPost_thenReturnProblem(String path, String json
139136
Problem expected =
140137
Problem.builder()
141138
.status(HttpStatus.BAD_REQUEST.value())
142-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
143-
.extension(PROPERTY_EXTENSION, "value")
144-
.extension(KIND_EXTENSION, expectedKind)
139+
.detail("type mismatch")
140+
.extension("property", "value")
141+
.extension("kind", expectedKind)
145142
.build();
146143

147144
if (!problem.equals(expected)) {
@@ -242,9 +239,9 @@ void givenMalformedNested_whenPost_thenReturnProblem(String path, String json) {
242239
.isEqualTo(
243240
Problem.builder()
244241
.status(HttpStatus.BAD_REQUEST.value())
245-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
246-
.extension(PROPERTY_EXTENSION, "nested.value")
247-
.extension(KIND_EXTENSION, expectedKind)
242+
.detail("type mismatch")
243+
.extension("property", "nested.value")
244+
.extension("kind", expectedKind)
248245
.build());
249246
});
250247
}
@@ -288,9 +285,9 @@ void givenEmptyStringPrimitive_whenPost_thenReturnProblem(String path, String js
288285
.isEqualTo(
289286
Problem.builder()
290287
.status(HttpStatus.BAD_REQUEST.value())
291-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
292-
.extension(PROPERTY_EXTENSION, "value")
293-
.extension(KIND_EXTENSION, expectedKind)
288+
.detail("type mismatch")
289+
.extension("property", "value")
290+
.extension("kind", expectedKind)
294291
.build());
295292
});
296293
}
@@ -321,9 +318,9 @@ void givenOverflowPrimitive_whenPost_thenReturnProblem(String path, String json)
321318
Problem expected =
322319
Problem.builder()
323320
.status(HttpStatus.BAD_REQUEST.value())
324-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
325-
.extension(PROPERTY_EXTENSION, "value")
326-
.extension(KIND_EXTENSION, "integer")
321+
.detail("type mismatch")
322+
.extension("property", "value")
323+
.extension("kind", "integer")
327324
.build();
328325

329326
if (!problem.equals(expected)) {
@@ -350,9 +347,9 @@ void givenNullPrimitive_whenPost_thenReturnProblem() {
350347
Problem expected =
351348
Problem.builder()
352349
.status(HttpStatus.BAD_REQUEST.value())
353-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
354-
.extension(PROPERTY_EXTENSION, "value")
355-
.extension(KIND_EXTENSION, "integer")
350+
.detail("type mismatch")
351+
.extension("property", "value")
352+
.extension("kind", "integer")
356353
.build();
357354

358355
if (!problem.equals(expected)) {
@@ -414,9 +411,9 @@ void givenMalformedComplexObject_whenPost_thenReturnProblemWithFirstInvalidField
414411
.isEqualTo(
415412
Problem.builder()
416413
.status(HttpStatus.BAD_REQUEST.value())
417-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
418-
.extension(PROPERTY_EXTENSION, expectedProperty)
419-
.extension(KIND_EXTENSION, expectedKind)
414+
.detail("type mismatch")
415+
.extension("property", expectedProperty)
416+
.extension("kind", expectedKind)
420417
.build()));
421418
}
422419
}

problem4j-spring-webflux/src/test/java/io/github/problem4j/spring/webflux/integration/MaxUploadSizeExceededWebFluxTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
package io.github.problem4j.spring.webflux.integration;
2323

24-
import static io.github.problem4j.spring.web.ProblemSupport.MAX_EXTENSION;
25-
import static io.github.problem4j.spring.web.ProblemSupport.MAX_UPLOAD_SIZE_EXCEEDED_DETAIL;
2624
import static org.hamcrest.Matchers.notNullValue;
2725

2826
import io.github.problem4j.core.Problem;
@@ -58,8 +56,8 @@ void givenMaxUploadSizeExceeded_shouldReturnProblem() {
5856
.isEqualTo(
5957
Problem.builder()
6058
.status(HttpStatus.PAYLOAD_TOO_LARGE.value())
61-
.detail(MAX_UPLOAD_SIZE_EXCEEDED_DETAIL.toLowerCase())
62-
.extension(MAX_EXTENSION, 1)
59+
.detail("max upload size exceeded")
60+
.extension("max", 1)
6361
.build());
6462
}
6563
}

problem4j-spring-webflux/src/test/java/io/github/problem4j/spring/webflux/integration/MissingParameterWebFluxTest.java

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@
2121

2222
package io.github.problem4j.spring.webflux.integration;
2323

24-
import static io.github.problem4j.spring.web.ProblemSupport.ATTRIBUTE_EXTENSION;
25-
import static io.github.problem4j.spring.web.ProblemSupport.COOKIE_EXTENSION;
26-
import static io.github.problem4j.spring.web.ProblemSupport.HEADER_EXTENSION;
27-
import static io.github.problem4j.spring.web.ProblemSupport.KIND_EXTENSION;
28-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_COOKIE_DETAIL;
29-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_HEADER_DETAIL;
30-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_PATH_VARIABLE_DETAIL;
31-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_REQUEST_ATTRIBUTE_DETAIL;
32-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_REQUEST_PARAM_DETAIL;
33-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_REQUEST_PART_DETAIL;
34-
import static io.github.problem4j.spring.web.ProblemSupport.MISSING_SESSION_ATTRIBUTE_DETAIL;
35-
import static io.github.problem4j.spring.web.ProblemSupport.NAME_EXTENSION;
36-
import static io.github.problem4j.spring.web.ProblemSupport.PARAM_EXTENSION;
3724
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
3825
import static org.hamcrest.Matchers.notNullValue;
3926

@@ -77,8 +64,8 @@ void givenRequestWithoutPathVariable_shouldReturnProblem() {
7764
.isEqualTo(
7865
Problem.builder()
7966
.status(HttpStatus.BAD_REQUEST.value())
80-
.detail(MISSING_PATH_VARIABLE_DETAIL.toLowerCase())
81-
.extension(NAME_EXTENSION, "var")
67+
.detail("missing path variable")
68+
.extension("name", "var")
8269
.build());
8370
});
8471
}
@@ -113,9 +100,9 @@ void givenRequestWithoutRequestParam_shouldReturnProblem() {
113100
.isEqualTo(
114101
Problem.builder()
115102
.status(HttpStatus.BAD_REQUEST.value())
116-
.detail(MISSING_REQUEST_PARAM_DETAIL.toLowerCase())
117-
.extension(PARAM_EXTENSION, "param")
118-
.extension(KIND_EXTENSION, "string")
103+
.detail("missing request param")
104+
.extension("param", "param")
105+
.extension("kind", "string")
119106
.build());
120107
});
121108
}
@@ -155,8 +142,8 @@ void givenRequestWithoutRequestPart_shouldReturnProblem() {
155142
.isEqualTo(
156143
Problem.builder()
157144
.status(HttpStatus.BAD_REQUEST.value())
158-
.detail(MISSING_REQUEST_PART_DETAIL.toLowerCase())
159-
.extension(PARAM_EXTENSION, "file")
145+
.detail("missing request part")
146+
.extension("param", "file")
160147
.build());
161148
});
162149
}
@@ -203,8 +190,8 @@ void givenRequestWithoutRequestHeader_shouldReturnProblem() {
203190
.isEqualTo(
204191
Problem.builder()
205192
.status(HttpStatus.BAD_REQUEST.value())
206-
.detail(MISSING_HEADER_DETAIL.toLowerCase())
207-
.extension(HEADER_EXTENSION, "X-Custom-Header")
193+
.detail("missing header")
194+
.extension("header", "X-Custom-Header")
208195
.build());
209196
});
210197
}
@@ -240,8 +227,8 @@ void givenRequestWithoutCookieValue_shouldReturnProblem() {
240227
.isEqualTo(
241228
Problem.builder()
242229
.status(HttpStatus.BAD_REQUEST.value())
243-
.detail(MISSING_COOKIE_DETAIL.toLowerCase())
244-
.extension(COOKIE_EXTENSION, "x_session")
230+
.detail("missing cookie")
231+
.extension("cookie", "x_session")
245232
.build());
246233
});
247234
}
@@ -277,8 +264,8 @@ void givenRequestWithoutRequestAttribute_shouldReturnProblem() {
277264
.isEqualTo(
278265
Problem.builder()
279266
.status(HttpStatus.BAD_REQUEST.value())
280-
.detail(MISSING_REQUEST_ATTRIBUTE_DETAIL.toLowerCase())
281-
.extension(ATTRIBUTE_EXTENSION, "attr")
267+
.detail("missing request attribute")
268+
.extension("attribute", "attr")
282269
.build());
283270
});
284271
}
@@ -298,8 +285,8 @@ void givenRequestWithoutSessionAttribute_shouldReturnProblem() {
298285
.isEqualTo(
299286
Problem.builder()
300287
.status(HttpStatus.BAD_REQUEST.value())
301-
.detail(MISSING_SESSION_ATTRIBUTE_DETAIL.toLowerCase())
302-
.extension(ATTRIBUTE_EXTENSION, "attr")
288+
.detail("missing session attribute")
289+
.extension("attribute", "attr")
303290
.build());
304291
}
305292
}

problem4j-spring-webflux/src/test/java/io/github/problem4j/spring/webflux/integration/TypeMismatchWebFluxTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
package io.github.problem4j.spring.webflux.integration;
2323

24-
import static io.github.problem4j.spring.web.ProblemSupport.KIND_EXTENSION;
25-
import static io.github.problem4j.spring.web.ProblemSupport.PROPERTY_EXTENSION;
26-
import static io.github.problem4j.spring.web.ProblemSupport.TYPE_MISMATCH_DETAIL;
2724
import static org.hamcrest.Matchers.notNullValue;
2825

2926
import io.github.problem4j.core.Problem;
@@ -59,9 +56,9 @@ void givenRequestWithInvalidPathVariable_shouldReturnProblem() {
5956
.isEqualTo(
6057
Problem.builder()
6158
.status(HttpStatus.BAD_REQUEST.value())
62-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
63-
.extension(PROPERTY_EXTENSION, "id")
64-
.extension(KIND_EXTENSION, "integer")
59+
.detail("type mismatch")
60+
.extension("property", "id")
61+
.extension("kind", "integer")
6562
.build());
6663
}
6764

@@ -95,9 +92,9 @@ void givenRequestWithInvalidParameterType_shouldReturnProblem() {
9592
.isEqualTo(
9693
Problem.builder()
9794
.status(HttpStatus.BAD_REQUEST.value())
98-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
99-
.extension(PROPERTY_EXTENSION, "id")
100-
.extension(KIND_EXTENSION, "integer")
95+
.detail("type mismatch")
96+
.extension("property", "id")
97+
.extension("kind", "integer")
10198
.build());
10299
}
103100

@@ -132,9 +129,9 @@ void givenRequestWithInvalidRequestHeader_shouldReturnProblem() {
132129
.isEqualTo(
133130
Problem.builder()
134131
.status(HttpStatus.BAD_REQUEST.value())
135-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
136-
.extension(PROPERTY_EXTENSION, "X-Id")
137-
.extension(KIND_EXTENSION, "integer")
132+
.detail("type mismatch")
133+
.extension("property", "X-Id")
134+
.extension("kind", "integer")
138135
.build());
139136
}
140137

@@ -168,9 +165,9 @@ void givenRequestWithInvalidCookieValue_shouldReturnProblem() {
168165
.isEqualTo(
169166
Problem.builder()
170167
.status(HttpStatus.BAD_REQUEST.value())
171-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
172-
.extension(PROPERTY_EXTENSION, "id")
173-
.extension(KIND_EXTENSION, "integer")
168+
.detail("type mismatch")
169+
.extension("property", "id")
170+
.extension("kind", "integer")
174171
.build());
175172
}
176173

@@ -207,9 +204,9 @@ void givenRequestWithInvalidEnumInRequestBody_shouldReturnProblem() {
207204
.isEqualTo(
208205
Problem.builder()
209206
.status(HttpStatus.BAD_REQUEST.value())
210-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
211-
.extension(PROPERTY_EXTENSION, "status")
212-
.extension(KIND_EXTENSION, "enum")
207+
.detail("type mismatch")
208+
.extension("property", "status")
209+
.extension("kind", "enum")
213210
.build());
214211
}
215212

0 commit comments

Comments
 (0)