@Test
  public void testAddFactory() {
    final DependencyBuilder<String> db = new DependencyBuilder<String>();
    try {
      db.addFactory(null, DI.constantly("", String.class));
      fail("null key should be rejected");
    } catch (IllegalArgumentException e) {
      // do nothing
    }
    try {
      db.addFactory("absent", null);
      fail("null source should be rejected");
    } catch (IllegalArgumentException e) {
      // do nothing
    }

    final IComponentSource<Integer, String> counterSource =
        new IComponentSource<Integer, String>() {
          int c = 0;

          @Override
          public Integer get(Map<String, IComponentSource<?, String>> dependencies) {
            return c++;
          }
        };
    db.addFactory("counter", counterSource);
    try {
      db.addFactory("counter2", DI.singleton(counterSource));
      fail("Singleton cannot be added as factory");
    } catch (IllegalArgumentException e) {
      // do nothing
    }
  }