Agent skill

Unit Test Exception Handler

by giuseppe-trisciuoglio in giuseppe-trisciuoglio/developer-kit

Provides patterns for unit testing @ExceptionHandler and @ControllerAdvice in Spring Boot applications.

MITAuto-check: notesTesting & QA

Install Unit Test Exception Handler

skills CLI
$ npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-exception-handler -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install giuseppe-trisciuoglio/developer-kit unit-test-exception-handler --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/giuseppe-trisciuoglio/developer-kit.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/developer-kit-java/skills/unit-test-exception-handler .claude/skills/unit-test-exception-handler && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
unit-test-exception-handler
GitHub stars
356
Token cost
~1.6k tokens
SKILL.md length
369 words
Files
2 (incl. references)
Skills in repo
115
Repo updated
First seen
Licence
MIT

At a glance

Provides patterns for unit testing @ExceptionHandler and @ControllerAdvice in Spring Boot applications.

  • Works in 6 steps: Create a test controller that throws… → Register ControllerAdvice via… → Assert HTTP status codes with… → …
  • Writing Spring exception handler tests
  • SKILL.md covers Overview, When to Use, Instructions and Examples, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Unit Test Exception Handler is an agent skill from giuseppe-trisciuoglio/developer-kit. Provides patterns for unit testing @ExceptionHandler and @ControllerAdvice in Spring Boot applications. Validates error response formatting, mocks exceptions, verifies HTTP status codes, tests field-level validation errors, and asserts custom error payloads. Use when writing Spring exception handler tests, REST API error tests, or mocking controller advice.

Its SKILL.md is about 1.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including reference files (for example `references/examples.md`).

It sits in Testing & QA, covering Unit testing and Backend development. It works with Spring Boot. The repository describes itself as: Modular plugin marketplace for Claude Code and agentic CLIs, with validated, spec-driven skills, agents, commands, and workflows for Java, TypeScript, Python, PHP, AWS, and AI. The licence is MIT.

When your agent uses it

  • Writing Spring exception handler tests
  • REST API error tests
  • Mocking controller advice

Example prompts

  • “Use the unit-test-exception-handler skill to provide patterns for unit testing @ExceptionHandler and @ControllerAdvice in Spring Boot applications”
  • “/unit-test-exception-handler”

Requirements

  • Pre-approved tools (allowed-tools): Read, Write, Bash, Glob, Grep

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Create a test controller that throws specific exceptions to trigger each @ExceptionHandler
  2. Register ControllerAdvice via setControllerAdvice() on MockMvcBuilders.standaloneSetup()
  3. Assert HTTP status codes with .andExpect(status().isXxx())
  4. Verify error response fields using jsonPath("$.field") matchers
  5. Test validation errors by sending invalid payloads and checking MethodArgumentNotValidException produces field-level details
  6. Debug failures with .andDo(print()) — if handler not invoked, verify setControllerAdvice() is called and exception type matches

What it can do on your machine

Read from SKILL.md and the folder at commit fe73fb3. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Bash
    • Glob
    • Grep

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are java).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Unit Test Exception Handler loads about 1.6k tokens when it runs, and up to ~2.4k if it reads all its reference files. Until then it costs about 98 tokens; SKILL.md has 369 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~98
When it runs · the whole SKILL.md, loaded when a task matches
~1.6k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~2.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Bash, Glob, Grep

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from giuseppe-trisciuoglio/developer-kit at commit fe73fb3, republished under its MIT licence (© giuseppe-trisciuoglio). 369 words, ~1,571 tokens.

Download SKILL.mdSave it as .claude/skills/unit-test-exception-handler/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
unit-test-exception-handler
description
Provides patterns for unit testing `@ExceptionHandler` and `@ControllerAdvice` in Spring Boot applications. Validates error response formatting, mocks exceptions, verifies HTTP status codes, tests field-level validation errors, and asserts custom error payloads. Use when writing Spring exception handler tests, REST API error tests, or mocking controller advice.
allowed-tools
Read, Write, Bash, Glob, Grep

Unit Testing ExceptionHandler and ControllerAdvice

Overview

This skill provides patterns for writing unit tests for Spring Boot exception handlers. It covers testing @ExceptionHandler methods in @ControllerAdvice classes using MockMvc, including HTTP status assertions, JSON response validation, field-level validation error testing, and mocking handler dependencies.

When to Use

  • Writing unit tests for @ExceptionHandler methods
  • Testing @ControllerAdvice global exception handling
  • Validating REST API error response formatting
  • Mocking exceptions in controller tests
  • Testing field-level validation error responses
  • Asserting custom error payloads and HTTP status codes

Instructions

  1. Create a test controller that throws specific exceptions to trigger each @ExceptionHandler
  2. Register ControllerAdvice via setControllerAdvice() on MockMvcBuilders.standaloneSetup()
  3. Assert HTTP status codes with .andExpect(status().isXxx())
  4. Verify error response fields using jsonPath("$.field") matchers
  5. Test validation errors by sending invalid payloads and checking MethodArgumentNotValidException produces field-level details
  6. Debug failures with .andDo(print()) — if handler not invoked, verify setControllerAdvice() is called and exception type matches

Examples

Exception Handler and Error DTO
java
@ControllerAdvice
public class GlobalExceptionHandler {

  @ExceptionHandler(ResourceNotFoundException.class)
  @ResponseStatus(HttpStatus.NOT_FOUND)
  public ErrorResponse handleNotFound(ResourceNotFoundException ex) {
    return new ErrorResponse(404, "Not Found", ex.getMessage());
  }

  @ExceptionHandler(ValidationException.class)
  @ResponseStatus(HttpStatus.BAD_REQUEST)
  public ErrorResponse handleValidation(ValidationException ex) {
    return new ErrorResponse(400, "Bad Request", ex.getMessage());
  }

  @ExceptionHandler(MethodArgumentNotValidException.class)
  @ResponseStatus(HttpStatus.BAD_REQUEST)
  public ValidationErrorResponse handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
    Map<String, String> errors = new HashMap<>();
    ex.getBindingResult().getFieldErrors().forEach(e -> errors.put(e.getField(), e.getDefaultMessage()));
    return new ValidationErrorResponse(400, "Validation Failed", errors);
  }
}

public record ErrorResponse(int status, String error, String message) {}
public record ValidationErrorResponse(int status, String error, Map<String, String> errors) {}
Unit Test
java
@ExtendWith(MockitoExtension.class)
class GlobalExceptionHandlerTest {

  private MockMvc mockMvc;

  @BeforeEach
  void setUp() {
    GlobalExceptionHandler handler = new GlobalExceptionHandler();
    mockMvc = MockMvcBuilders.standaloneSetup(new TestController())
        .setControllerAdvice(handler)
        .build();
  }

  @Test
  void shouldReturn404WhenResourceNotFound() throws Exception {
    mockMvc.perform(get("/api/users/999"))
        .andExpect(status().isNotFound())
        .andExpect(jsonPath("$.status").value(404))
        .andExpect(jsonPath("$.error").value("Not Found"))
        .andExpect(jsonPath("$.message").value("User not found"));
  }

  @Test
  void shouldReturn400WithFieldErrorsOnValidationFailure() throws Exception {
    mockMvc.perform(post("/api/users")
        .contentType("application/json")
        .content("{\"name\":\"\",\"email\":\"invalid\"}"))
        .andExpect(status().isBadRequest())
        .andExpect(jsonPath("$.status").value(400))
        .andExpect(jsonPath("$.errors.name").value("must not be blank"))
        .andExpect(jsonPath("$.errors.email").value("must be a valid email"));
  }
}

@RestController
@RequestMapping("/api")
class TestController {
  @GetMapping("/users/{id}") public User getUser(@PathVariable Long id) {
    throw new ResourceNotFoundException("User not found");
  }
  @PostMapping("/users") public User createUser(@RequestBody @Valid User user) {
    throw new ValidationException("Validation failed");
  }
}

Best Practices

  • Test each @ExceptionHandler method independently with a dedicated exception throw
  • Register exactly one @ControllerAdvice instance via setControllerAdvice() — never skip it
  • Assert all fields in the error response body, not just the HTTP status
  • For validation errors, verify both the field name key and the error message value
  • Use MockMvcBuilders.standaloneSetup() for isolated handler tests without full Spring context
  • Log assertion failures: chain .andDo(print()) to print request/response when a test fails
Show full SKILL.md (141 more words)Show less

Common Pitfalls

  • Handler not invoked: ensure setControllerAdvice() is called on the builder
  • JsonPath mismatch: use .andDo(print()) to inspect actual response structure
  • Status is 200: missing @ResponseStatus on the handler method
  • Duplicate handlers: @Order controls precedence; more specific exception types take priority
  • Testing handler logic instead of behavior: mock external dependencies, test only the response transformation

Constraints and Warnings

  • @ExceptionHandler specificity: more specific exception types are matched first; Exception.class catches all unmatched types
  • @ResponseStatus default: without @ResponseStatus or returning ResponseEntity, HTTP status defaults to 200
  • Global vs local scope: @ExceptionHandler in @ControllerAdvice is global; declared in a controller it is local only to that controller
  • Logging side effects: handlers that log should be verified with verify(mockLogger).logXxx(...)
  • Localization: when using MessageSource, test with different Locale values to confirm message resolution
  • Security context: AuthorizationException handlers can access SecurityContextHolder — test that context is correctly evaluated

© giuseppe-trisciuoglio, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (references) in plugins/developer-kit-java/skills/unit-test-exception-handler of giuseppe-trisciuoglio/developer-kit.

  • SKILL.md
  • references/examples.md

Open the folder on GitHubat commit fe73fb3

Compare with similar skills

Unit Test Exception Handler next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Unit Test Exception Handler compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Unit Test Exception Handler this skillgiuseppe-trisciuoglio/developer-kit356—~1.6kAutomated safety check: NotesMIT
321 Frameworks Spring Boot Testing Unit Testsjabrena/plinth447—~952Automated safety check: PassApache-2.0
Coverage CheckAI-Unified-Process/marketplace142—~2.7kAutomated safety check: PassApache-2.0
Hilla TestAI-Unified-Process/marketplace142—~3.9kAutomated safety check: WarnApache-2.0
Groovy 5 Developer Guideapache/grails-core2.9k—~3kAutomated safety check: PassApache-2.0
Java Rulessoftspark/ai-toolkit179—~3.1kAutomated safety check: PassApache-2.0

Similar skills

  • A skill your agent uses when you need to write unit tests for Spring Boot applications — including pure unit tests with @ExtendWith(MockitoExtension.class) for @Service/@Component, slice tests with…

    447 GitHub stars~952 tokensUpdated 2 days ago
    Testing & QAAuto-check passed
  • Coverage Check

    AI-Unified-Process/marketplace

    Audits an already-written use case (UC-XXX) or test case (TC-XXX) against its specification and reports a coverage matrix: which main success scenario steps, alternative flows, business rules…

    142 GitHub stars~2.7k tokensUpdated 4 days ago
    Testing & QAAuto-check passed
  • Hilla Test

    AI-Unified-Process/marketplace

    Creates tests for Hilla use cases on both sides of the browser boundary: Vitest + React Testing Library tests for the React/TypeScript view (with the generated endpoint clients mocked) and Spring…

    142 GitHub stars~3.9k tokensUpdated 4 days ago
    Testing & QAAuto-check: warnings
  • Groovy 5 Developer Guide

    apache/grails-core

    Guidance for Groovy 5 work in Grails projects: syntax, closures, traits, DSLs, metaprogramming, Spock tests, static compilation and Java 21 integration.

    2.9k GitHub stars~3k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Java Rules

    softspark/ai-toolkit

    Java coding rules: style, patterns, security, testing. An agent skill from softspark/ai-toolkit.

    179 GitHub stars~3.1k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Pest Testing

    liberusoftware/real-estate-laravel

    A skill your agent uses for Pest PHP testing in Laravel projects only.

    112 GitHub starsUsed in 1 repo~1.8k tokens
    Testing & QAAuto-check passed

More from giuseppe-trisciuoglio/developer-kit

All 115 skills in this repo
  • Nestjs Drizzle Crud Generator

    giuseppe-trisciuoglio/developer-kit

    Generates complete CRUD modules for NestJS applications with Drizzle ORM.

    356 GitHub stars~1.3k tokensUpdated 29 days ago
    Auto-check: notes
  • Spring Boot Actuator

    giuseppe-trisciuoglio/developer-kit

    Provides patterns to configure Spring Boot Actuator for production-grade monitoring, health probes, secured management endpoints, and Micrometer metrics across JVM services.

    356 GitHub stars~2.2k tokensUpdated 29 days ago
    Auto-check: notes
  • Spring Boot Crud Patterns

    giuseppe-trisciuoglio/developer-kit

    Provides and generates complete CRUD workflows for Spring Boot 3 services.

    356 GitHub stars~2.5k tokensUpdated 29 days ago
    Auto-check: notes
  • Spring Boot Security JWT

    giuseppe-trisciuoglio/developer-kit

    Provides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based…

    356 GitHub stars~3.9k tokensUpdated 29 days ago
    Auto-check: notes
  • AWS CLI Beast

    giuseppe-trisciuoglio/developer-kit

    Provides advanced AWS CLI patterns for managing EC2, Lambda, S3, DynamoDB, RDS, VPC, IAM, and CloudWatch.

    356 GitHub stars~1.7k tokensUpdated 29 days ago
    Auto-check: notes
  • PR Review Comments

    giuseppe-trisciuoglio/developer-kit

    Posts review findings from a JSON file as inline comments on a GitHub Pull Request, attaching each comment to its file and line.

    356 GitHub stars~1k tokensUpdated 29 days ago
    Auto-check: notes

Works with

Questions about Unit Test Exception Handler

What does Unit Test Exception Handler do?

Provides patterns for unit testing @ExceptionHandler and @ControllerAdvice in Spring Boot applications. Unit Test Exception Handler is an agent skill from giuseppe-trisciuoglio/developer-kit. Provides patterns for unit testing @ExceptionHandler and @ControllerAdvice in Spring Boot applications.

When should I use Unit Test Exception Handler?

Unit Test Exception Handler fits situations like: writing Spring exception handler tests; REST API error tests; mocking controller advice.

How do I install Unit Test Exception Handler in Claude Code?

Run `npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-exception-handler -a claude-code`. Or copy the skill folder (plugins/developer-kit-java/skills/unit-test-exception-handler in giuseppe-trisciuoglio/developer-kit) into .claude/skills/unit-test-exception-handler in your project. Claude Code loads it when a task matches its description.

How do I install Unit Test Exception Handler in Codex?

Run `npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-exception-handler -a codex`. Or copy the skill folder (plugins/developer-kit-java/skills/unit-test-exception-handler in giuseppe-trisciuoglio/developer-kit) into .agents/skills/unit-test-exception-handler in your project. Codex loads it when a task matches its description.

Can I use Unit Test Exception Handler in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-exception-handler -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/unit-test-exception-handler, .gemini/skills/unit-test-exception-handler, .github/skills/unit-test-exception-handler and .opencode/skills/unit-test-exception-handler in your project.

What does Unit Test Exception Handler need to run?

SKILL.md names no scripts, command-line tools or credentials: Unit Test Exception Handler is instructions for the agent only. Its frontmatter pre-approves these tools: Read, Write, Bash, Glob, Grep.

Does Unit Test Exception Handler access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Unit Test Exception Handler safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Unit Test Exception Handler use?

Unit Test Exception Handler is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Unit Test Exception Handler use?

About 1.6k tokens (SKILL.md is roughly 6.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 796 tokens, read only when the agent opens those files.

What are the alternatives to Unit Test Exception Handler?

Skills that share tags, products or a category with Unit Test Exception Handler: 321 Frameworks Spring Boot Testing Unit Tests (jabrena/plinth, 447 stars), Coverage Check (AI-Unified-Process/marketplace, 142 stars), Hilla Test (AI-Unified-Process/marketplace, 142 stars) and Groovy 5 Developer Guide (apache/grails-core, 2.9k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Unit Test Exception Handler?

giuseppe-trisciuoglio (a GitHub user) maintains it in giuseppe-trisciuoglio/developer-kit, which has 356 GitHub stars. The repository holds 115 skills in this directory. The repository was last updated on September 10, 2026.

Source: giuseppe-trisciuoglio/developer-kit on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.