So let's see how to make this work - in theory as well as with Maven. It comes down to these three steps: 1. compile and test snippet source files 2. reference parts of those files from your documentation 3. configure Javadoc to pick up these files. Here are the details. 👇🏾🧵
Re 1: I recommend not to reuse tests for snippets and instead create a new source tree `src/demo/java` with `…Demo.java` files. There you can write tests that contain the code you want to embed in Javadoc as well as assertions that verify the correct behavior.
To have Maven compile and test these files, add the folder to the test sources with the Codehaus Build Helper plugin (mojohaus.org/build-helper-m…) and configure Surefire to pick up `…Demo.java` files.
@nipafx Why not have this be in your unit test file, though? I hope people doing `src/demo` will make damn sure those things actually get run.