From 6eeeb9ca4196ab4be78064719d2fcc0632eefcb0 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Apr 2026 20:14:13 +0000 Subject: [PATCH 1/2] Add equivalence tests for capMissingBytes old vs new formula Adds two private static helper methods to StreamBufferTest that extract the old (if-guarded) and new (unconditional Math.min) capping formulas verbatim, plus a @DataProvider with 10 input rows covering all three equivalence classes: A: maximumAvailableBytes < missingBytes (old if-branch fires) B: maximumAvailableBytes == missingBytes (boundary) C: maximumAvailableBytes > missingBytes (old if skipped, incl. > INT_MAX) The parameterised test capMissingBytes_oldAndNewFormula_returnSameResult asserts that both formulas produce identical int results for every row, proving the commit cb66b68 refactor is semantically correct. https://claude.ai/code/session_01HYTj7Mg73S1Le9QTn7XFxu --- .../streambuffer/StreamBufferTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/test/java/net/ladenthin/streambuffer/StreamBufferTest.java b/src/test/java/net/ladenthin/streambuffer/StreamBufferTest.java index 48e58b3..b3db5e0 100644 --- a/src/test/java/net/ladenthin/streambuffer/StreamBufferTest.java +++ b/src/test/java/net/ladenthin/streambuffer/StreamBufferTest.java @@ -2188,4 +2188,51 @@ public void available_afterPartialReadFromSingleEntry_returnsRemainingCount() th assertThat(sb.getInputStream().available(), is(5)); } // + + // + + // Extracts the OLD capping formula from the guarded if-block (pre-cb66b68) + private static int capMissingBytesOld(long maximumAvailableBytes, int missingBytes) { + if (maximumAvailableBytes < missingBytes) { + return (int) Math.min(maximumAvailableBytes, Integer.MAX_VALUE); + } + return missingBytes; + } + + // Extracts the NEW capping formula (unconditional Math.min, post-cb66b68) + private static int capMissingBytesNew(long maximumAvailableBytes, int missingBytes) { + return (int) Math.min(maximumAvailableBytes, (long) missingBytes); + } + + @DataProvider + public static Object[][] capMissingBytesInputs() { + return new Object[][] { + // Case A: maxAvail < missingBytes (old if-branch fires, new Math.min picks maxAvail) + { 1L, 5 }, // trivially small + { 3L, 5 }, // standard small case + { (long) Integer.MAX_VALUE - 1, Integer.MAX_VALUE }, // one below INT_MAX + + // Case B: maxAvail == missingBytes (boundary: old skips if, new Math.min picks either) + { 5L, 5 }, // small equality + { (long) Integer.MAX_VALUE, Integer.MAX_VALUE }, // equality at INT_MAX + + // Case C: maxAvail > missingBytes (old skips if, new Math.min picks missingBytes) + { 9L, 3 }, // standard: more available than needed + { (long) Integer.MAX_VALUE + 1L, Integer.MAX_VALUE }, // maxAvail just above INT_MAX + { (long) Integer.MAX_VALUE + 1L, 5 }, // maxAvail > INT_MAX, small missing + { 3_000_000_000L, 100 }, // large long, small int + { Long.MAX_VALUE, 1 }, // extreme: largest possible long + }; + } + + @Test + @UseDataProvider("capMissingBytesInputs") + public void capMissingBytes_oldAndNewFormula_returnSameResult( + long maximumAvailableBytes, int missingBytes) { + int oldResult = capMissingBytesOld(maximumAvailableBytes, missingBytes); + int newResult = capMissingBytesNew(maximumAvailableBytes, missingBytes); + assertThat(newResult, is(oldResult)); + } + + // } From 10339395100162b7419710e455927aef19bb2588 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 8 Apr 2026 20:38:29 +0000 Subject: [PATCH 2/2] Update Coveralls badge to current URL format Old URLs used /repos// and /r// paths which are legacy. Updated to /repos/github// and /github// as required by the current Coveralls API. https://claude.ai/code/session_01HYTj7Mg73S1Le9QTn7XFxu --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60d53dd..eb5bc63 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Travis build status](https://travis-ci.org/bernardladenthin/streambuffer.svg)](https://travis-ci.org/bernardladenthin/streambuffer) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.ladenthin/streambuffer/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.ladenthin/streambuffer) -[![Coverage Status](https://coveralls.io/repos/bernardladenthin/streambuffer/badge.svg)](https://coveralls.io/r/bernardladenthin/streambuffer) +[![Coverage Status](https://coveralls.io/repos/github/bernardladenthin/streambuffer/badge.svg)](https://coveralls.io/github/bernardladenthin/streambuffer) [![Codecov](https://codecov.io/github/bernardladenthin/streambuffer/coverage.png)](https://codecov.io/gh/bernardladenthin/streambuffer) [![Coverity Scan Build Status](https://scan.coverity.com/projects/5453/badge.svg)](https://scan.coverity.com/projects/5453) [![Known Vulnerabilities](https://snyk.io/test/github/bernardladenthin/streambuffer/badge.svg?targetFile=pom.xml)](https://snyk.io/test/github/bernardladenthin/streambuffer?targetFile=pom.xml)