### Question:
HopServer { @VisibleForTesting static void callStopHopServerRestService( String hostname, String port, String username, String password ) throws ParseException, HopServerCommandException { try { HopClientEnvironment.init(); ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); Client client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) ); String contextURL = "http: WebResource resource = client.resource( contextURL + "/status/?xml=Y" ); String response = resource.get( String.class ); if ( response == null || !response.contains( "<serverstatus>" ) ) { throw new HopServerCommandException( BaseMessages.getString( PKG, "HopServer.Error.NoServerFound", hostname, "" + port ) ); } resource = client.resource( contextURL + "/stopHopServer" ); response = resource.get( String.class ); if ( response == null || !response.contains( "Shutting Down" ) ) { throw new HopServerCommandException( BaseMessages.getString( PKG, "HopServer.Error.NoShutdown", hostname, "" + port ) ); } } catch ( Exception e ) { throw new HopServerCommandException( BaseMessages.getString( PKG, "HopServer.Error.NoServerFound", hostname, "" + port ), e ); } } HopServer( final HopServerConfig config );  HopServer( final HopServerConfig config, Boolean joinOverride ); static void main( String[] args ); static void runHopServer( HopServerConfig config ); WebServer getWebServer(); void setWebServer( WebServer webServer ); HopServerConfig getConfig(); void setConfig( HopServerConfig config );  }### Answer:
@Test public void callStopHopServerRestService() throws Exception { WebResource status = mock( WebResource.class ); doReturn( "<serverstatus>" ).when( status ).get( String.class ); WebResource stop = mock( WebResource.class ); doReturn( "Shutting Down" ).when( stop ).get( String.class ); Client client = mock( Client.class ); doCallRealMethod().when( client ).addFilter( any( HTTPBasicAuthFilter.class ) ); doCallRealMethod().when( client ).getHeadHandler(); doReturn( status ).when( client ).resource( "http: doReturn( stop ).when( client ).resource( "http: mockStatic( Client.class ); when( Client.create( any( ClientConfig.class ) ) ).thenReturn( client ); HopServer.callStopHopServerRestService( "localhost", "8080", "admin", "Encrypted 2be98afc86aa7f2e4bb18bd63c99dbdde" ); assertEquals( "Basic " + new String( Base64.getEncoder().encode( "admin:password".getBytes( "utf-8" ) ) ), getInternalState( client.getHeadHandler(), "authentication" ) ); }