title: Unit testing with EasyMock and Spring
body: <p>In my project i have UtilClass for example A(all method static, private constructor). I need to test one of this static method a(13 parameters). This class have one dependencies(another class B). Class B - static field in class A. In code smth like that:</p>
  
  <pre><code>public class A{
      private static B b = AppContext.getBean(B.class);
  
      public static C a("14 parameters") throw MyException{
          try{
          b.call("13 parameters");
          }catch(MyExceptionSecond e){
              MyException newException = new MyException(msg,e);
              if(e.getCode() == smth){
                  //do smth
              }
              throw privateMethodClassA(newException);
          }
      }
  }
  </code></pre>
  
  <p>I need to test how working privateMethodClassA, for that i mocked class B in config-test.xml:</p>
  
  <pre><code>&lt;bean class="org.easymock.EasyMock" factory-method="createMock" primary="true" id="classB"&gt;
      &lt;constructor-arg value="com.my.package.B"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>That is my test and setUp method:</p>
  
  <pre><code>public class MyTest {
     private B b;
  
  @Before
  public void setUp() throws Exception {
  
      b = AppContext.getBean(B.class);
      expect(b.call("13 paramaters"))
          .andThrow(
              new MyExceptionSecond("some error code", "testMessage", new Object()))
          .anyTimes();
      replay(b);
  }
  
  @Test(expected = MyException.class)
  public void testExceptionMethod() throws Exception {
      A.a("13 parametrs");
  }
  }
  </code></pre>
  
  <p>If I evaluating in debug b.call("13 parameters") everything all right(in context test), but in the same debug going into context call class A and evaluate b.call("13 parameters
  ") with the same parameters mocked object return null, instead of MyExceptionSecond as in the first case. The problem is - i can't get the MyException error all my attempts led to : 
  <code>java.lang.AssertionError: Expected exception: com.my.package.MyException</code>
  What do you think about this issue? </p>
  
  <p>P.S My guess is that this is a problem in the attachment of expect() to the context of the test and not to the moсk itself.</p>
  
  <p>P.P.S java8, EasyMock 4.2, spring 4.2.8, AppContext == org.springframework.context.ApplicationContext.</p>