@@ -0,0 +1,2459 @@
+package io.prometheus.client.exporter;%0A%0Aimport io.prometheus.client.Gauge;%0Aimport io.prometheus.client.CollectorRegistry;%0Aimport java.io.IOException;%0Aimport java.net.InetSocketAddress;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0Aimport java.util.Scanner;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Apublic class TestHTTPServer %7B%0A%0A  HTTPServer s;%0A%0A  @Before%0A  public void init() throws IOException %7B%0A    CollectorRegistry registry = new CollectorRegistry();%0A    Gauge.build(%22a%22, %22a help%22).register(registry);%0A    Gauge.build(%22b%22, %22a help%22).register(registry);%0A    Gauge.build(%22c%22, %22a help%22).register(registry);%0A    s = new HTTPServer(new InetSocketAddress(0), registry);%0A  %7D%0A%0A  @After%0A  public void cleanup() %7B%0A    s.stop();%0A  %7D%0A%0A  String request(String suffix) throws IOException %7B%0A    String url = %22http://localhost:%22 + s.server.getAddress().getPort() + %22/metrics%22 + suffix;%0A    URLConnection connection = new URL(url).openConnection();%0A    connection.setDoOutput(true);%0A    connection.connect();%0A    Scanner s = new Scanner(connection.getInputStream(), %22UTF-8%22).useDelimiter(%22%5C%5CA%22);%0A    return s.hasNext() ? s.next() : %22%22;%0A  %7D%0A%0A  @Test%0A  public void testSimpleRequest() throws IOException %7B%0A    String response = request(%22%22);%0A    assertThat(response).contains(%22a 0.0%22);%0A    assertThat(response).contains(%22b 0.0%22);%0A    assertThat(response).contains(%22c 0.0%22);%0A  %7D%0A%0A  @Test%0A  public void testBadParams() throws IOException %7B%0A    String response = request(%22?x%22);%0A    assertThat(response).contains(%22a 0.0%22);%0A    assertThat(response).contains(%22b 0.0%22);%0A    assertThat(response).contains(%22c 0.0%22);%0A  %7D%0A%0A  @Test%0A  public void testSingleName() throws IOException %7B%0A    String response = request(%22?name%5B%5D=a%22);%0A    assertThat(response).contains(%22a 0.0%22);%0A    assertThat(response).doesNotContain(%22b 0.0%22);%0A    assertThat(response).doesNotContain(%22c 0.0%22);%0A  %7D%0A%0A  @Test%0A  public void testMultiName() throws IOException %7B%0A    String response = request(%22?name%5B%5D=a&name%5B%5D=b%22);%0A    assertThat(response).contains(%22a 0.0%22);%0A    assertThat(response).contains(%22b 0.0%22);%0A    assertThat(response).doesNotContain(%22c 0.0%22);%0A  %7D%0A%0A  @Test%0A  public void testDecoding() throws IOException %7B%0A    String response = request(%22?n%2561me%5B%5D=%2561%22);%0A    assertThat(response).contains(%22a 0.0%22);%0A    assertThat(response).doesNotContain(%22b 0.0%22);%0A    assertThat(response).doesNotContain(%22c 0.0%22);%0A  %7D%0A%0A%7D%0A

Add unittest for HTTPServe