private HttpServer createMockHttpServer(boolean addDefaultHandler) throws IOException {
		IOException lastException = null;
		for (int retryNum = 0; retryNum < 10; retryNum++) {
			LAST_SERVER_PORT_NUM++; // don't try to reuse the same server port num in the same session
			InetSocketAddress serverAddress =
				new InetSocketAddress(InetAddress.getLoopbackAddress(), LAST_SERVER_PORT_NUM);

			try {
				HttpServer server = HttpServer.create(serverAddress, 0);
				if (addDefaultHandler) {
					server.createContext("/", this::mock404Handler);
				}
				return server;
			}
			catch (IOException e) {
				// ignore, just try again with next port num
				lastException = e;
			}
		}
		throw new IOException(
			"Could not allocate port for mock http server, last attempted port: " +
				LAST_SERVER_PORT_NUM,
			lastException);
	}
Tests the LibreTranslateStringTranslationService by creating a mock HTTP server that responds
to the minimal requests the service needs.
Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/string/translate/libretranslate/LibreTranslateStringTranslationServiceTest.java