### Question:
LongUpDownCounterSdk extends AbstractSynchronousInstrument<BoundInstrument> implements LongUpDownCounter { @Override public void add(long increment, Labels labels) { BoundInstrument boundInstrument = bind(labels); boundInstrument.add(increment); boundInstrument.unbind(); } private  LongUpDownCounterSdk(
      InstrumentDescriptor descriptor,
      MeterProviderSharedState meterProviderSharedState,
      MeterSharedState meterSharedState,
      Batcher batcher); @Override void add(long increment, Labels labels); @Override void add(long increment);  }### Answer:
@Test void add_PreventNullLabels() { assertThrows( NullPointerException.class, () -> testSdk.longUpDownCounterBuilder("testCounter").build().add(1, null), "labels"); }
@Test void collectMetrics_WithOneRecord() { LongUpDownCounterSdk longUpDownCounter = testSdk.longUpDownCounterBuilder("testUpDownCounter").build(); testClock.advanceNanos(SECOND_NANOS); longUpDownCounter.add(12, Labels.empty()); List<MetricData> metricDataList = longUpDownCounter.collectAll(); assertThat(metricDataList).hasSize(1); MetricData metricData = metricDataList.get(0); assertThat(metricData.getResource()).isEqualTo(RESOURCE); assertThat(metricData.getInstrumentationLibraryInfo()).isEqualTo(INSTRUMENTATION_LIBRARY_INFO); assertThat(metricData.getPoints()).hasSize(1); assertThat(metricData.getPoints()) .containsExactly( LongPoint.create(testClock.now() - SECOND_NANOS, testClock.now(), Labels.empty(), 12)); }
@Test void collectMetrics_WithEmptyLabel() { LongUpDownCounterSdk longUpDownCounter = testSdk.longUpDownCounterBuilder("testUpDownCounter").build(); LongUpDownCounterSdk longUpDownCounter1 = testSdk.longUpDownCounterBuilder("testUpDownCounter1").build(); testClock.advanceNanos(SECOND_NANOS); longUpDownCounter.add(12, Labels.empty()); longUpDownCounter1.add(12); assertThat(longUpDownCounter.collectAll().get(0)) .isEqualToIgnoringGivenFields(longUpDownCounter1.collectAll().get(0), "name"); }
@Test void collectMetrics_WithMultipleCollects() { long startTime = testClock.now(); LongUpDownCounterSdk longUpDownCounter = testSdk.longUpDownCounterBuilder("testUpDownCounter").build(); BoundLongUpDownCounter boundCounter = longUpDownCounter.bind(Labels.of("K", "V")); try { longUpDownCounter.add(12, Labels.empty()); boundCounter.add(123); longUpDownCounter.add(21, Labels.empty()); testClock.advanceNanos(SECOND_NANOS); boundCounter.add(321); longUpDownCounter.add(111, Labels.of("K", "V")); long firstCollect = testClock.now(); List<MetricData> metricDataList = longUpDownCounter.collectAll(); assertThat(metricDataList).hasSize(1); MetricData metricData = metricDataList.get(0); assertThat(metricData.getPoints()).hasSize(2); assertThat(metricData.getPoints()) .containsExactly( LongPoint.create(startTime, firstCollect, Labels.of("K", "V"), 555), LongPoint.create(startTime, firstCollect, Labels.empty(), 33)); testClock.advanceNanos(SECOND_NANOS); boundCounter.add(222); longUpDownCounter.add(11, Labels.empty()); long secondCollect = testClock.now(); metricDataList = longUpDownCounter.collectAll(); assertThat(metricDataList).hasSize(1); metricData = metricDataList.get(0); assertThat(metricData.getPoints()).hasSize(2); assertThat(metricData.getPoints()) .containsExactly( LongPoint.create(startTime, secondCollect, Labels.of("K", "V"), 777), LongPoint.create(startTime, secondCollect, Labels.empty(), 44)); } finally { boundCounter.unbind(); } }