Skip to content

Conversation

@yalishevant
Copy link

  • Add @asciidoctor/tabs extension for tabbed code blocks
  • Add Kotlin examples for Writing Tests intro
  • Add Kotlin examples for Dependency Injection documentation
  • Add UI supplemental files (tabs.css, tabs.js) for tab styling

This PR adds the first tabbed Java/Kotlin code examples to the documentation, allowing users to switch between languages.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

  • There are no TODOs left in the code
  • Method preconditions are checked and documented — N/A (no new API)
  • Coding conventions have been followed
  • Change is covered by automated tests (Kotlin examples compile and tests pass)
  • Public API has Javadoc and @API annotations — N/A (documentation only)
  • Change is documented in the User Guide (this is the change itself)
  • Release Notes — N/A (documentation enhancement, no functional changes)

@testlens-app
Copy link

testlens-app bot commented Jan 26, 2026

✅ All tests passed ✅

🏷️ Commit: 7c52015
▶️ Tests: 6968 executed
⚪️ Checks: 15/15 completed


Learn more about TestLens at testlens.app.

Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Thank you, looks very promising! 👍

Comment on lines 127 to 139
@ExtendWith(RandomParametersExtension::class)
class KotlinMyRandomParametersTest {

@Test
fun injectsInteger(@Random i: Int, @Random j: Int) {
assertNotEquals(i, j)
}

@Test
fun injectsDouble(@Random d: Double) {
assertEquals(0.0, d, 1.0)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please move this snippet into a .kt file in src/test/java so it gets compiled and executed.

Copy link
Author

Choose a reason for hiding this comment

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

Let's then maybe also extract the Java version of MyRandomParametersTest to a file in src/test/java? Currently it's inline in the .adoc file, and extracting only the Kotlin version would be inconsistent. I can do both.

Copy link
Member

@marcphilipp marcphilipp Jan 31, 2026

Choose a reason for hiding this comment

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

I missed that. Yes, we should do that as well!

Copy link
Author

Choose a reason for hiding this comment

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

It seems I know why it was inlined. The Java snippet uses RandomParametersExtension which is in the junit-examples repository, not here. If extracted to a file, it won't compile. The local RandomNumberExtension also only supports int, not double, so injectsDouble wouldn't work either.
Options:

  • Keep Java inline (as is). And probably it will be right to inline Kotlin as well, with using both injectsInteger + injectsDouble).
  • Extract Java but adapt it to use local @random annotation and remove injectsDouble.

What do you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

TBH, I don't see any point in referencing two different "random number" extensions within our User Guide.

It's of course OK for the RandomParametersExtension to remain in the examples repository, but I think it's fine to stick with the local RandomNumberExtension in the User Guide, both in Dependency Injection for Constructors and Methods as well as in Registering Extensions.

So, I'm in favor of revising the current Java-based example to use RandomNumberExtension, and the Kotlin-based example would copy that. Perhaps demonstrating parameter resolution for the constructor and a test method would suffice -- basically like RandomNumberDemo but without the field injection.

Comment on lines +22 to +23
// tag::user_guide[]
@Execution(ExecutionMode.SAME_THREAD)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// tag::user_guide[]
@Execution(ExecutionMode.SAME_THREAD)
@Execution(ExecutionMode.SAME_THREAD)
// tag::user_guide[]

Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

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

Please satisfy the DCO bot by singining off on your commits. It's best to start it early, rebasing afterwards can be painful.

See: https://github.com/junit-team/junit-framework/pull/5316/checks?check_run_id=61522289208

@yalishevant yalishevant force-pushed the add-kotlin-tabs-documentation branch from f719c64 to 099a6a0 Compare January 27, 2026 09:10
yalishevant and others added 3 commits January 27, 2026 13:54
- Add @asciidoctor/tabs extension for tabbed code blocks
- Add Kotlin examples for Writing Tests intro
- Add Kotlin examples for Dependency Injection documentation
- Add UI supplemental files (tabs.css, tabs.js) for tab styling

Signed-off-by: Anton.Yalyshev <[email protected]>
Signed-off-by: Anton.Yalyshev <[email protected]>
@yalishevant yalishevant force-pushed the add-kotlin-tabs-documentation branch from 099a6a0 to 20ba541 Compare January 27, 2026 12:57
@mpkorstanje mpkorstanje dismissed their stale review January 27, 2026 15:20

Completed

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.

4 participants