biz.xsoftware.mock
Interface Behavior

All Known Subinterfaces:
CloningBehavior

public interface Behavior

A way of providing snippets of code to be run when a method is called. If you want to pass in a Behavior implementation for

public int doSomethingCool(int i, String s, long l);

Then your Behavior class must define the same exact method and that method will be called in your Behavior implementation when the mockobject's doSomethingCool method is called. You must also return the same value as the doSomethingCool method which in this case is an int.

This interface is intended to be implemented by helper classes to be used by MockObjects. A Behavior should have a method in it that matches the method used when adding it to a MockObject. We'll give a basic example on how to use a behavior. First we'll need an interface that will need to be mocked:

 public interface MyInterface {
     public String myMethod();
 }
 
Here is the example Behavior:
 public class MyBehavior implements Behavior {
     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.create
         myInterface.addBehavior("myMethod", new MyBehavior());
         System.out.println(((MyInterface) myInterface).myMethod());
     }
 }
 
When this example is run "This is the desired behavior" will be printed to console

Author:
Dean Hiller, Brian Freeman