@Test
	public void testWaitUnitAgentPrepared() {
		SingleConsole singleConsole = new SingleConsole(getFreePort()) {
			@Override
			public boolean isCanceled() {
				return canceled;
			}
		};
		ProcessReports report = mock(ProcessReports.class);
		WorkerProcessReport workerProcessReport = mock(WorkerProcessReport.class);
		WorkerProcessReport workerProcessReport2 = mock(WorkerProcessReport.class);
		WorkerProcessReport[] workerProcessReports = new WorkerProcessReport[]{workerProcessReport,
				workerProcessReport2};
		when(workerProcessReport.getNumberOfRunningThreads()).thenReturn((short) 3);
		when(workerProcessReport2.getNumberOfRunningThreads()).thenReturn((short) 2);

		when(report.getWorkerProcessReports()).thenReturn(workerProcessReports);

		ProcessReports[] processReports = new ProcessReports[]{report};
		singleConsole.update(processReports);
		assertThat(singleConsole.getRunningProcess(), is(2));
		assertThat(singleConsole.getRunningThread(), is(5));

		Set<String> fileDigests = new HashSet<>();
		fileDigests.add("E9C4736A0963EB81C0C85AF48CF2F3F2");
		singleConsole.onAcceptDistFilesDigestListener(fileDigests);

		processReports = new ProcessReports[]{};
		singleConsole.waitUntilAgentPrepared(1);
		singleConsole.update(processReports);
		try {
			singleConsole.waitUntilAgentPrepared(1);
			fail("Should throw Exception");
		} catch (NGrinderRuntimeException e) {
			//
		}

		singleConsole.waitUntilAllAgentDisconnected();

		processReports = new ProcessReports[]{report};
		singleConsole.update(processReports);
		try {
			singleConsole.waitUntilAllAgentDisconnected();
			fail("Should throw Exception");
		} catch (NGrinderRuntimeException e) {
			//
		}
	}
Returns a free port number on localhost, or -1 if unable to find a free port.

@return a free port number on localhost, or -1 if unable to find a free port
ngrinder-core/src/test/java/net/grinder/SingleConsoleTest.java