title: Mock a static method multiple times using JMockit within a JUnit test
body: <p>I have a class with static methods that I'm currently mocking with JMockit. Say it looks something like:</p>
  
  <pre><code>public class Foo {
      public static FooValue getValue(Object something) {
          ...
      }
      public static enum FooValue { X, Y, Z, ...; }
  }
  </code></pre>
  
  <p>I have another class (let's call it MyClass) that calls Foo's static method; I'm trying to write test cases for this class. My JUnit test, using JMockit, looks something like this:</p>
  
  <pre><code>public class MyClassTest extends TestCase {
      @NonStrict private final Foo mock = null;
  
      @Test public void testMyClass() {
          new Expectations() {
              {
                  Foo.getValue((Object) any); result = Foo.FooValue.X;
              }
          };
      }
  
      myClass.doSomething();
  }
  </code></pre>
  
  <p>This works fine and dandy, and when the test is executed my instance of MyClass will correctly get the enum value of Foo.FooValue.X when it calls Foo.getValue().</p>
  
  <p>Now, I'm trying to iterate over <em>all</em> the values in the enumeration, and repeatedly run the test. If I put the above test code in a for loop and try to set the result of the mocked static method to each enumeration value, that doesn't work. The mocked version of Foo.getValue() always returns Foo.FooValue.X, and never any of the other values as I iterate through the enumeration.</p>
  
  <p>How do I go about mocking the static method multiple times within the single JUnit test? I want to do something like this (but obviously it doesn't work):</p>
  
  <pre><code>public class MyClassTest extends TestCase {
      @NonStrict private final Foo mock = null;
  
      @Test public void testMyClass() {
  
          for (final Foo.FooValue val : Foo.FooValue.values() {
  
              new Expectations() {
                  {
                      // Here, I'm attempting to redefine the mocked method during each iteration
                      // of the loop. Apparently, that doesn't work.
                      Foo.getValue((Object) any); result = val;
                  }
              };
  
              myClass.doSomething();
          }
  
      }
  }
  </code></pre>
  
  <p>Any ideas?</p>