// syntax (it is kinda gross but still cleaner than the version above)
// the first two calls "succeed", the third throws io exn, and then the
// fourth
doNothing().doNothing().doThrow(new IOException()).doNothing().when(
failAppend).append(Mockito.<Event> anyObject());
doReturn(new ReportEvent("stub")).when(failAppend).getMetrics();
StubbornAppendSink<EventSink> sink = new StubbornAppendSink<EventSink>(
failAppend);
sink.open();
for (int i = 0; i < 3; i++) {
sink.append(e);
System.out.println(i);
}
ReportEvent rpt = sink.getMetrics();
Assert.assertEquals(new Long(1), rpt
.getLongMetric(StubbornAppendSink.A_FAILS));
Assert.assertEquals(new Long(1), rpt
.getLongMetric(StubbornAppendSink.A_RECOVERS));
}