Add Regression Test Coverage For LambdaProxyMiddleware Route Miss#177
Merged
stevehu merged 1 commit intoJul 21, 2026
Conversation
…te miss Extract the matcher lookup from execute into a package-private resolveFunctionName so the routing behaviour can be asserted directly, and add a package-private constructor that builds only the route table without creating an AWS Lambda client. Add LambdaProxyMiddlewareTest covering the happy path, path template matching, and both routing-miss paths. The two miss cases reproduce the NPE from #173 when run against the pre-#174 code. Also guard the existing MockLambdaProxyMiddlewareTest assertion, which used the same unguarded map.get(method).match(path) pattern that #173 was about. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds regression coverage for the previously reported LambdaProxyMiddleware routing miss NPE (method has no matcher), and introduces a small test seam so the real routing/matcher logic can be exercised without constructing an AWS Lambda client.
Changes:
- Extracts
resolveFunctionName(path, method)fromexecute()to centralize route resolution and safely handle “no matcher” / “no match” miss cases. - Adds a package-private constructor that builds only the route table (no AWS client) to enable unit testing of route-miss behavior end-to-end through
execute(). - Adds new
LambdaProxyMiddlewareTestcoverage and hardensMockLambdaProxyMiddlewareTestto avoid the same null-deref pattern.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/java/com/networknt/aws/lambda/handler/middleware/proxy/LambdaProxyMiddleware.java | Adds route-resolution helper and a test-only seam constructor; execute() now uses extracted routing logic. |
| src/test/java/com/networknt/aws/lambda/handler/middleware/proxy/LambdaProxyMiddlewareTest.java | New tests covering match and miss paths (including regression for missing method matcher). |
| src/test/java/com/networknt/aws/lambda/middleware/proxy/MockLambdaProxyMiddlewareTest.java | Guards test setup against missing matcher/match result to avoid null dereferences. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
114
to
115
| LOG.trace("Function name: {}", functionName); | ||
| var res = this.invokeFunction(this.client, functionName, exchange); |
Comment on lines
+89
to
+93
| var middleware = new LambdaProxyMiddleware(FUNCTIONS); | ||
| Status status = Assertions.assertDoesNotThrow( | ||
| () -> middleware.execute(exchangeFor("/v1/unknown", "GET"))); | ||
| Assertions.assertEquals(LambdaProxyMiddleware.FAILED_TO_INVOKE_LAMBDA, status.getCode()); | ||
| } |
Contributor
Author
|
The routing extraction preserves existing behavior while adding regression coverage for missing method and path matchers. The focused tests and full Maven test suite pass. |
stevehu
deleted the
176-add-regression-test-coverage-for-lambdaproxymiddleware-route-miss
branch
July 21, 2026 19:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #176.
The NPE fixed in #174 shipped without a test. This adds one that actually reproduces it, plus the seam needed to write it.
Why a seam was needed
LambdaProxyMiddleware's only constructor callsinitClient, which builds a real Netty-backedLambdaAsyncClient, so the class could not be instantiated in a unit test. That is why the existing coverage lives inMockLambdaProxyMiddleware— a separate class with its ownexecutethat resolves functions through a plain map lookup:The mock never exercises the matcher logic, so no test written against it could have caught #173 or would catch a regression.
Changes
resolveFunctionName(path, method)— extracted fromexecute. Returnsnullfor both miss cases (no matcher for the method, and matcher present but no template matches), so the caller keeps treating every routing miss identically. Pure extraction, no behaviour change.clientorconfigis touched, so a null-client instance is sufficient to test it end to end throughexecute.LambdaProxyMiddlewareTest— six cases: happy path, path template matching, both miss paths at theresolveFunctionNamelevel, and both miss paths throughexecuteassertingERR10086and that the description identifies the unroutable endpoint.MockLambdaProxyMiddlewareTest— the existing assertion used the same unguardedmap.get(method).match(path)pattern that NPE Occurs When A Call Path Matches A Function But Not The Method #173 was about, so it would NPE identically for an unmapped method. Now guarded.Verification
The two miss-path tests were run against the pre-#174 code by temporarily reverting the null guard, and they fail with exactly the reported error:
With the guard restored:
Tests run: 79, Failures: 0, Errors: 0, Skipped: 4— 73 before this PR, 6 added.BUILD SUCCESS,git diff --checkclean.Note for reviewers
The package-private constructor is test-only visibility rather than a public API addition. If you would rather not carry a test seam on the production class, the alternative is making
MockLambdaProxyMiddlewaredelegate to the real routing logic instead of duplicating a divergent copy — happy to switch to that if you prefer.🤖 Generated with Claude Code