### Question:
Pinger { void ping() throws IOException { pingCount++; Map<String, String> usageDataMap = collector.getUdcParams(); StringBuilder uri = new StringBuilder( "http: for ( Map.Entry<String,String> entry : usageDataMap.entrySet() ) { uri.append( entry.getKey() ); uri.append( "=" ); uri.append( URLEncoder.encode( entry.getValue(), StandardCharsets.UTF_8.name() ) ); uri.append( "+" ); } uri.append( PING + "=" ).append( pingCount ); URL url = new URL( uri.toString() ); URLConnection con = url.openConnection(); con.setDoInput( true ); con.setDoOutput( false ); con.setUseCaches( false ); con.connect(); con.getInputStream().close(); } Pinger( HostnamePort address, UdcInformationCollector collector );   }### Answer:
@Test public void shouldPingServer() throws IOException { final HostnamePort hostURL = new HostnamePort( hostname, server.getLocalPort() ); final Map<String,String> udcFields = new HashMap<>(); udcFields.put( ID, EXPECTED_STORE_ID ); udcFields.put( UdcConstants.VERSION, EXPECTED_KERNEL_VERSION ); Pinger p = new Pinger( hostURL, new TestUdcCollector( udcFields ) ); p.ping(); Map<String,String> actualQueryMap = handler.getQueryMap(); assertThat( actualQueryMap, notNullValue() ); assertThat( actualQueryMap.get( ID ), is( EXPECTED_STORE_ID ) ); }
@Test public void normalPingSequenceShouldBeOneThenTwoThenThreeEtc() throws Exception { int[] expectedSequence = {1, 2, 3, 4}; final HostnamePort hostURL = new HostnamePort( hostname, server.getLocalPort() ); final Map<String,String> udcFields = new HashMap<>(); Pinger p = new Pinger( hostURL, new TestUdcCollector( udcFields ) ); for ( int s : expectedSequence ) { p.ping(); int count = Integer.parseInt( handler.getQueryMap().get( UdcConstants.PING ) ); assertEquals( s, count ); } }