Skip to content

Commit 6174487

Browse files
committed
test: standardize 4XX test suite in WalletController by replacing hardcoded status codes with HttpStatus constants
1 parent 0aae251 commit 6174487

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

wallet-entrypoint/src/test/java/com/br/walletentrypoint/rest/WalletController4XXTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void shouldReturn400WhenUserIdIsBlank() {
6767
.post(BASE_PATH)
6868
.then()
6969
.statusCode(HttpStatus.BAD_REQUEST.value())
70-
.body("statusCode", equalTo(400))
70+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
7171
.body("title", equalTo("Validation Failed"))
7272
.body("details", hasSize(1))
7373
.body("details[0].field", equalTo("userId"))
@@ -89,7 +89,7 @@ void shouldReturn400WhenCurrencyIsInvalid() {
8989
.post(BASE_PATH)
9090
.then()
9191
.statusCode(HttpStatus.BAD_REQUEST.value())
92-
.body("statusCode", equalTo(400))
92+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
9393
.body("title", equalTo("Validation Failed"))
9494
.body("details", hasSize(1))
9595
.body("details[0].field", equalTo("currency"))
@@ -111,7 +111,7 @@ void shouldReturn400WithMultipleValidationErrors() {
111111
.post(BASE_PATH)
112112
.then()
113113
.statusCode(HttpStatus.BAD_REQUEST.value())
114-
.body("statusCode", equalTo(400))
114+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
115115
.body("title", equalTo("Validation Failed"))
116116
.body("details", hasSize(2))
117117
.body("details.field", hasItem("userId"))
@@ -133,7 +133,7 @@ void shouldReturn400WhenDepositAmountIsZero() {
133133
.post(BASE_PATH + "/{userId}/deposit", "688c2e05c0514a144d4bd13c")
134134
.then()
135135
.statusCode(HttpStatus.BAD_REQUEST.value())
136-
.body("statusCode", equalTo(400))
136+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
137137
.body("title", equalTo("Validation Failed"))
138138
.body("details[0].field", equalTo("amount"))
139139
.body("details[0].message", equalTo("Amount must be greater than zero"));
@@ -154,7 +154,7 @@ void shouldReturn400WhenWithdrawAmountIsNegative() {
154154
.post(BASE_PATH + "/{userId}/withdraw", "688c2e05c0514a144d4bd13c")
155155
.then()
156156
.statusCode(HttpStatus.BAD_REQUEST.value())
157-
.body("statusCode", equalTo(400))
157+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
158158
.body("title", equalTo("Validation Failed"))
159159
.body("details[0].field", equalTo("amount"))
160160
.body("details[0].message", equalTo("Amount must be greater than zero"));
@@ -177,7 +177,7 @@ void shouldReturn400WhenTransferFromUserIdIsBlank() {
177177
.post(BASE_PATH + "/transfer")
178178
.then()
179179
.statusCode(HttpStatus.BAD_REQUEST.value())
180-
.body("statusCode", equalTo(400))
180+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
181181
.body("title", equalTo("Validation Failed"))
182182
.body("details[0].field", equalTo("fromUserId"))
183183
.body("details[0].message", equalTo("Source user ID is required"));
@@ -192,7 +192,7 @@ void shouldReturn400WhenHistoricalBalanceDateIsInvalid() {
192192
.get(BASE_PATH + "/{userId}/balance/historical", "688c2e05c0514a144d4bd13c")
193193
.then()
194194
.statusCode(HttpStatus.BAD_REQUEST.value())
195-
.body("statusCode", equalTo(400))
195+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
196196
.body("title", equalTo("Invalid Parameter Type"));
197197
}
198198

@@ -211,7 +211,7 @@ void shouldReturn400WhenJsonIsMalformed() {
211211
.post(BASE_PATH)
212212
.then()
213213
.statusCode(HttpStatus.BAD_REQUEST.value())
214-
.body("statusCode", equalTo(400))
214+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
215215
.body("title", equalTo("Invalid Request Body"))
216216
.body("details[0].field", equalTo("requestBody"))
217217
.body("details[0].message", equalTo("Invalid JSON format"));
@@ -239,7 +239,7 @@ void shouldReturn400WhenUserAlreadyHasWallet() {
239239
.post(BASE_PATH)
240240
.then()
241241
.statusCode(HttpStatus.BAD_REQUEST.value())
242-
.body("statusCode", equalTo(400))
242+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
243243
.body("title", equalTo("Business Rule Violation"))
244244
.body("message", equalTo("User already has a wallet"))
245245
.body("details[0].field", equalTo("businessRule"))
@@ -267,7 +267,7 @@ void shouldReturn400WhenWalletNotFoundForDeposit() {
267267
.post(BASE_PATH + "/{userId}/deposit", userId)
268268
.then()
269269
.statusCode(HttpStatus.BAD_REQUEST.value())
270-
.body("statusCode", equalTo(400))
270+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
271271
.body("title", equalTo("Business Rule Violation"))
272272
.body("message", equalTo("Wallet not found for user: " + userId));
273273
}
@@ -292,7 +292,7 @@ void shouldReturn400WhenInsufficientFunds() {
292292
.post(BASE_PATH + "/{userId}/withdraw", "688c2e05c0514a144d4bd13c")
293293
.then()
294294
.statusCode(HttpStatus.BAD_REQUEST.value())
295-
.body("statusCode", equalTo(400))
295+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
296296
.body("title", equalTo("Business Rule Violation"))
297297
.body("message", equalTo("Insufficient funds"));
298298
}
@@ -319,7 +319,7 @@ void shouldReturn400WhenTransferCurrencyMismatch() {
319319
.post(BASE_PATH + "/transfer")
320320
.then()
321321
.statusCode(HttpStatus.BAD_REQUEST.value())
322-
.body("statusCode", equalTo(400))
322+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
323323
.body("title", equalTo("Business Rule Violation"))
324324
.body("message", equalTo("Currency mismatch between wallets"));
325325
}
@@ -347,7 +347,7 @@ void shouldReturn400WhenTransferringToSameUser() {
347347
.post(BASE_PATH + "/transfer")
348348
.then()
349349
.statusCode(HttpStatus.BAD_REQUEST.value())
350-
.body("statusCode", equalTo(400))
350+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
351351
.body("title", equalTo("Business Rule Violation"))
352352
.body("message", equalTo("Cannot transfer to same user"));
353353
}
@@ -367,7 +367,7 @@ void shouldReturn400WhenHistoricalDateIsInFuture() {
367367
.get(BASE_PATH + "/{userId}/balance/historical", "688c2e05c0514a144d4bd13c")
368368
.then()
369369
.statusCode(HttpStatus.BAD_REQUEST.value())
370-
.body("statusCode", equalTo(400))
370+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
371371
.body("title", equalTo("Business Rule Violation"))
372372
.body("message", equalTo("Date cannot be in the future"));
373373
}
@@ -386,7 +386,7 @@ void shouldReturn400WhenWalletNotFoundForGet() {
386386
.get(BASE_PATH + "/{userId}", nonexistentUserId)
387387
.then()
388388
.statusCode(HttpStatus.BAD_REQUEST.value())
389-
.body("statusCode", equalTo(400))
389+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
390390
.body("title", equalTo("Business Rule Violation"))
391391
.body("message", equalTo("Wallet not found for user: " + nonexistentUserId));
392392
}
@@ -402,7 +402,7 @@ void shouldReturn400WhenRequiredParameterIsMissing() {
402402
.get(BASE_PATH + "/{userId}/balance/historical", "688c2e05c0514a144d4bd13c")
403403
.then()
404404
.statusCode(HttpStatus.BAD_REQUEST.value())
405-
.body("statusCode", equalTo(400))
405+
.body("statusCode", equalTo(HttpStatus.BAD_REQUEST.value()))
406406
.body("title", equalTo("Missing Required Parameter"))
407407
.body("message", equalTo("One or more required parameters are missing"))
408408
.body("details[0].field", equalTo("date"))

0 commit comments

Comments
 (0)