|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project |
| 6 | + |
| 7 | +AssertLog is a Java library for unit-testing logging. It intercepts log output during tests and provides assertion methods to verify what was (or was not) logged. |
| 8 | + |
| 9 | +Group ID: `com.codeborne.assertlog` | Current version: `0.2-SNAPSHOT` |
| 10 | + |
| 11 | +## Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +./gradlew test # run all tests (default task also runs clean) |
| 15 | +./gradlew clean test # clean build then test (what CI runs) |
| 16 | +./gradlew :assertlog-log4j-junit4:test --tests "org.assertlog.PetClinicTest#info" # single test |
| 17 | +./gradlew build # compile + test + jar |
| 18 | +``` |
| 19 | + |
| 20 | +Tests only run classes matching `org/assertlog/**/*` (configured in root `build.gradle`). |
| 21 | + |
| 22 | +## Module Structure |
| 23 | + |
| 24 | +Two submodules declared in `settings.gradle`: |
| 25 | + |
| 26 | +- **`assertlog-core`** — shared types only; currently just `OriginalLogsPolicy` enum (`SHOW`/`HIDE`) |
| 27 | +- **`assertlog-log4j-junit4`** — Log4j 1.x + JUnit 4 integration; depends on `assertlog-core` |
| 28 | + |
| 29 | +Each submodule has its own `build.gradle` for dependencies. Root `build.gradle` applies shared config (Java 8 source/target, UTF-8 encoding, test logging). `gradle/deploy.gradle` handles Maven Central publishing via `uploadArchives` (requires `signing.keyId` property). |
| 30 | + |
| 31 | +## Key Class: MockLogging |
| 32 | + |
| 33 | +`MockLogging` (`assertlog-log4j-junit4`) is a JUnit 4 `ExternalResource` rule that: |
| 34 | + |
| 35 | +1. **`before()`** — saves the root Log4j logger's state, sets the configured log level, removes existing appenders if `policy == HIDE`, then adds a capturing appender that feeds into an internal `ArrayDeque<LoggingEvent>` |
| 36 | +2. **`after()`** — removes the capturing appender and restores the original level and appenders |
| 37 | + |
| 38 | +Assertion methods consume events from the queue (ordered, dequeue semantics) except: |
| 39 | +- `assertLoggedInAnyOrder` / `assertLogged(Pattern)` / `assertNotLogged(Pattern)` — search without requiring order |
| 40 | +- `assertNoMoreLogs()` — fails if the queue is not empty (typically called in `@After`) |
| 41 | + |
| 42 | +`assertNotLogged` and `assertLogged(Pattern)` (the non-consuming overload) **must be called before** the dequeue-based `assertLogged` methods, as the queue is mutated. |
| 43 | + |
| 44 | +## Adding New Integrations |
| 45 | + |
| 46 | +The pattern for a new logging framework or test runner is: |
| 47 | +1. Create a new submodule (e.g., `assertlog-logback-junit5`) |
| 48 | +2. Add it to `settings.gradle` |
| 49 | +3. Implement an equivalent of `MockLogging` using the target framework's extension mechanism |
| 50 | +4. Depend on `assertlog-core` for shared types |
0 commit comments