title: How to test/mock this static factory (used for graph construction)?
body: <p>So, I have implemented my business classes, where I pass in all dependencies via the constructor, so I can mock those out and easily unit test them. This works great so far, but then, at one point, I need to create an object graph out of those objects. For this, I'm using a static factory (I can't use a DI framework, sadly). Example:</p>
  
  <pre><code>public class FooBar {
      public FooBar(Foo foo, Bar bar) {
          this.foo = foo;
          this.bar = bar;
      }
  }
  
  public class Foo  {
      public Foo() {}
  }
  
  public class Bar {
      public Bar(Foo foo) {
          this.foo = foo;
      }
  }
  
  public class GraphFactory {
      public static FooBar newFooBar() {
          Foo foo = new Foo();
          Bar bar = new Bar(foo);
  
          return new FooBar(foo, bar);
      }
  }
  </code></pre>
  
  <p>So, I'm not able to really test the GraphFactory (can't mock the dependencies), which is kinda ok (not much work is done here). But what if construction of the graph is more complex, i.e. it involves looking up some properties, doing JNDI lookups and so on?</p>
  
  <p>Should I still not write a unit test for this? Is my class design maybe broken? Isn't the purpose of unit testing to test classes in isolation?</p>