giuseppe-trisciuoglio avatar

Unit Test Application Events

This one walks you through unit testing Spring application events without spinning up the whole context. You'll mock ApplicationEventPublisher, capture events with ArgumentCaptor to inspect payloads, and test listeners in isolation against mocked dependencies. It covers the async handler case too, complete with the Thread.sleep versus Awaitility tradeoff. The validation checkpoints are practical: confirm your captor actually caught something before asserting on fields, verify the right event type was published if listeners don't fire. Honestly, the error handling examples alone make this worth using. Most teams skip testing that listeners swallow exceptions gracefully, then wonder why one bad listener tanks the whole event chain in production.

skills.sh installs
3.8K
GitHub stars
369
last updated
Aug 21, 2026

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-application-events --agent claude-code

Installs into .claude/skills of the current project.

Files

Unit Testing Application Events

Overview

Provides actionable patterns for testing Spring ApplicationEvent publishers and @EventListener consumers using JUnit 5 and Mockito — without booting the full Spring context.

When to Use

  • Writing unit tests for event publishers or listeners
  • Verifying that an event was published with correct payload
  • Testing @EventListener method invocation and side effects
  • Testing event propagation through multiple listeners
  • Validating async event handling (@Async + @EventListener)
  • Mocking ApplicationEventPublisher in service tests

Instructions

Sponsors

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, Documentation, Java & JVM
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 102
1github avatarunit-test-vue-piniagithub/awesome-copilotWrite and review unit tests for Vue 3 + TypeScript + Vitest + Pinia codebases. Use when creating or updating tests for components, composables, and stores; mock1.8Kskills.sh installs
2bobmatnyc avatarwordpress-testing-qabobmatnyc/claude-mpm-skillsWordPress plugin and theme testing with PHPUnit integration tests, WP_Mock unit tests, PHPCS coding standards, and CI/CD workflows430skills.sh installs
3davila7 avatarplaywright-e2e-builderdavila7/claude-code-templatesPlan and build comprehensive Playwright E2E test suites with Page Object Model, authentication state persistence, custom fixtures, visual regression, and CI int245skills.sh installs
4giuseppe-trisciuoglio avatarunit-test-boundary-conditionsgiuseppe-trisciuoglio/developer-kitProvides edge case, corner case, boundary condition, and limit testing patterns for Java unit tests. Validates minimum/maximum values, null cases, empty collect4.2Kskills.sh installs
5giuseppe-trisciuoglio avatarunit-test-parameterizedgiuseppe-trisciuoglio/developer-kitProvides parameterized testing patterns with JUnit 5, generates data-driven unit tests using @ParameterizedTest, @ValueSource, @CsvSource, @MethodSource. Create3.9Kskills.sh installs
6giuseppe-trisciuoglio avatarunit-test-json-serializationgiuseppe-trisciuoglio/developer-kitProvides patterns for unit testing JSON serialization/deserialization with Jackson and `@JsonTest`. Validates JSON mapping, custom serializers, date formats, an3.9Kskills.sh installs