biz.xsoftware.mock
Annotation Type BehaviorMethod


@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface BehaviorMethod

This annotation is used to annotate a method inside a Behavior class as implementing an interface method in the MockObject. We'll give a basic example on how to use this annotation. First we'll need an interface that will need to be mocked:

 public interface MyInterface {
     public String myMethod();
 }
 
Here is the example Behavior implementation with myMethod annotated as a BehaviorMethod:
 public class MyBehavior implements Behavior {
     @BehaviorMethod
     public String myMethod() {
         return "This is the desired behavior";
     }
 }
 
Here is the example of using the Behavior with a MockObject:
 public class Example {
     public static void main(String... args) {
         MockObject myInterface = MockObjectFactory.createMock(MyInterface.class);
         myInterface.setBehavior(new MyBehavior());
         System.out.println(((MyInterface) myInterface).myMethod());
     }
 }
 
When this example is run "This is the desired behavior" will be printed to console.

Author:
Brian Freeman

Optional Element Summary
 Class<?> override
           
 

override

public abstract Class<?> override
Default:
void.class