Skip to content

test: add Java switch tests and mark unreachable getMethodName fallback with c8 ignore#478

Merged
askpt merged 2 commits into
mainfrom
repo-assist/improve-java-coverage-20260726-06cc6a5651461acf
Jul 26, 2026
Merged

test: add Java switch tests and mark unreachable getMethodName fallback with c8 ignore#478
askpt merged 2 commits into
mainfrom
repo-assist/improve-java-coverage-20260726-06cc6a5651461acf

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This pull request was created by Repo Assist, an automated AI assistant.

Summary

Two improvements to the Java analyzer:

  1. New tests for Java switch analysis — covers both the traditional switch statement and the modern Java 14+ arrow-case switch expression.
  2. Defensive c8 ignore annotation on the getMethodName fallback path — marks the unreachable return methodName (no enclosing class found) so coverage reports accurately reflect only executable code paths.

Changes

src/metricsAnalyzer/languages/javaAnalyzer.ts

Annotated the return methodName fallback in getMethodName with /* c8 ignore start/stop */. Valid Java always places methods inside a class_declaration, interface_declaration, enum_declaration, or record_declaration. The fallback is a defensive guard — impossible to reach with syntactically valid Java source.

src/unit/unit.test.ts

Added two new tests to the Java Analyzer: Enum methods suite (alongside existing tests, they're logically close to other complex-method-name tests):

  • Traditional switch: switch (n) { case 1: ... }switch_expression node in tree-sitter-java → complexity +1, reason "switch statement".
  • Modern switch expression: switch (day) { case "X" -> 6; } → same switch_expression node → complexity +1, confirming both Java switch forms are correctly analyzed.

Test Status

npm run compile  ✅  (0 errors)
npm run lint     ✅  (0 warnings)
npm run test:unit  ✅  200 passing, 0 failing  (was 198)

Coverage javaAnalyzer.ts: 99.53% lines, 96% branches (remaining uncovered branches are /* c8 ignore */-annotated defensive dead paths).

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1c6668b751c51af8571f01204ceffb19362e0f66

…h c8 ignore

- Add two new tests for Java switch analysis:
  * Traditional switch statement (adds +1 complexity)
  * Modern Java 14+ switch expression (also adds +1 via switch_expression node)
- Annotate the unreachable getMethodName fallback (return methodName without
  class prefix) with /* c8 ignore start/stop */ — valid Java always has methods
  inside a class, interface, enum, or record declaration

Tests: 200 passing (was 198)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [repo-assist] test: add Java switch tests and mark unreachable getMethodName fallback with c8 ignore test: add Java switch tests and mark unreachable getMethodName fallback with c8 ignore Jul 26, 2026
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.43%. Comparing base (7e0ee42) to head (27e9ce6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #478      +/-   ##
==========================================
+ Coverage   81.40%   81.43%   +0.02%     
==========================================
  Files          13       13              
  Lines        4345     4346       +1     
  Branches      440      440              
==========================================
+ Hits         3537     3539       +2     
+ Misses        807      806       -1     
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt
askpt marked this pull request as ready for review July 26, 2026 12:59
@askpt
askpt self-requested a review as a code owner July 26, 2026 12:59
Copilot AI review requested due to automatic review settings July 26, 2026 12:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Java cognitive complexity analyzer test coverage around switch constructs and adjusts coverage annotations in the Java analyzer’s method-name resolution fallback.

Changes:

  • Added unit tests for Java switch parsing/complexity, including a Java 14+ arrow-case switch expression.
  • Added c8 coverage-ignore annotations around the getMethodName fallback return in the Java analyzer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/unit/unit.test.ts Adds Java switch tests (traditional + Java 14+ switch expression) to the unit test suite.
src/metricsAnalyzer/languages/javaAnalyzer.ts Adds c8 ignore start/stop around the getMethodName fallback return path.

Comment thread src/unit/unit.test.ts Outdated
Comment thread src/unit/unit.test.ts Outdated
Comment thread src/metricsAnalyzer/languages/javaAnalyzer.ts Outdated
…gnore annotation

Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Copilot finished work on behalf of askpt July 26, 2026 13:11
@askpt
askpt enabled auto-merge (squash) July 26, 2026 13:13
@askpt
askpt merged commit a94c59d into main Jul 26, 2026
8 checks passed
@askpt
askpt deleted the repo-assist/improve-java-coverage-20260726-06cc6a5651461acf branch July 26, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants