Skip to content

Commit 0409a37

Browse files
oschwaldclaude
andcommitted
Use var for local variable declarations
This updates local variables throughout the codebase to use var instead of explicit type names, making the code more concise while maintaining readability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a422f35 commit 0409a37

18 files changed

+167
-167
lines changed

src/main/java/com/maxmind/minfraud/WebServiceClient.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ public void reportTransaction(TransactionReport transaction) throws IOException,
306306
if (transaction == null) {
307307
throw new IllegalArgumentException("transaction report must not be null");
308308
}
309-
URI uri = createUri(WebServiceClient.pathBase + "transactions/report");
310-
HttpRequest request = requestFor(transaction, uri);
309+
var uri = createUri(WebServiceClient.pathBase + "transactions/report");
310+
var request = requestFor(transaction, uri);
311311

312312
HttpResponse<InputStream> response = null;
313313
try {
@@ -328,8 +328,8 @@ private <T> T responseFor(String service, AbstractModel transaction, Class<T> cl
328328
if (transaction == null) {
329329
throw new IllegalArgumentException("transaction must not be null");
330330
}
331-
URI uri = createUri(WebServiceClient.pathBase + service);
332-
HttpRequest request = requestFor(transaction, uri);
331+
var uri = createUri(WebServiceClient.pathBase + service);
332+
var request = requestFor(transaction, uri);
333333

334334
HttpResponse<InputStream> response = null;
335335
try {
@@ -346,7 +346,7 @@ private <T> T responseFor(String service, AbstractModel transaction, Class<T> cl
346346

347347
private HttpRequest requestFor(AbstractModel transaction, URI uri)
348348
throws MinFraudException, IOException {
349-
HttpRequest.Builder builder = HttpRequest.newBuilder()
349+
var builder = HttpRequest.newBuilder()
350350
.uri(uri)
351351
.header("Accept", "application/json")
352352
.header("Authorization", authHeader)
@@ -365,7 +365,7 @@ private HttpRequest requestFor(AbstractModel transaction, URI uri)
365365

366366
private void maybeThrowException(HttpResponse<InputStream> response, URI uri)
367367
throws IOException, MinFraudException {
368-
int status = response.statusCode();
368+
var status = response.statusCode();
369369
if (status >= 400 && status < 500) {
370370
this.handle4xxStatus(response, uri);
371371
} else if (status >= 500 && status < 600) {
@@ -383,7 +383,7 @@ private <T> T handleResponse(HttpResponse<InputStream> response, URI uri, Class<
383383
throws MinFraudException, IOException {
384384
maybeThrowException(response, uri);
385385

386-
InjectableValues inject = new Std().addValue(
386+
var inject = new Std().addValue(
387387
"locales", locales);
388388

389389
try (InputStream stream = response.body()) {
@@ -398,7 +398,7 @@ private void handle4xxStatus(HttpResponse<InputStream> response, URI uri)
398398
throws IOException, InsufficientFundsException,
399399
InvalidRequestException, AuthenticationException,
400400
PermissionRequiredException {
401-
int status = response.statusCode();
401+
var status = response.statusCode();
402402

403403
String body;
404404
try (InputStream stream = response.body()) {
@@ -425,8 +425,8 @@ private void handleErrorWithJsonBody(Map<String, String> content,
425425
throws HttpException, InsufficientFundsException,
426426
InvalidRequestException, AuthenticationException,
427427
PermissionRequiredException {
428-
String error = content.get("error");
429-
String code = content.get("code");
428+
var error = content.get("error");
429+
var code = content.get("code");
430430

431431
if (error == null || code == null) {
432432
throw new HttpException(

src/test/java/com/maxmind/minfraud/WebServiceClientTest.java

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,41 +57,41 @@ public class WebServiceClientTest {
5757

5858
@Test
5959
public void testReportTransaction() throws Exception {
60-
String responseContent = "";
61-
WebServiceClient client = createSuccessClient("transactions/report", 204,
60+
var responseContent = "";
61+
var client = createSuccessClient("transactions/report", 204,
6262
responseContent);
63-
TransactionReport request = fullTransactionReport();
63+
var request = fullTransactionReport();
6464
client.reportTransaction(request);
6565
}
6666

6767
@Test
6868
public void testFullScoreTransaction() throws Exception {
69-
String responseContent = readJsonFile("score-response");
70-
WebServiceClient client = createSuccessClient("score", 200, responseContent);
71-
Transaction request = fullTransaction();
72-
ScoreResponse response = client.score(request);
69+
var responseContent = readJsonFile("score-response");
70+
var client = createSuccessClient("score", 200, responseContent);
71+
var request = fullTransaction();
72+
var response = client.score(request);
7373

7474
JSONAssert.assertEquals(responseContent, response.toJson(), true);
7575
verifyRequestFor(wireMock, "score", "full-request");
7676
}
7777

7878
@Test
7979
public void testFullScoreTransactionWithEmailMd5() throws Exception {
80-
String responseContent = readJsonFile("score-response");
81-
WebServiceClient client = createSuccessClient("score", 200, responseContent);
82-
Transaction request = fullTransactionEmailMd5();
83-
ScoreResponse response = client.score(request);
80+
var responseContent = readJsonFile("score-response");
81+
var client = createSuccessClient("score", 200, responseContent);
82+
var request = fullTransactionEmailMd5();
83+
var response = client.score(request);
8484

8585
JSONAssert.assertEquals(responseContent, response.toJson(), true);
8686
verifyRequestFor(wireMock, "score", "full-request-email-md5");
8787
}
8888

8989
@Test
9090
public void testFullInsightsTransaction() throws Exception {
91-
String responseContent = readJsonFile("insights-response");
92-
WebServiceClient client = createSuccessClient("insights", 200, responseContent);
93-
Transaction request = fullTransaction();
94-
InsightsResponse response = client.insights(request);
91+
var responseContent = readJsonFile("insights-response");
92+
var client = createSuccessClient("insights", 200, responseContent);
93+
var request = fullTransaction();
94+
var response = client.insights(request);
9595

9696
// We use non-strict checking as there is some extra stuff in the serialized
9797
// object, most notably the "name" field in the GeoIP2 InsightsResponse subobjects.
@@ -118,7 +118,7 @@ public void testFullInsightsTransaction() throws Exception {
118118

119119
assertTrue(response.getCreditCard().isVirtual());
120120

121-
List<IpRiskReason> reasons = response.getIpAddress().getRiskReasons();
121+
var reasons = response.getIpAddress().getRiskReasons();
122122

123123
assertEquals(2, reasons.size(), "two IP risk reasons");
124124
assertEquals(
@@ -130,10 +130,10 @@ public void testFullInsightsTransaction() throws Exception {
130130

131131
@Test
132132
public void testFullFactorsTransaction() throws Exception {
133-
String responseContent = readJsonFile("factors-response");
134-
WebServiceClient client = createSuccessClient("factors", 200, responseContent);
135-
Transaction request = fullTransaction();
136-
FactorsResponse response = client.factors(request);
133+
var responseContent = readJsonFile("factors-response");
134+
var client = createSuccessClient("factors", 200, responseContent);
135+
var request = fullTransaction();
136+
var response = client.factors(request);
137137

138138
// We use non-strict checking as there is some extra stuff in the serialized
139139
// object, most notably the "name" field in the GeoIP2 InsightsResponse subobjects.
@@ -161,8 +161,8 @@ public void testFullFactorsTransaction() throws Exception {
161161

162162
@Test
163163
public void testRequestEncoding() throws Exception {
164-
WebServiceClient client = createSuccessClient("insights", 200, "{}");
165-
Transaction request = new Transaction.Builder(
164+
var client = createSuccessClient("insights", 200, "{}");
165+
var request = new Transaction.Builder(
166166
new Device.Builder(InetAddress.getByName("1.1.1.1")).build()
167167
).shipping(
168168
new Shipping.Builder()
@@ -178,28 +178,28 @@ public void testRequestEncoding() throws Exception {
178178

179179
@Test
180180
public void test200WithNoBody() throws Exception {
181-
WebServiceClient client = createSuccessClient("insights", 200, "");
182-
Transaction request = fullTransaction();
183-
Exception ex = assertThrows(MinFraudException.class, () -> client.insights(request));
181+
var client = createSuccessClient("insights", 200, "");
182+
var request = fullTransaction();
183+
var ex = assertThrows(MinFraudException.class, () -> client.insights(request));
184184

185185
assertThat(ex.getMessage(),
186186
matchesPattern("Received a 200 response but could not decode it as JSON"));
187187
}
188188

189189
@Test
190190
public void test200WithInvalidJson() throws Exception {
191-
WebServiceClient client = createSuccessClient("insights", 200, "{");
192-
Transaction request = fullTransaction();
191+
var client = createSuccessClient("insights", 200, "{");
192+
var request = fullTransaction();
193193

194-
Exception ex = assertThrows(MinFraudException.class, () -> client.insights(request));
194+
var ex = assertThrows(MinFraudException.class, () -> client.insights(request));
195195

196196
assertEquals("Received a 200 response but could not decode it as JSON",
197197
ex.getMessage());
198198
}
199199

200200
@Test
201201
public void testInsufficientCredit() {
202-
Exception ex = assertThrows(InsufficientFundsException.class, () -> createInsightsError(
202+
var ex = assertThrows(InsufficientFundsException.class, () -> createInsightsError(
203203
402,
204204
"application/json",
205205
"{\"code\":\"INSUFFICIENT_FUNDS\",\"error\":\"out of credit\"}"
@@ -214,7 +214,7 @@ public void testInsufficientCredit() {
214214
"LICENSE_KEY_REQUIRED",
215215
"USER_ID_REQUIRED"})
216216
public void testInvalidAuth(String code) {
217-
Exception ex = assertThrows(AuthenticationException.class, () ->
217+
var ex = assertThrows(AuthenticationException.class, () ->
218218
createInsightsError(
219219
401,
220220
"application/json",
@@ -226,7 +226,7 @@ public void testInvalidAuth(String code) {
226226

227227
@Test
228228
public void testPermissionRequired() {
229-
Exception ex = assertThrows(PermissionRequiredException.class, () -> createInsightsError(
229+
var ex = assertThrows(PermissionRequiredException.class, () -> createInsightsError(
230230
403,
231231
"application/json",
232232
"{\"code\":\"PERMISSION_REQUIRED\",\"error\":\"Permission required\"}"
@@ -236,7 +236,7 @@ public void testPermissionRequired() {
236236

237237
@Test
238238
public void testInvalidRequest() {
239-
Exception ex = assertThrows(InvalidRequestException.class, () ->
239+
var ex = assertThrows(InvalidRequestException.class, () ->
240240
createInsightsError(
241241
400,
242242
"application/json",
@@ -248,7 +248,7 @@ public void testInvalidRequest() {
248248

249249
@Test
250250
public void test400WithInvalidJson() {
251-
Exception ex = assertThrows(HttpException.class, () ->
251+
var ex = assertThrows(HttpException.class, () ->
252252
createInsightsError(
253253
400,
254254
"application/json",
@@ -261,7 +261,7 @@ public void test400WithInvalidJson() {
261261

262262
@Test
263263
public void test400WithNoBody() {
264-
Exception ex = assertThrows(HttpException.class, () ->
264+
var ex = assertThrows(HttpException.class, () ->
265265
createInsightsError(
266266
400,
267267
"application/json",
@@ -274,7 +274,7 @@ public void test400WithNoBody() {
274274

275275
@Test
276276
public void test400WithUnexpectedContentType() {
277-
Exception ex = assertThrows(HttpException.class, () ->
277+
var ex = assertThrows(HttpException.class, () ->
278278
createInsightsError(
279279
400,
280280
"text/plain",
@@ -288,7 +288,7 @@ public void test400WithUnexpectedContentType() {
288288

289289
@Test
290290
public void test400WithUnexpectedJson() {
291-
Exception ex = assertThrows(HttpException.class, () ->
291+
var ex = assertThrows(HttpException.class, () ->
292292
createInsightsError(
293293
400,
294294
"application/json",
@@ -302,7 +302,7 @@ public void test400WithUnexpectedJson() {
302302

303303
@Test
304304
public void test300() {
305-
Exception ex = assertThrows(HttpException.class, () ->
305+
var ex = assertThrows(HttpException.class, () ->
306306
createInsightsError(
307307
300,
308308
"application/json",
@@ -315,7 +315,7 @@ public void test300() {
315315

316316
@Test
317317
public void test500() {
318-
Exception ex = assertThrows(HttpException.class, () ->
318+
var ex = assertThrows(HttpException.class, () ->
319319
createInsightsError(
320320
500,
321321
"application/json",
@@ -363,9 +363,9 @@ private WebServiceClient createClient(String service, int status, String content
363363

364364
@Test
365365
public void testHttpClientWorks() {
366-
HttpClient customClient = HttpClient.newBuilder().build();
366+
var customClient = HttpClient.newBuilder().build();
367367

368-
WebServiceClient client = new WebServiceClient.Builder(6, "0123456789")
368+
var client = new WebServiceClient.Builder(6, "0123456789")
369369
.httpClient(customClient)
370370
.build();
371371

@@ -375,9 +375,9 @@ public void testHttpClientWorks() {
375375

376376
@Test
377377
public void testHttpClientWithConnectTimeoutThrowsException() {
378-
HttpClient customClient = HttpClient.newBuilder().build();
378+
var customClient = HttpClient.newBuilder().build();
379379

380-
Exception ex = assertThrows(IllegalArgumentException.class, () ->
380+
var ex = assertThrows(IllegalArgumentException.class, () ->
381381
new WebServiceClient.Builder(6, "0123456789")
382382
.httpClient(customClient)
383383
.connectTimeout(Duration.ofSeconds(5))
@@ -390,9 +390,9 @@ public void testHttpClientWithConnectTimeoutThrowsException() {
390390

391391
@Test
392392
public void testHttpClientWithProxyThrowsException() {
393-
HttpClient customClient = HttpClient.newBuilder().build();
393+
var customClient = HttpClient.newBuilder().build();
394394

395-
Exception ex = assertThrows(IllegalArgumentException.class, () ->
395+
var ex = assertThrows(IllegalArgumentException.class, () ->
396396
new WebServiceClient.Builder(6, "0123456789")
397397
.httpClient(customClient)
398398
.proxy(java.net.ProxySelector.of(null))

src/test/java/com/maxmind/minfraud/exception/HttpExceptionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class HttpExceptionTest {
99

1010
@Test
1111
public void testHttpException() throws Exception {
12-
URI uri = new URI("https://www.maxmind.com/");
13-
HttpException e = new HttpException("message", 200, uri);
12+
var uri = new URI("https://www.maxmind.com/");
13+
var e = new HttpException("message", 200, uri);
1414
assertEquals(200, e.httpStatus(), "correct status");
1515
assertEquals(uri, e.uri(), "correct URL");
1616
}

src/test/java/com/maxmind/minfraud/exception/InvalidRequestExceptionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class InvalidRequestExceptionTest {
99

1010
@Test
1111
public void testInvalidRequestException() throws Exception {
12-
URI uri = new URI("https://www.maxmind.com/");
13-
String code = "INVALID_INPUT";
14-
int status = 400;
15-
InvalidRequestException e = new InvalidRequestException("message", code, status, uri, null);
12+
var uri = new URI("https://www.maxmind.com/");
13+
var code = "INVALID_INPUT";
14+
var status = 400;
15+
var e = new InvalidRequestException("message", code, status, uri, null);
1616
assertEquals(code, e.code(), "correct code");
1717
assertEquals(status, e.httpStatus(), "correct status");
1818
assertEquals(uri, e.uri(), "correct URL");

src/test/java/com/maxmind/minfraud/request/AccountTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public class AccountTest {
99

1010
@Test
1111
public void testUserId() {
12-
Account account = new Builder().userId("usr").build();
12+
var account = new Builder().userId("usr").build();
1313
assertEquals("usr", account.userId());
1414
}
1515

1616
@Test
1717
public void testUsername() {
18-
Account account = new Builder().username("username").build();
18+
var account = new Builder().username("username").build();
1919
assertEquals("14c4b06b824ec593239362517f538b29", account.usernameMd5());
2020
}
2121
}

0 commit comments

Comments
 (0)