To add an Exemplar to a method, annotate it with the @Exemplar annotation:
@Exemplar(args="'world'", expect="'Hello world'") public void sayHello(String name) { System.out.println("Hello " + name); }
The easiest way to add an exemplar is to use Ctrl+\ with the cursor within the method name or body. Alternatively select Add Exemplar under the right-click menu->Source.
To add more than one Exemplar to a method, annotate it with the @Exemplars annotation and place the set of Exemplars within the set property of the annotation.
@Exemplars(set={ @Exemplar(args="'world'", expect="'Hello world'"), @Exemplar(args="'Fred'" , expect="'Hello Fred'") }) public void sayHello(String name) { System.out.println("Hello " + name); }
This is necessary as Java does not permit a method to have more than one annotation of any given type, but it is possible for an annotation to contain an array of annotations.
Using Ctrl+\ on a method that already has an Exemplar will add the @Exemplars annotation, add a set containing the existing Exemplar, and finally add a new Exemplar to the set.
These examples show the use of the args and expect properties. These define what argument values to pass into the method under test, and what you expect to be returned from it. Both of these properties take a Simple Invocation Notation (SIN) Expression String. Subsequent sections detail SIN Expressions and how to specify and use these and other Exemplar properties.
Note you don’t have to annotate the concrete method; you can annotate just interface or abstract methods instead if you wish. For more information on this see the Using Exemplars in Interfaces and Abstract Classes section.