This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch quick-fix/drop-test-visibility-rule in repository https://gitbox.apache.org/repos/asf/camel.git
commit bc59331c257eea0c7dbf140be82a52a1532fe98a Author: Claus Ibsen <[email protected]> AuthorDate: Tue Aug 25 08:54:56 2026 +0200 chore: Remove test-visibility convention from AGENTS.md Drop the "Drop public From Test Classes and Methods" rule. Camel test classes have been public for ~20 years and every existing test class in the codebase is public. AIs (and humans) overwhelmingly copy from existing tests, so the rule fights the actual corpus: it tells contributors to write package-private tests while thousands of surrounding examples are public, producing pointless style drift in every touched file for zero functional gain. The rule also grew a thicket of exceptions (supertype overrides must stay public, base/support classes must stay public, anything under camel-test/** and test-infra/** must stay public) and still missed cases: tests driven by the test-infra CamelContextExtension (@RouteFixture/@ContextFixture) must be public because the extension invokes fixture methods reflectively, and on Java 25 Method.invoke on a package-private receiver class throws IllegalAccessException. A recent change that dutifully followed the rule broke CI for exactly this reason. A convention that needs this many carve-outs and still causes build failures is not worth keeping. public tests are perfectly fine. Removing the rule keeps guidance short and consistent with the codebase. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- AGENTS.md | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 93b6a3794e0b..0c2c1ef1aa48 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -251,57 +251,6 @@ await().atMost(10, TimeUnit.SECONDS).until(() -> mock.getReceivedCounter() >= 2) - Use `untilAsserted` or `until` with a clear predicate — do not replace a sleep with a busy-wait loop. -### Test Visibility: Drop `public` From Test Classes and Methods - -JUnit 5 does **not** require test classes or test methods to be `public` — package-private -(the default, no modifier) is sufficient and preferred. Removing the unnecessary `public` -qualifier reduces visual noise and follows modern JUnit 5 conventions. - -**Examples:** - -```java -// Preferred — package-private (no modifier): -class MyComponentTest extends CamelTestSupport { - @Test - void testSendMessage() { ... } - - @Override - protected RoutesBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() { // stays public — overrides RouteBuilder.configure() - from("direct:start").to("mock:result"); - } - }; - } -} - -// Avoid — unnecessary public: -public class MyComponentTest extends CamelTestSupport { - @Test - public void testSendMessage() { ... } -} -``` - -**Rules:** - -- New test classes and test methods MUST NOT use the `public` modifier. -- When modifying an existing test file, remove the `public` modifier from the class declaration - and from any test methods you touch. Do NOT sweep the entire file — only change what you are - already modifying. -- `@BeforeAll`, `@AfterAll`, `@BeforeEach` and `@AfterEach` methods follow the same rule: drop - `public` when adding or modifying them. -- **Exception — methods that override or implement a supertype method keep the supertype's - visibility.** Java forbids reducing visibility on an override (JLS 8.4.8.3), so - `public void configure()` in a `RouteBuilder`, and any override of a public method from - `CamelTestSupport` or an implemented interface, MUST stay `public`. -- **Exception — base and support classes stay `public`** when they are extended from another - package or module (a package-private class cannot be), and anything under - `components/camel-test/**` or `test-infra/**` stays `public` because those are released - artifacts consumed by downstream projects and by users' own tests. -- Do NOT create a standalone PR solely to remove `public` from test files in bulk — apply the - convention incrementally as part of other work. - ### Issue Investigation (Before Implementation) Before implementing a fix for a JIRA issue, **thoroughly investigate** the issue's validity and context.
