@Test
  public void readComponentMeasures_is_not_cached() {
    writer.writeComponentMeasures(COMPONENT_REF, of(MEASURE));

    assertThat(underTest.readComponentMeasures(COMPONENT_REF))
        .isNotSameAs(underTest.readComponentMeasures(COMPONENT_REF));
  }
  @Override
  public void publish(BatchReportWriter writer) {
    for (final BatchResource resource : resourceCache.all()) {
      Iterable<Measure> batchMeasures = measureCache.byResource(resource.resource());
      batchMeasures =
          Iterables.filter(
              batchMeasures,
              new Predicate<Measure>() {
                @Override
                public boolean apply(Measure input) {
                  // Reload Metric to have all Hibernate fields populated
                  input.setMetric(metricFinder.findByKey(input.getMetricKey()));
                  return shouldPersistMeasure(resource.resource(), input);
                }
              });
      Iterable<org.sonar.batch.protocol.output.BatchReport.Measure> reportMeasures =
          Iterables.transform(
              batchMeasures,
              new Function<Measure, BatchReport.Measure>() {
                private final BatchReport.Measure.Builder builder =
                    BatchReport.Measure.newBuilder();

                @Override
                public BatchReport.Measure apply(Measure input) {
                  return toReportMeasure(builder, input);
                }
              });
      writer.writeComponentMeasures(resource.batchId(), reportMeasures);
    }
  }
  @Test
  public void verify_readComponentMeasures_returns_measures() {
    writer.writeComponentMeasures(COMPONENT_REF, of(MEASURE));

    try (CloseableIterator<BatchReport.Measure> measures =
        underTest.readComponentMeasures(COMPONENT_REF)) {
      assertThat(measures.next()).isEqualTo(MEASURE);
      assertThat(measures.hasNext()).isFalse();
    }
  }