Skip to content

Commit 5d74bc8

Browse files
Use literals in tests
1 parent aa0851a commit 5d74bc8

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
@@ -16,7 +16,6 @@
1616

1717
package io.github.problem4j.spring.web;
1818

19-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.IS_NOT_VALID_ERROR;
2019
import static org.assertj.core.api.Assertions.assertThat;
2120

2221
import io.github.problem4j.spring.web.parameter.BindingResultSupport;
@@ -58,7 +57,7 @@ void givenBindingResultForBindingError_shouldResolveViolation() {
5857

5958
List<Violation> violations = support.fetchViolations(bindingResult);
6059

61-
assertThat(violations).containsExactly(new Violation("age", IS_NOT_VALID_ERROR));
60+
assertThat(violations).containsExactly(new Violation("age", "is not valid"));
6261
}
6362

6463
@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
@@ -20,7 +20,6 @@
2020

2121
import io.github.problem4j.core.Problem;
2222
import io.github.problem4j.core.ProblemContext;
23-
import io.github.problem4j.spring.web.parameter.ViolationSupport;
2423
import java.lang.reflect.Method;
2524
import org.junit.jupiter.api.BeforeEach;
2625
import org.junit.jupiter.api.Test;
@@ -63,9 +62,9 @@ void givenExceptionWithCauseAndWithoutPropertyName_shouldDelegateAndIncludeMetho
6362
.isEqualTo(
6463
Problem.builder()
6564
.status(HttpStatus.BAD_REQUEST.value())
66-
.detail(ViolationSupport.TYPE_MISMATCH_DETAIL)
67-
.extension(ViolationSupport.PROPERTY_EXTENSION, "value")
68-
.extension(ViolationSupport.KIND_EXTENSION, "boolean")
65+
.detail("Type mismatch")
66+
.extension("property", "value")
67+
.extension("kind", "boolean")
6968
.build());
7069
}
7170

@@ -87,9 +86,9 @@ void givenExceptionWithCauseAndWithoutParameter_shouldDelegateToMethodParameter(
8786
.isEqualTo(
8887
Problem.builder()
8988
.status(HttpStatus.BAD_REQUEST.value())
90-
.detail(ViolationSupport.TYPE_MISMATCH_DETAIL)
91-
.extension(ViolationSupport.PROPERTY_EXTENSION, "flag")
92-
.extension(ViolationSupport.KIND_EXTENSION, "boolean")
89+
.detail("Type mismatch")
90+
.extension("property", "flag")
91+
.extension("kind", "boolean")
9392
.build());
9493
}
9594

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
@@ -20,7 +20,6 @@
2020

2121
import io.github.problem4j.core.Problem;
2222
import io.github.problem4j.core.ProblemContext;
23-
import io.github.problem4j.spring.web.parameter.ViolationSupport;
2423
import org.junit.jupiter.api.BeforeEach;
2524
import org.junit.jupiter.api.Test;
2625
import org.springframework.beans.TypeMismatchException;
@@ -50,9 +49,9 @@ void givenExceptionWithParameterNameAndType_shouldReturnProblemWithAll() {
5049
.isEqualTo(
5150
Problem.builder()
5251
.status(HttpStatus.BAD_REQUEST.value())
53-
.detail(ViolationSupport.TYPE_MISMATCH_DETAIL)
54-
.extension(ViolationSupport.PROPERTY_EXTENSION, "age")
55-
.extension(ViolationSupport.KIND_EXTENSION, "integer")
52+
.detail("Type mismatch")
53+
.extension("property", "age")
54+
.extension("kind", "integer")
5655
.build());
5756
}
5857

@@ -68,8 +67,8 @@ void givenExceptionWithParameterType_shouldReturnProblemWithTypeOnly() {
6867
.isEqualTo(
6968
Problem.builder()
7069
.status(HttpStatus.BAD_REQUEST.value())
71-
.detail(ViolationSupport.TYPE_MISMATCH_DETAIL)
72-
.extension(ViolationSupport.KIND_EXTENSION, "integer")
70+
.detail("Type mismatch")
71+
.extension("kind", "integer")
7372
.build());
7473
}
7574

@@ -86,8 +85,8 @@ void givenExceptionWithParameterName_shouldReturnProblemWithNameOnly() {
8685
.isEqualTo(
8786
Problem.builder()
8887
.status(HttpStatus.BAD_REQUEST.value())
89-
.detail(ViolationSupport.TYPE_MISMATCH_DETAIL)
90-
.extension(ViolationSupport.PROPERTY_EXTENSION, "field")
88+
.detail("Type mismatch")
89+
.extension("property", "field")
9190
.build());
9291
}
9392
}

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
@@ -16,9 +16,6 @@
1616

1717
package io.github.problem4j.spring.webflux.integration;
1818

19-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.KIND_EXTENSION;
20-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.PROPERTY_EXTENSION;
21-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.TYPE_MISMATCH_DETAIL;
2219
import static org.assertj.core.api.Assertions.assertThat;
2320

2421
import io.github.problem4j.core.Problem;
@@ -80,9 +77,9 @@ void givenNullValue_whenPost_thenReturnTypeMismatch(String path, String json) {
8077
.isEqualTo(
8178
Problem.builder()
8279
.status(HttpStatus.BAD_REQUEST.value())
83-
.detail(TYPE_MISMATCH_DETAIL)
84-
.extension(PROPERTY_EXTENSION, "value")
85-
.extension(KIND_EXTENSION, expectedKind)
80+
.detail("Type mismatch")
81+
.extension("property", "value")
82+
.extension("kind", expectedKind)
8683
.build());
8784
});
8885
}
@@ -123,9 +120,9 @@ void givenNullInNestedObjectValue_whenPost_thenReturnTypeMismatch(String path, S
123120
.isEqualTo(
124121
Problem.builder()
125122
.status(HttpStatus.BAD_REQUEST.value())
126-
.detail(TYPE_MISMATCH_DETAIL)
127-
.extension(PROPERTY_EXTENSION, "nested.value")
128-
.extension(KIND_EXTENSION, expectedKind)
123+
.detail("Type mismatch")
124+
.extension("property", "nested.value")
125+
.extension("kind", expectedKind)
129126
.build());
130127
});
131128
}
@@ -161,8 +158,8 @@ void givenNullNestedObject_whenPost_thenReturnTypeMismatch(String path, String j
161158
.isEqualTo(
162159
Problem.builder()
163160
.status(HttpStatus.BAD_REQUEST.value())
164-
.detail(TYPE_MISMATCH_DETAIL)
165-
.extension(PROPERTY_EXTENSION, "nested")
161+
.detail("Type mismatch")
162+
.extension("property", "nested")
166163
.build()));
167164
}
168165

@@ -194,9 +191,9 @@ void givenMalformedComplexKotlinObject_whenPost_thenReturnProblemWithFirstInvali
194191
.isEqualTo(
195192
Problem.builder()
196193
.status(HttpStatus.BAD_REQUEST.value())
197-
.detail(TYPE_MISMATCH_DETAIL)
198-
.extension(PROPERTY_EXTENSION, expectedProperty)
199-
.extension(KIND_EXTENSION, expectedKind)
194+
.detail("Type mismatch")
195+
.extension("property", expectedProperty)
196+
.extension("kind", expectedKind)
200197
.build()));
201198
}
202199

@@ -243,9 +240,9 @@ void givenListElementNullability_whenElementNull_thenBehaviorMatchesNullability(
243240
.isEqualTo(
244241
Problem.builder()
245242
.status(HttpStatus.BAD_REQUEST.value())
246-
.detail(TYPE_MISMATCH_DETAIL)
247-
.extension(PROPERTY_EXTENSION, "values")
248-
.extension(KIND_EXTENSION, "integer")
243+
.detail("Type mismatch")
244+
.extension("property", "values")
245+
.extension("kind", "integer")
249246
.build()));
250247
}
251248

@@ -280,9 +277,9 @@ void givenMapValueNullability_whenValueNull_thenBehaviorMatchesNullability() {
280277
.isEqualTo(
281278
Problem.builder()
282279
.status(HttpStatus.BAD_REQUEST.value())
283-
.detail(TYPE_MISMATCH_DETAIL)
284-
.extension(PROPERTY_EXTENSION, "map.k")
285-
.extension(KIND_EXTENSION, "integer")
280+
.detail("Type mismatch")
281+
.extension("property", "map.k")
282+
.extension("kind", "integer")
286283
.build()));
287284
}
288285

@@ -389,9 +386,9 @@ void givenMalformedPrimitive_whenPost_thenReturnProblem(String path, String json
389386
Problem expected =
390387
Problem.builder()
391388
.status(HttpStatus.BAD_REQUEST.value())
392-
.detail(TYPE_MISMATCH_DETAIL)
393-
.extension(PROPERTY_EXTENSION, "value")
394-
.extension(KIND_EXTENSION, expectedKind)
389+
.detail("Type mismatch")
390+
.extension("property", "value")
391+
.extension("kind", expectedKind)
395392
.build();
396393

397394
if (!problem.equals(expected)) {
@@ -492,9 +489,9 @@ void givenMalformedNested_whenPost_thenReturnProblem(String path, String json) {
492489
.isEqualTo(
493490
Problem.builder()
494491
.status(HttpStatus.BAD_REQUEST.value())
495-
.detail(TYPE_MISMATCH_DETAIL)
496-
.extension(PROPERTY_EXTENSION, "nested.value")
497-
.extension(KIND_EXTENSION, expectedKind)
492+
.detail("Type mismatch")
493+
.extension("property", "nested.value")
494+
.extension("kind", expectedKind)
498495
.build());
499496
});
500497
}
@@ -538,9 +535,9 @@ void givenEmptyStringPrimitive_whenPost_thenReturnProblem(String path, String js
538535
.isEqualTo(
539536
Problem.builder()
540537
.status(HttpStatus.BAD_REQUEST.value())
541-
.detail(TYPE_MISMATCH_DETAIL)
542-
.extension(PROPERTY_EXTENSION, "value")
543-
.extension(KIND_EXTENSION, expectedKind)
538+
.detail("Type mismatch")
539+
.extension("property", "value")
540+
.extension("kind", expectedKind)
544541
.build());
545542
});
546543
}
@@ -571,9 +568,9 @@ void givenOverflowPrimitive_whenPost_thenReturnProblem(String path, String json)
571568
Problem expected =
572569
Problem.builder()
573570
.status(HttpStatus.BAD_REQUEST.value())
574-
.detail(TYPE_MISMATCH_DETAIL)
575-
.extension(PROPERTY_EXTENSION, "value")
576-
.extension(KIND_EXTENSION, "integer")
571+
.detail("Type mismatch")
572+
.extension("property", "value")
573+
.extension("kind", "integer")
577574
.build();
578575

579576
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
@@ -16,9 +16,6 @@
1616

1717
package io.github.problem4j.spring.webflux.integration;
1818

19-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.KIND_EXTENSION;
20-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.PROPERTY_EXTENSION;
21-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.TYPE_MISMATCH_DETAIL;
2219
import static org.assertj.core.api.Assertions.assertThat;
2320

2421
import io.github.problem4j.core.Problem;
@@ -136,9 +133,9 @@ void givenMalformedPrimitive_whenPost_thenReturnProblem(String path, String json
136133
Problem expected =
137134
Problem.builder()
138135
.status(HttpStatus.BAD_REQUEST.value())
139-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
140-
.extension(PROPERTY_EXTENSION, "value")
141-
.extension(KIND_EXTENSION, expectedKind)
136+
.detail("type mismatch")
137+
.extension("property", "value")
138+
.extension("kind", expectedKind)
142139
.build();
143140

144141
if (!problem.equals(expected)) {
@@ -239,9 +236,9 @@ void givenMalformedNested_whenPost_thenReturnProblem(String path, String json) {
239236
.isEqualTo(
240237
Problem.builder()
241238
.status(HttpStatus.BAD_REQUEST.value())
242-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
243-
.extension(PROPERTY_EXTENSION, "nested.value")
244-
.extension(KIND_EXTENSION, expectedKind)
239+
.detail("type mismatch")
240+
.extension("property", "nested.value")
241+
.extension("kind", expectedKind)
245242
.build());
246243
});
247244
}
@@ -285,9 +282,9 @@ void givenEmptyStringPrimitive_whenPost_thenReturnProblem(String path, String js
285282
.isEqualTo(
286283
Problem.builder()
287284
.status(HttpStatus.BAD_REQUEST.value())
288-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
289-
.extension(PROPERTY_EXTENSION, "value")
290-
.extension(KIND_EXTENSION, expectedKind)
285+
.detail("type mismatch")
286+
.extension("property", "value")
287+
.extension("kind", expectedKind)
291288
.build());
292289
});
293290
}
@@ -318,9 +315,9 @@ void givenOverflowPrimitive_whenPost_thenReturnProblem(String path, String json)
318315
Problem expected =
319316
Problem.builder()
320317
.status(HttpStatus.BAD_REQUEST.value())
321-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
322-
.extension(PROPERTY_EXTENSION, "value")
323-
.extension(KIND_EXTENSION, "integer")
318+
.detail("type mismatch")
319+
.extension("property", "value")
320+
.extension("kind", "integer")
324321
.build();
325322

326323
if (!problem.equals(expected)) {
@@ -347,9 +344,9 @@ void givenNullPrimitive_whenPost_thenReturnProblem() {
347344
Problem expected =
348345
Problem.builder()
349346
.status(HttpStatus.BAD_REQUEST.value())
350-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
351-
.extension(PROPERTY_EXTENSION, "value")
352-
.extension(KIND_EXTENSION, "integer")
347+
.detail("type mismatch")
348+
.extension("property", "value")
349+
.extension("kind", "integer")
353350
.build();
354351

355352
if (!problem.equals(expected)) {
@@ -411,9 +408,9 @@ void givenMalformedComplexObject_whenPost_thenReturnProblemWithFirstInvalidField
411408
.isEqualTo(
412409
Problem.builder()
413410
.status(HttpStatus.BAD_REQUEST.value())
414-
.detail(TYPE_MISMATCH_DETAIL.toLowerCase())
415-
.extension(PROPERTY_EXTENSION, expectedProperty)
416-
.extension(KIND_EXTENSION, expectedKind)
411+
.detail("type mismatch")
412+
.extension("property", expectedProperty)
413+
.extension("kind", expectedKind)
417414
.build()));
418415
}
419416
}

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
@@ -16,8 +16,6 @@
1616

1717
package io.github.problem4j.spring.webflux.integration;
1818

19-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.MAX_EXTENSION;
20-
import static io.github.problem4j.spring.web.parameter.ViolationSupport.MAX_UPLOAD_SIZE_EXCEEDED_DETAIL;
2119
import static org.assertj.core.api.Assertions.assertThat;
2220

2321
import io.github.problem4j.core.Problem;
@@ -53,8 +51,8 @@ void givenMaxUploadSizeExceeded_shouldReturnProblem() {
5351
.isEqualTo(
5452
Problem.builder()
5553
.status(HttpStatus.CONTENT_TOO_LARGE.value())
56-
.detail(MAX_UPLOAD_SIZE_EXCEEDED_DETAIL.toLowerCase())
57-
.extension(MAX_EXTENSION, 1)
54+
.detail("max upload size exceeded")
55+
.extension("max", 1)
5856
.build());
5957
}
6058
}

0 commit comments

Comments
 (0)