-
Notifications
You must be signed in to change notification settings - Fork 11
Method Grouping and Triggering
Methods can be grouped together to coordinate their appearance and disappearance from an API.
For methods in your API which are not required (those declared with any(..)
and atMost(..)
) it is possible to assign them to a group. Grouping methods allows for more complicated (A|B) types of scenarios, where the user can pick one method over another, but not both. The first time a method with a group is called all other methods in the group are removed from play. This is also a nice way to support method overloading, which is really just two or more methods with different signatures which could be called. Flapi's setReturnType(..)
method is an example of this, being two methods setReturnType(String clazz)
and setReturnType(Class clazz)
grouped together.
Methods are grouped by calling the atMost(..)
and any(..)
methods accepting an integer group number. The effect is scoped to the current block.
Building off of the group numbers, it is also possible to have a method appear after a method in a group has been called. The method will be hidden initially, and will only enter play after the specified group has been hit for the first time. This functionality is available to all methods in a block via the after(int group)
method.