title: How to test the interaction between a method and its two helpers?
body: <p>I have the following structure of my <code>Java</code> code:</p>
  
  <pre><code>public MyClass {
      // some class variables
      ...
      private void process() {
          private MyObject obj; 
          ...
          obj = createHelper();
          ...
          messageHelper(obj, "One of several possible strings");
          ...  
          messageHelper(obj, "Another call with a different string");  
          ...
      }
  
      private MyObject createHelper {
          MyObject obj = new MyObject();
          // some Setter calls
          ...
          return obj;
      }
  
      private void messageHelper (MyOject obj, String message) {
          ...
      }
  
  }
  </code></pre>
  
  <p>I would like to test, that based on properties <code>obj</code> (that I would like to specify), <code>messageHelper()</code> receives the right string.  In other words I need to control the result of one method and have access to the parameters of the other.</p>
  
  <p>I'm still very shaky with all this Mock/Stub/Spy stuff.  </p>
  
  <p>It seems to me that I need to <code>Spy</code> on <code>MyClass</code>, <code>stub</code> <code>CreateHelper()</code> with a "manually" created object and  not sure what for intercepting call parameters for <code>messageHelper()</code>.  </p>
  
  <p>Also I noted that <a href="http://docs.spockframework.org/en/latest/interaction_based_testing.html#wheretodeclareinteractions" rel="nofollow">Wiki</a> cautions against using Spies:</p>
  
  <blockquote>
    <p>Think twice before using this feature. It might be better to change
    the design of the code under specification.</p>
  </blockquote>
  
  <p>So what would an appropriate <em>Spocky</em> way to accomplish the task? </p>
  
  <p><strong>Slightly Refactored Code:</strong> <em>(5/5/14)</em></p>
  
  <pre><code>public MyClass {
      // some class variables
      private messageSevice = new messageService();
      ...
      private void process() {
          private MyObject obj; 
          ...
          obj = new MyObject(parameters ...);
          ...
          if (someCondition) {
              messageService.produceMessageOne(obj);
          }
          ... 
          if (otherCondition) { 
              messageService.produceMessageTwo(obj);  
          {
          ...
      }
  
  }
  
  public class MessageService implements IMessageService {
  
      private final static MSG_ONE = "...";
      private final static MSG_TWO = "...";
      ...
  
      public void produceMessageOne(MyObject obj) {
           produceMessage(obj, MSG_ONE);
           ...
      }
      public void produceMessageOne(MyObject obj) {
           produceMessage(obj, MSG_TWO);
      }
  
      private void produceMessage(MyObject obj, String message) {
           ...
      }    
  }
  </code></pre>
  
  <p>I would greatly appreciate if someone suggests the way it should be tested with <strong>Spock</strong>.</p>