Refactor: isolate status logic & remove magic numbers#2490
Conversation
…s code mapping to a constant map (STATUS_CODE_MAP), create dedicated methods statusFromCode() and applyStatus() to handle status code parsing and callback invocation. Also extract content extraction to a reusable extractContent() method. This eliminates the long switch with hardcoded integers and makes the STATUS_CODE handling self-documenting and easier to extend.
There was a problem hiding this comment.
Code Review
This pull request refactors the status code processing logic in InstrumentationTestRunnerProcessor.java by replacing a switch-case block with a static map lookup and extracting helper methods like applyStatus and extractContent. However, calling applyStatus(code) outside of the try block introduces a bug where exceptions bypass the finally block, preventing onTestFinished from executing and failing to reset currentTest. It is recommended to move this call inside the try block and remove the Portuguese comment.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| applyStatus(code); | ||
| try { | ||
| switch (statusInt) { | ||
| case 1: | ||
| currentTest.setStatus(Status.STARTED); | ||
| onTestStart(currentTest.build()); | ||
| break; | ||
| case 0: | ||
| currentTest.setStatus(Status.PASSED); | ||
| break; | ||
| case -1: | ||
| currentTest.setStatus(Status.ERROR); | ||
| break; | ||
| case -2: | ||
| currentTest.setStatus(Status.FAILED); | ||
| break; | ||
| case -4: | ||
| currentTest.setStatus(Status.ASSUMPTION_FAILURE); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException( | ||
| String.format("Illegal test instrumentation code: \"%s\"", statusCode)); | ||
| } | ||
| // A chamada onTestStart, se necessária, já foi feita em applyStatus | ||
| } finally { | ||
| onTestFinished(currentTest.build()); | ||
| currentTest = null; | ||
| } |
There was a problem hiding this comment.
By calling applyStatus(code) outside of the try block, any IllegalArgumentException thrown by statusFromCode (when an invalid status code is encountered) will bypass the finally block. This means onTestFinished won't be called and currentTest won't be reset to null, which changes the original error-handling behavior and can corrupt the state for subsequent lines.
Additionally, the empty try block with a Portuguese comment is awkward and inconsistent with the rest of the English codebase.
We should move applyStatus(code) inside the try block.
try {
applyStatus(code);
} finally {
onTestFinished(currentTest.build());
currentTest = null;
}…s code mapping to a constant map (STATUS_CODE_MAP), create dedicated methods statusFromCode() and applyStatus() to handle status code parsing and callback invocation. Also extract content extraction to a reusable extractContent() method. This eliminates the long switch with hardcoded integers and makes the STATUS_CODE handling self-documenting and easier to extend.
|
sorry, everything in the tools directory is obsolete code, and we aren't accepting PRs for it. |
…s code mapping to a constant map (STATUS_CODE_MAP), create dedicated methods statusFromCode() and applyStatus() to handle status code parsing and callback invocation. Also extract content extraction to a reusable extractContent() method. This eliminates the long switch with hardcoded integers and makes the STATUS_CODE handling self-documenting and easier to extend.
Overview
This change isolates the logic for converting the AM instrument's status codes into values for the Status enum, eliminating the magic numbers (1, 0, -1, -2, -4) scattered throughout the processLine method.
Proposed Changes