### Question:
InfluxDbProtocolFormatter { public String format(List<MBeanMetric> metrics, URI uri, AppType appType) { StringBuilder formattedMetrics = new StringBuilder(); for(MBeanMetric metric : metrics) { MBeanResourceMetric resourceMetric = (MBeanResourceMetric) metric; formattedMetrics.append("tessera_") .append(appType) .append("_") .append(sanitize(resourceMetric.getResourceMethod())) .append(",") .append("instance=") .append(uri) .append(" ") .append(sanitize(resourceMetric.getName())) .append("=") .append(resourceMetric.getValue()) .append("\n"); } return formattedMetrics.toString().trim(); }  String format(List<MBeanMetric> metrics, URI uri, AppType appType);  }### Answer:
@Test public void noArgResourceResponseCorrectlyFormatted() { mockMetrics.add(new MBeanResourceMetric("GET->upCheck()#a10a4f8d", "AverageTime[ms]_total", "100")); String expectedResponse = "tessera_P2P_GET_upCheck,instance=http: assertThat(protocolFormatter.format(mockMetrics, mockUri, mockAppType)).isEqualTo(expectedResponse); }
@Test public void singleArgResourceResponseCorrectlyFormatted() { mockMetrics.add(new MBeanResourceMetric("POST->resend(ResendRequest)#8ca0a760", "RequestRate[requestsPerSeconds]", "1.3")); String expectedResponse = "tessera_P2P_POST_resend_ResendRequest,instance=http: assertThat(protocolFormatter.format(mockMetrics, mockUri, mockAppType)).isEqualTo(expectedResponse); }
@Test public void singleArrayArgResourceResponseCorrectlyFormatted() { mockMetrics.add(new MBeanResourceMetric("POST->push(byte[])#7f702b7e", "MinTime[ms]_total", "3.4")); String expectedResponse = "tessera_P2P_POST_push_byte,instance=http: assertThat(protocolFormatter.format(mockMetrics, mockUri, mockAppType)).isEqualTo(expectedResponse); }
@Test public void multipleArgResourceResponseCorrectlyFormatted() { mockMetrics.add(new MBeanResourceMetric("GET->receiveRaw(String;String)#fc8f8357", "AverageTime[ms]_total", "5.2")); String expectedResponse = "tessera_P2P_GET_receiveRaw_StringString,instance=http: assertThat(protocolFormatter.format(mockMetrics, mockUri, mockAppType)).isEqualTo(expectedResponse); }
@Test public void multipleMetricsResponseCorrectlyFormatted() { mockMetrics.add(new MBeanResourceMetric("GET->upCheck()#a10a4f8d", "AverageTime[ms]_total", "100")); mockMetrics.add(new MBeanResourceMetric("POST->resend(ResendRequest)#8ca0a760", "RequestRate[requestsPerSeconds]", "1.3")); String expectedResponse = "tessera_P2P_GET_upCheck,instance=http: "tessera_P2P_POST_resend_ResendRequest,instance=http: assertThat(protocolFormatter.format(mockMetrics, mockUri, mockAppType)).isEqualTo(expectedResponse); }
@Test public void noMetricsToFormatIsHandled() { assertThat(protocolFormatter.format(mockMetrics, mockUri, mockAppType)).isEmpty(); }