title: How to test class with local connection to EJB
body: <p>I am facing problem with testing class which has implemented some local connection to EJB in the constructor. This connection is used just inside the constructor and sets some private attributes of the instantiated class.</p>
  
  <p>MyClass which I want to test:</p>
  
  <pre><code>public class MyClass {
  
    private String myValue;
  
    public MyClass() throws Exception {
      MyBeanLocal local = EJBFactory.getLocal(MyBeanLocal.class);
      myValue = local.fetchValue();
    }
  
    public void processValue() {
      ... do some String magic which should be tested ...
    }
  
    public String getValue() {
      return myValue;
    }
  
  }
  </code></pre>
  
  <p>EJBFactory contains some enhanced lookup (with caching) and can return local or remote connection (remote requires server location).</p>
  
  <p>MyBeanLocal interface</p>
  
  <pre><code>public interface MyLocalBean {
    public String fetchValue();
  }
  </code></pre>
  
  <p>And finally my junit class where I want to test MyClass.processValue method:</p>
  
  <pre><code>public class MyClassTest {
  
    private MyClass myClass;
  
    @Before
    public void setUp() {
      myClass = new MyClass();
    }
  
    @Test
    public void testProcessValue() {
      Assert.assertEquals(myClass.processValue(), "MY EXPECTED VALUE");
    }
  
  }
  </code></pre>
  
  <p>The question is how to test situation when I run JUnits in local machine (or some automatic test machine like Hudson or Jenkins) and bean runs on application server context which is different than my local one. I can't touch to production code, just need to write test.</p>
  
  <p>Actually I don't need to make MyBeanLocal functional, but I need myValue set.</p>
  
  <p>I was thinking about mocking, but I am not familiar with that.</p>