Skip to content

Commit 60f924f

Browse files
Use literals in tests
1 parent b17a9e2 commit 60f924f

22 files changed

Lines changed: 242 additions & 341 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;
@@ -63,7 +62,7 @@ void givenBindingResultForBindingError_shouldResolveViolation() {
6362

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

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

6968
@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/BindingKotlinWebFluxTest.java

Lines changed: 29 additions & 32 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;
@@ -85,9 +82,9 @@ void givenNullValue_whenPost_thenReturnTypeMismatch(String path, String json) {
8582
.isEqualTo(
8683
Problem.builder()
8784
.status(HttpStatus.BAD_REQUEST.value())
88-
.detail(TYPE_MISMATCH_DETAIL)
89-
.extension(PROPERTY_EXTENSION, "value")
90-
.extension(KIND_EXTENSION, expectedKind)
85+
.detail("Type mismatch")
86+
.extension("property", "value")
87+
.extension("kind", expectedKind)
9188
.build());
9289
});
9390
}
@@ -128,9 +125,9 @@ void givenNullInNestedObjectValue_whenPost_thenReturnTypeMismatch(String path, S
128125
.isEqualTo(
129126
Problem.builder()
130127
.status(HttpStatus.BAD_REQUEST.value())
131-
.detail(TYPE_MISMATCH_DETAIL)
132-
.extension(PROPERTY_EXTENSION, "nested.value")
133-
.extension(KIND_EXTENSION, expectedKind)
128+
.detail("Type mismatch")
129+
.extension("property", "nested.value")
130+
.extension("kind", expectedKind)
134131
.build());
135132
});
136133
}
@@ -166,8 +163,8 @@ void givenNullNestedObject_whenPost_thenReturnTypeMismatch(String path, String j
166163
.isEqualTo(
167164
Problem.builder()
168165
.status(HttpStatus.BAD_REQUEST.value())
169-
.detail(TYPE_MISMATCH_DETAIL)
170-
.extension(PROPERTY_EXTENSION, "nested")
166+
.detail("Type mismatch")
167+
.extension("property", "nested")
171168
.build()));
172169
}
173170

@@ -199,9 +196,9 @@ void givenMalformedComplexKotlinObject_whenPost_thenReturnProblemWithFirstInvali
199196
.isEqualTo(
200197
Problem.builder()
201198
.status(HttpStatus.BAD_REQUEST.value())
202-
.detail(TYPE_MISMATCH_DETAIL)
203-
.extension(PROPERTY_EXTENSION, expectedProperty)
204-
.extension(KIND_EXTENSION, expectedKind)
199+
.detail("Type mismatch")
200+
.extension("property", expectedProperty)
201+
.extension("kind", expectedKind)
205202
.build()));
206203
}
207204

@@ -248,9 +245,9 @@ void givenListElementNullability_whenElementNull_thenBehaviorMatchesNullability(
248245
.isEqualTo(
249246
Problem.builder()
250247
.status(HttpStatus.BAD_REQUEST.value())
251-
.detail(TYPE_MISMATCH_DETAIL)
252-
.extension(PROPERTY_EXTENSION, "values")
253-
.extension(KIND_EXTENSION, "integer")
248+
.detail("Type mismatch")
249+
.extension("property", "values")
250+
.extension("kind", "integer")
254251
.build()));
255252
}
256253

@@ -285,9 +282,9 @@ void givenMapValueNullability_whenValueNull_thenBehaviorMatchesNullability() {
285282
.isEqualTo(
286283
Problem.builder()
287284
.status(HttpStatus.BAD_REQUEST.value())
288-
.detail(TYPE_MISMATCH_DETAIL)
289-
.extension(PROPERTY_EXTENSION, "map.k")
290-
.extension(KIND_EXTENSION, "integer")
285+
.detail("Type mismatch")
286+
.extension("property", "map.k")
287+
.extension("kind", "integer")
291288
.build()));
292289
}
293290

@@ -394,9 +391,9 @@ void givenMalformedPrimitive_whenPost_thenReturnProblem(String path, String json
394391
Problem expected =
395392
Problem.builder()
396393
.status(HttpStatus.BAD_REQUEST.value())
397-
.detail(TYPE_MISMATCH_DETAIL)
398-
.extension(PROPERTY_EXTENSION, "value")
399-
.extension(KIND_EXTENSION, expectedKind)
394+
.detail("Type mismatch")
395+
.extension("property", "value")
396+
.extension("kind", expectedKind)
400397
.build();
401398

402399
if (!problem.equals(expected)) {
@@ -497,9 +494,9 @@ void givenMalformedNested_whenPost_thenReturnProblem(String path, String json) {
497494
.isEqualTo(
498495
Problem.builder()
499496
.status(HttpStatus.BAD_REQUEST.value())
500-
.detail(TYPE_MISMATCH_DETAIL)
501-
.extension(PROPERTY_EXTENSION, "nested.value")
502-
.extension(KIND_EXTENSION, expectedKind)
497+
.detail("Type mismatch")
498+
.extension("property", "nested.value")
499+
.extension("kind", expectedKind)
503500
.build());
504501
});
505502
}
@@ -543,9 +540,9 @@ void givenEmptyStringPrimitive_whenPost_thenReturnProblem(String path, String js
543540
.isEqualTo(
544541
Problem.builder()
545542
.status(HttpStatus.BAD_REQUEST.value())
546-
.detail(TYPE_MISMATCH_DETAIL)
547-
.extension(PROPERTY_EXTENSION, "value")
548-
.extension(KIND_EXTENSION, expectedKind)
543+
.detail("Type mismatch")
544+
.extension("property", "value")
545+
.extension("kind", expectedKind)
549546
.build());
550547
});
551548
}
@@ -576,9 +573,9 @@ void givenOverflowPrimitive_whenPost_thenReturnProblem(String path, String json)
576573
Problem expected =
577574
Problem.builder()
578575
.status(HttpStatus.BAD_REQUEST.value())
579-
.detail(TYPE_MISMATCH_DETAIL)
580-
.extension(PROPERTY_EXTENSION, "value")
581-
.extension(KIND_EXTENSION, "integer")
576+
.detail("Type mismatch")
577+
.extension("property", "value")
578+
.extension("kind", "integer")
582579
.build();
583580

584581
if (!problem.equals(expected)) {

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;
@@ -141,9 +138,9 @@ void givenMalformedPrimitive_whenPost_thenReturnProblem(String path, String json
141138
Problem expected =
142139
Problem.builder()
143140
.status(HttpStatus.BAD_REQUEST.value())
144-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
145-
.extension(PROPERTY_EXTENSION, "value")
146-
.extension(KIND_EXTENSION, expectedKind)
141+
.detail("type mismatch")
142+
.extension("property", "value")
143+
.extension("kind", expectedKind)
147144
.build();
148145

149146
if (!problem.equals(expected)) {
@@ -244,9 +241,9 @@ void givenMalformedNested_whenPost_thenReturnProblem(String path, String json) {
244241
.isEqualTo(
245242
Problem.builder()
246243
.status(HttpStatus.BAD_REQUEST.value())
247-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
248-
.extension(PROPERTY_EXTENSION, "nested.value")
249-
.extension(KIND_EXTENSION, expectedKind)
244+
.detail("type mismatch")
245+
.extension("property", "nested.value")
246+
.extension("kind", expectedKind)
250247
.build());
251248
});
252249
}
@@ -290,9 +287,9 @@ void givenEmptyStringPrimitive_whenPost_thenReturnProblem(String path, String js
290287
.isEqualTo(
291288
Problem.builder()
292289
.status(HttpStatus.BAD_REQUEST.value())
293-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
294-
.extension(PROPERTY_EXTENSION, "value")
295-
.extension(KIND_EXTENSION, expectedKind)
290+
.detail("type mismatch")
291+
.extension("property", "value")
292+
.extension("kind", expectedKind)
296293
.build());
297294
});
298295
}
@@ -323,9 +320,9 @@ void givenOverflowPrimitive_whenPost_thenReturnProblem(String path, String json)
323320
Problem expected =
324321
Problem.builder()
325322
.status(HttpStatus.BAD_REQUEST.value())
326-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
327-
.extension(PROPERTY_EXTENSION, "value")
328-
.extension(KIND_EXTENSION, "integer")
323+
.detail("type mismatch")
324+
.extension("property", "value")
325+
.extension("kind", "integer")
329326
.build();
330327

331328
if (!problem.equals(expected)) {
@@ -352,9 +349,9 @@ void givenNullPrimitive_whenPost_thenReturnProblem() {
352349
Problem expected =
353350
Problem.builder()
354351
.status(HttpStatus.BAD_REQUEST.value())
355-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
356-
.extension(PROPERTY_EXTENSION, "value")
357-
.extension(KIND_EXTENSION, "integer")
352+
.detail("type mismatch")
353+
.extension("property", "value")
354+
.extension("kind", "integer")
358355
.build();
359356

360357
if (!problem.equals(expected)) {
@@ -416,9 +413,9 @@ void givenMalformedComplexObject_whenPost_thenReturnProblemWithFirstInvalidField
416413
.isEqualTo(
417414
Problem.builder()
418415
.status(HttpStatus.BAD_REQUEST.value())
419-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
420-
.extension(PROPERTY_EXTENSION, expectedProperty)
421-
.extension(KIND_EXTENSION, expectedKind)
416+
.detail("type mismatch")
417+
.extension("property", expectedProperty)
418+
.extension("kind", expectedKind)
422419
.build()));
423420
}
424421
}

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.assertj.core.api.Assertions.assertThat;
2725

2826
import io.github.problem4j.core.Problem;
@@ -58,8 +56,8 @@ void givenMaxUploadSizeExceeded_shouldReturnProblem() {
5856
.isEqualTo(
5957
Problem.builder()
6058
.status(HttpStatus.CONTENT_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
}

0 commit comments

Comments
 (0)