docufier is a tool that turns classes with doc comments (e.g. unit tests) into markdown. There is also a maven plugin.
An example would be the following test case:
/**
*
* Output and Input
* ----------------
*
* For more control over the execution we'll use a `ProcBuilder` instance to configure
* the process.
*
* The run method builds and spawns the actual process and blocks until the process exits.
* The process takes care of writing the output to a stream, as opposed to the standard
* facilities in the JDK that expect the client to actively consume the
* output from an input stream:
*/
@Test
public void testOutputToStream() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
new ProcBuilder("echo")
.withArg("Hello World!")
.withOutputStream(output)
.run();
assertEquals("Hello World!\n", output.toString());
}
Which will be rendered to the following markdown:
Output and Input
----------------
For more control over the execution we'll use a `ProcBuilder` instance to configure
the process.
The run method builds and spawns the actual process and blocks until the process exits.
The process takes care of writing the output to a stream, as opposed to the standard
facilities in the JDK that expect the client to actively consume the
output from an input stream:
~~~ .java
ByteArrayOutputStream output = new ByteArrayOutputStream();
new ProcBuilder("echo")
.withArg("Hello World!")
.withOutputStream(output)
.run();
assertEquals("Hello World!\n", output.toString());
~~~
For a full example refer to the README.md of the jproc project, which has been generated from the acceptance test suite.