* Call getMetrics on source and get a record builder mock to verify
* @param source the metrics source
* @return the record builder mock to verify
*/
public static MetricsRecordBuilder getMetrics(MetricsSource source) {
MetricsBuilder mb = mock(MetricsBuilder.class);
final MetricsRecordBuilder rb = mock(MetricsRecordBuilder.class,
new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
StringBuilder sb = new StringBuilder();
for (Object o : args) {
if (sb.length() > 0) sb.append(", ");
sb.append(String.valueOf(o));
}
LOG.debug(invocation.getMethod().getName() +": "+ sb);
return invocation.getMock();
}
});
when(mb.addRecord(anyString())).thenReturn(rb);
source.getMetrics(mb, true);
return rb;
}