public void testAbstractMainClass() throws Exception {

    final LoggerStubFactory loggerStubFactory = new LoggerStubFactory();
    final Logger logger = loggerStubFactory.getLogger();
    final String myUsage = "do some stuff";

    final MyMainClass mainClass = new MyMainClass(logger, myUsage);

    assertSame(logger, mainClass.getLogger());

    loggerStubFactory.assertNoMoreCalls();

    final String javaVersion = System.getProperty("java.version");

    try {
      try {
        System.setProperty("java.version", "whatever");
        new MyMainClass(logger, myUsage);
        fail("Expected VersionException");
      } catch (VersionException e) {
      }

      loggerStubFactory.assertNoMoreCalls();

      try {
        System.setProperty("java.version", "1.3");
        new MyMainClass(logger, myUsage);
        fail("Expected LoggedInitialisationException");
      } catch (LoggedInitialisationException e) {
        AssertUtilities.assertContains(e.getMessage(), "Unsupported");
        loggerStubFactory.assertSuccess("error", String.class);
      }
    } finally {
      System.setProperty("java.version", javaVersion);
    }

    loggerStubFactory.assertNoMoreCalls();

    final LoggedInitialisationException barfError = mainClass.barfError("foo");
    assertEquals("foo", barfError.getMessage());
    final CallData errorCall = loggerStubFactory.assertSuccess("error", String.class);
    AssertUtilities.assertContains(errorCall.getParameters()[0].toString(), "foo");
    loggerStubFactory.assertNoMoreCalls();

    final LoggedInitialisationException barfUsage = mainClass.barfUsage();
    AssertUtilities.assertContains(barfUsage.getMessage(), myUsage);
    final CallData errorCall2 = loggerStubFactory.assertSuccess("error", String.class);
    AssertUtilities.assertContains(errorCall2.getParameters()[0].toString(), myUsage);
    loggerStubFactory.assertNoMoreCalls();
  }
  public void testProcessMessages() throws Exception {
    final ConsoleConnection consoleConnection = new ConsoleConnectionImplementation(m_sender);

    m_senderStubFactory.setResult("blockingSend", new ResultMessage(new Integer(10)));
    assertEquals(10, consoleConnection.getNumberOfAgents());
    m_senderStubFactory.assertSuccess("blockingSend", GetNumberOfAgentsMessage.class);
    m_senderStubFactory.assertNoMoreCalls();

    final GrinderProperties properties = new GrinderProperties();
    consoleConnection.startWorkerProcesses(properties);
    final CallData data =
        m_senderStubFactory.assertSuccess("blockingSend", StartWorkerProcessesMessage.class);
    assertSame(properties, ((StartWorkerProcessesMessage) data.getParameters()[0]).getProperties());
    m_senderStubFactory.assertNoMoreCalls();

    consoleConnection.resetWorkerProcesses();
    m_senderStubFactory.assertSuccess("blockingSend", ResetWorkerProcessesMessage.class);
    m_senderStubFactory.assertNoMoreCalls();

    consoleConnection.stopAgents();
    m_senderStubFactory.assertSuccess("blockingSend", StopAgentAndWorkerProcessesMessage.class);
    m_senderStubFactory.assertNoMoreCalls();

    m_senderStubFactory.setResult("blockingSend", null);

    try {
      consoleConnection.getNumberOfAgents();
      fail("Expected ConsoleConnectionException");
    } catch (ConsoleConnectionException e) {
    }

    m_senderStubFactory.setResult("blockingSend", new ResultMessage(new Serializable() {}));

    try {
      consoleConnection.getNumberOfAgents();
      fail("Expected ConsoleConnectionException");
    } catch (ConsoleConnectionException e) {
    }

    final CommunicationException communicationException = new CommunicationException("");
    m_senderStubFactory.setThrows("blockingSend", communicationException);

    try {
      consoleConnection.getNumberOfAgents();
      fail("Expected ConsoleConnectionException");
    } catch (ConsoleConnectionException e) {
      assertSame(communicationException, e.getCause());
    }

    try {
      consoleConnection.startWorkerProcesses(new GrinderProperties());
      fail("Expected ConsoleConnectionException");
    } catch (ConsoleConnectionException e) {
      assertSame(communicationException, e.getCause());
    }

    try {
      consoleConnection.resetWorkerProcesses();
      fail("Expected ConsoleConnectionException");
    } catch (ConsoleConnectionException e) {
      assertSame(communicationException, e.getCause());
    }

    try {
      consoleConnection.stopAgents();
      fail("Expected ConsoleConnectionException");
    } catch (ConsoleConnectionException e) {
      assertSame(communicationException, e.getCause());
    }

    consoleConnection.close();
  }