Coverage Report - biz.xsoftware.mock.BehaviorMethod
 
Classes in this File Line Coverage Branch Coverage Complexity
BehaviorMethod
N/A
N/A
0
 
 1  
 package biz.xsoftware.mock;
 2  
 
 3  
 import java.lang.annotation.ElementType;
 4  
 import java.lang.annotation.Retention;
 5  
 import java.lang.annotation.RetentionPolicy;
 6  
 import java.lang.annotation.Target;
 7  
 
 8  
 /**
 9  
  * This annotation is used to annotate a method inside a {@link Behavior} class
 10  
  * as implementing an interface method in the {@link MockObject}. We'll give a
 11  
  * basic example on how to use this annotation. First we'll need an interface
 12  
  * that will need to be mocked:
 13  
  * 
 14  
  * <pre>
 15  
  * public interface MyInterface {
 16  
  *     public String myMethod();
 17  
  * }
 18  
  * </pre>
 19  
  * 
 20  
  * Here is the example Behavior implementation with myMethod annotated as a
 21  
  * BehaviorMethod:
 22  
  * 
 23  
  * <pre>
 24  
  * public class MyBehavior implements Behavior {
 25  
  *     @BehaviorMethod
 26  
  *     public String myMethod() {
 27  
  *         return &quot;This is the desired behavior&quot;;
 28  
  *     }
 29  
  * }
 30  
  * </pre>
 31  
  * 
 32  
  * Here is the example of using the Behavior with a MockObject:
 33  
  * 
 34  
  * <pre>
 35  
  * public class Example {
 36  
  *     public static void main(String... args) {
 37  
  *         MockObject myInterface = MockObjectFactory.createMock(MyInterface.class);
 38  
  *         myInterface.setBehavior(new MyBehavior());
 39  
  *         System.out.println(((MyInterface) myInterface).myMethod());
 40  
  *     }
 41  
  * }
 42  
  * </pre>
 43  
  * 
 44  
  * When this example is run "This is the desired behavior" will be printed to
 45  
  * console.
 46  
  * 
 47  
  * @author Brian Freeman
 48  
  */
 49  
 @Retention(RetentionPolicy.RUNTIME)
 50  
 @Target(ElementType.METHOD)
 51  
 public @interface BehaviorMethod {
 52  
     Class<?> override() default void.class;
 53  
 }