PushGatewayProvider implements Provider<PushGateway> { @Override public PushGateway get() { final HostAndPort address = configuration.getAddress().withDefaultPort(9091); return new PushGateway(address.toString()); } @Inject  PushGatewayProvider(MetricsPrometheusReporterConfiguration configuration); @Override PushGateway get();  }
@Test public void getReturnsPushGatewayProvider() throws Exception { final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_ACCEPTED)); server.start(); final MetricsPrometheusReporterConfiguration configuration = new MetricsPrometheusReporterConfiguration() { @Override public HostAndPort getAddress() { return HostAndPort.fromParts(server.getHostName(), server.getPort()); } }; final PushGatewayProvider provider = new PushGatewayProvider(configuration); final PushGateway pushGateway = provider.get(); pushGateway.push(CollectorRegistry.defaultRegistry, "test"); final RecordedRequest request = server.takeRequest(); assertEquals("PUT", request.getMethod()); assertEquals("/metrics/job/test", request.getPath()); assertEquals("text/plain; version=0.0.4; charset=utf-8", request.getHeader("Content-Type")); assertEquals(0L, request.getBodySize()); }