This is an automated email from the ASF dual-hosted git repository.

He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-http.git


The following commit(s) were added to refs/heads/main by this push:
     new 121e66da6 refactor: apply misc Java 11-17 improvements (#1094)
121e66da6 is described below

commit 121e66da610b418786bd66fd0f066ebb46edc238
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Fri Jun 26 16:22:22 2026 +0800

    refactor: apply misc Java 11-17 improvements (#1094)
    
    Motivation:
    Modernize Java code to use Java 11-17 APIs for cleaner, more
    idiomatic code.
    
    Modification:
    - Map.forEach replacing entrySet iteration loops
    - Text blocks replacing multi-line string concatenation
    - Records replacing simple data holder classes (test code only)
    - List.copyOf replacing Collections.unmodifiableList(new ArrayList<>())
    
    Result:
    Cleaner, more modern Java code using Java 11-17 features.
---
 .../javadsl/server/JsonStreamingExamplesTest.java    |  6 +++++-
 .../http/javadsl/server/examples/petstore/Pet.java   | 20 +-------------------
 .../server/examples/petstore/PetStoreExample.java    |  4 ++--
 .../server/directives/ParameterDirectivesTest.java   |  8 ++++++--
 .../server/examples/petstore/PetStoreAPITest.java    |  8 ++++----
 5 files changed, 18 insertions(+), 28 deletions(-)

diff --git 
a/docs/src/test/java/docs/http/javadsl/server/JsonStreamingExamplesTest.java 
b/docs/src/test/java/docs/http/javadsl/server/JsonStreamingExamplesTest.java
index 64f8dbf75..36baff0b3 100644
--- a/docs/src/test/java/docs/http/javadsl/server/JsonStreamingExamplesTest.java
+++ b/docs/src/test/java/docs/http/javadsl/server/JsonStreamingExamplesTest.java
@@ -223,7 +223,11 @@ public class JsonStreamingExamplesTest extends 
JUnitJupiterRouteTest {
     routes
         .run(HttpRequest.GET("/tweets?n=2").addHeader(acceptCsv))
         .assertStatusCode(200)
-        .assertEntity("12,Hello World!\n" + "12,Hello World!\n");
+        .assertEntity(
+            """
+            12,Hello World!
+            12,Hello World!
+            """);
 
     // test responses to potential errors
     final Accept acceptText = Accept.create(MediaRanges.ALL_APPLICATION);
diff --git 
a/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/Pet.java
 
b/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/Pet.java
index a8195696f..90c0e2782 100644
--- 
a/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/Pet.java
+++ 
b/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/Pet.java
@@ -13,24 +13,6 @@
 
 package org.apache.pekko.http.javadsl.server.examples.petstore;
 
-import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-public class Pet {
-  private final int id;
-  private final String name;
-
-  @JsonCreator
-  public Pet(@JsonProperty("id") int id, @JsonProperty("name") String name) {
-    this.id = id;
-    this.name = name;
-  }
-
-  public int getId() {
-    return id;
-  }
-
-  public String getName() {
-    return name;
-  }
-}
+public record Pet(@JsonProperty("id") int id, @JsonProperty("name") String 
name) {}
diff --git 
a/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreExample.java
 
b/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreExample.java
index 526abcc44..62c0a850b 100644
--- 
a/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreExample.java
+++ 
b/http-tests/src/main/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreExample.java
@@ -39,12 +39,12 @@ public class PetStoreExample {
 
   // #marshall
   private static Route putPetHandler(Map<Integer, Pet> pets, Pet thePet) {
-    pets.put(thePet.getId(), thePet);
+    pets.put(thePet.id(), thePet);
     return complete(StatusCodes.OK, thePet, Jackson.<Pet>marshaller());
   }
 
   private static Route alternativeFuturePutPetHandler(Map<Integer, Pet> pets, 
Pet thePet) {
-    pets.put(thePet.getId(), thePet);
+    pets.put(thePet.id(), thePet);
     CompletableFuture<Pet> futurePet = CompletableFuture.supplyAsync(() -> 
thePet);
     return completeOKWithFuture(futurePet, Jackson.<Pet>marshaller());
   }
diff --git 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/ParameterDirectivesTest.java
 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/ParameterDirectivesTest.java
index 286eab163..c53210acc 100644
--- 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/ParameterDirectivesTest.java
+++ 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/ParameterDirectivesTest.java
@@ -404,8 +404,12 @@ public class ParameterDirectivesTest extends 
JUnitJupiterRouteTest {
 
                   StringBuilder res = new StringBuilder();
                   res.append(paramEntries.size()).append(": [");
-                  for (Map.Entry<String, String> entry : entries)
-                    res.append(entry.getKey()).append(" -> 
").append(entry.getValue()).append(", ");
+                  entries.forEach(
+                      entry ->
+                          res.append(entry.getKey())
+                              .append(" -> ")
+                              .append(entry.getValue())
+                              .append(", "));
                   res.append(']');
                   return complete(res.toString());
                 }));
diff --git 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreAPITest.java
 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreAPITest.java
index 0081a276a..d9cf93e52 100644
--- 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreAPITest.java
+++ 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/examples/petstore/PetStoreAPITest.java
@@ -33,8 +33,8 @@ public class PetStoreAPITest extends JUnitJupiterRouteTest {
     
response.assertStatusCode(StatusCodes.OK).assertMediaType("application/json");
 
     Pet pet = response.entity(Jackson.unmarshaller(Pet.class));
-    assertEquals("cat", pet.getName());
-    assertEquals(1, pet.getId());
+    assertEquals("cat", pet.name());
+    assertEquals(1, pet.id());
   }
 
   @Test
@@ -54,8 +54,8 @@ public class PetStoreAPITest extends JUnitJupiterRouteTest {
     response.assertStatusCode(StatusCodes.OK);
 
     Pet pet = response.entity(Jackson.unmarshaller(Pet.class));
-    assertEquals("giraffe", pet.getName());
-    assertEquals(1, pet.getId());
+    assertEquals("giraffe", pet.name());
+    assertEquals(1, pet.id());
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to