BatcherStats { @Nullable synchronized BatchingException asException() { if (requestExceptionCounts.isEmpty() && requestPartialFailureCount == 0) { return null; } StringBuilder messageBuilder = new StringBuilder(); messageBuilder.append("Batching finished with "); if (!requestExceptionCounts.isEmpty()) { messageBuilder .append( String.format("%d batches failed to apply due to: ", requestExceptionCounts.size())) .append(buildExceptionList(requestExceptionCounts, requestStatusCounts)) .append(" and "); } messageBuilder.append(String.format("%d partial failures.", requestPartialFailureCount)); if (requestPartialFailureCount > 0) { int totalEntriesCount = 0; for (Integer count : entryExceptionCounts.values()) { totalEntriesCount += count; } messageBuilder .append( String.format( " The %d partial failures contained %d entries that failed with: ", requestPartialFailureCount, totalEntriesCount)) .append(buildExceptionList(entryExceptionCounts, entryStatusCounts)) .append("."); } return new BatchingException(messageBuilder.toString()); }    }
@Test public void testWhenNoException() { BatcherStats batcherStats = new BatcherStats(); assertThat(batcherStats.asException()).isNull(); }