/**
   * Test method for {@link
   * net.sf.hajdbc.balancer.load.LoadBalancer#invoke(net.sf.hajdbc.invocation.Invoker,
   * net.sf.hajdbc.Database, java.lang.Object)}.
   */
  @Test
  public void invoke() throws Exception {
    TestInvoker invoker = mock(TestInvoker.class);
    Object object = new Object();
    Object expected = new Object();
    Exception expectedException = new Exception();

    Balancer<Void, MockDatabase> balancer =
        this.factory.createBalancer(new HashSet<MockDatabase>(Arrays.asList(this.databases)));

    when(invoker.invoke(this.databases[0], object)).thenReturn(expected);

    Object result = null;
    Exception exception = null;
    try {
      result = balancer.invoke(invoker, this.databases[0], object);
    } catch (Exception e) {
      exception = e;
    }

    assertSame(expected, result);
    assertNull(exception);

    reset(invoker);

    when(invoker.invoke(this.databases[0], object)).thenThrow(expectedException);

    result = null;
    exception = null;

    try {
      result = balancer.invoke(invoker, this.databases[0], object);
    } catch (Exception e) {
      exception = e;
    }

    assertNull(result);
    assertSame(expectedException, exception);
  }