@Test
@SuppressWarnings("unchecked")
public void shouldBuildAByteBufferOfTheCorrectLength() throws IOException {
InstanceDomain instanceDomain = mock(InstanceDomain.class);
Instance instance = mock(Instance.class);
PcpMetricInfo pcpMetricInfo = mock(PcpMetricInfo.class);
when(pcpMetricInfo.getTypeHandler()).thenReturn(mock(TypeHandler.class));
when(pcpMetricInfo.byteSize()).thenReturn(MOCK_PCP_METRIC_INFO_BYTE_SIZE);
when(instanceDomain.getInstances()).thenReturn(singletonList(instance));
when(instanceDomain.byteSize()).thenReturn(MOCK_INSTANCE_DOMAIN_BYTE_SIZE);
when(instance.byteSize()).thenReturn(MOCK_INSTANCE_BYTE_SIZE);
when(metricInfoStore.byName(SOME_METRIC_NAME)).thenReturn(pcpMetricInfo);
when(metricInfoStore.all()).thenReturn(singletonList(pcpMetricInfo));
when(instanceDomainStore.all()).thenReturn(singletonList(instanceDomain));
when(byteBuffer.slice()).thenReturn(mock(ByteBuffer.class));
pcpMmvWriter.addMetric(MetricName.parse(SOME_METRIC_NAME), Semantics.COUNTER, null, 1);
pcpMmvWriter.setMetricHelpText(SOME_METRIC_NAME, "Short help", "Long help");
pcpMmvWriter.start();
verify(byteBufferFactory).build(EXPECTED_LENGTH);
}