GetFirstNotNullRule implements IResolveDependencyStrategy { @Override public <T> T resolve(Object... args) throws ResolveDependencyStrategyException { for (Object arg : args) { if (arg != null) { return (T) arg; } } throw new ResolveDependencyStrategyException("All objects are null: " + Arrays.toString(args)); }  @Override T resolve(Object... args);  }
@Test public void MustCorrectReturnFirstNotNull() throws ResolveDependencyStrategyException { Object[] args = new Object[10]; Object targetObject = new Object(); args[9] = targetObject; assertTrue(targetObject == new GetFirstNotNullRule().resolve(args)); targetObject = new Object(); args[4] = targetObject; assertTrue(targetObject == new GetFirstNotNullRule().resolve(args)); targetObject = new Object(); args[1] = targetObject; assertTrue(targetObject == new GetFirstNotNullRule().resolve(args)); }
@Test(expected = ResolveDependencyStrategyException.class) public void MustInCorrectReturnFirstNotNullWhenAllNull() throws ResolveDependencyStrategyException { Object[] args = new Object[10]; new GetFirstNotNullRule().resolve(args); }