### Question:
JmxRuntimeFactory { public @Nonnull JmxRuntime forRemoteProcess(@Nonnull String host, int port) throws FailedToInitializeJmxConnection { return forRemoteProcess(host, port, null, null); }  @Nonnull JmxRuntime forConnectionString(@Nonnull String locator); @Nonnull JmxRuntime forRemoteProcess(@Nonnull String host, int port); @Nonnull JmxRuntime forRemoteProcess(@Nonnull String host, int port, String username, String password); @Nonnull JmxRuntime forLocalProcess(int pid);  }### Answer:
@Test public void jmxRemoteConnect() throws Exception { TestThread.JMXProcess process = runRemoteSut(); JmxRuntime runtime = new JmxRuntimeFactory().forRemoteProcess(JMX_HOST, process.JMX_PORT); assertThreadState(runtime); }
@Test(timeout = 10000) public void jmxRemoteConnectMissingPasswd() throws Exception { TestThread.JMXProcess process = runRemoteSut(true); try { new JmxRuntimeFactory().forRemoteProcess(JMX_HOST, process.JMX_PORT); fail(); } catch (JmxRuntimeFactory.FailedToInitializeJmxConnection ex) { assertThat(ex.getMessage(), containsString("Credentials required")); } }
@Test public void jmxRemoteConnectWithIncorrectPasswd() throws Exception { TestThread.JMXProcess process = runRemoteSut(true); try { new JmxRuntimeFactory().forRemoteProcess(JMX_HOST, process.JMX_PORT, JMX_USER, "incorrect_passwd"); fail(); } catch (JmxRuntimeFactory.FailedToInitializeJmxConnection ex) { assertThat(ex.getMessage(), containsString("Invalid username or password")); } }
@Test(expected = JmxRuntimeFactory.FailedToInitializeJmxConnection.class) public void connectToNonexistingRemoteProcess() { new JmxRuntimeFactory().forRemoteProcess("localhost", 0); }