Skip to content

Commit 14eabda

Browse files
committed
refactor: streamline Java test method and update collection preallocation guidance
1 parent 76b79a5 commit 14eabda

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

instructions/java.instructions.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,10 @@ class FindByStatus {
326326
@Test
327327
@DisplayName("returns matching orders when status exists")
328328
void shouldReturnOrders_whenStatusExists() {
329-
// arrange
330329
when(repository.findByStatus(Status.PENDING)).thenReturn(List.of(order));
331-
// act
330+
332331
var result = service.findByStatus(Status.PENDING);
333-
// assert
332+
334333
assertThat(result).hasSize(1).containsExactly(order);
335334
}
336335
}
@@ -341,8 +340,7 @@ class FindByStatus {
341340
- Profile before optimizing; use JFR (Java Flight Recorder) and async-profiler
342341
- Choose the right garbage collector: G1GC (default), ZGC (low latency), Shenandoah (low latency)
343342
- Use `StringBuilder` for string concatenation in loops; single-expression concatenation is optimized by the compiler
344-
- Preallocate collections with expected capacity: `new ArrayList<>(expectedSize)`, `HashMap.newHashMap(expectedSize)` (Java 19+)
345-
- Use primitive-specialized collections from Eclipse Collections or Koloboke for hot paths with large datasets
343+
- Preallocate collections with expected capacity: `new ArrayList<>(expectedSize)`, `new HashMap<>((int) (expectedSize / 0.75f) + 1)` when sizing for the default load factor
346344
- Use connection pooling (HikariCP) for database connections
347345
- Use `HttpClient` (java.net.http, Java 11+) instead of legacy `HttpURLConnection`
348346
- Avoid boxing in hot loops; use `int` not `Integer` where possible

0 commit comments

Comments
 (0)