DeviceConnectionDurationTracker { public DeviceConnectionDurationTracker updateNoOfDeviceConnections(final long noOfDeviceConnections) { if (noOfDeviceConnections < 0) { throw new IllegalArgumentException("number of device connections must be >= 0"); } report(); this.noOfDeviceConnections.set(noOfDeviceConnections); log.trace("Updated number of device connections for the tenant [{}] to [{}]", tenantId, noOfDeviceConnections); if (noOfDeviceConnections == 0) { vertx.cancelTimer(timerId); log.trace("Stopped the device connection duration tracker for the tenant [{}].", tenantId); return null; } return this; } private  DeviceConnectionDurationTracker(
            final String tenantId, final Vertx vertx,
            final long noOfDeviceConnections,
            final Consumer<Long> recorder,
            final long recordingIntervalInMs); DeviceConnectionDurationTracker updateNoOfDeviceConnections(final long noOfDeviceConnections);  }
@SuppressWarnings("unchecked") @Test public void testScheduledRecordingOfConnectionDurationIsCancelled() { final DeviceConnectionDurationTracker tracker = DeviceConnectionDurationTracker.Builder .forTenant("TEST_TENANT") .withNumberOfDeviceConnections(1) .withVertx(vertx) .withRecordingInterval(10) .recordUsing(duration -> { }) .start(); verify(vertx).setPeriodic(eq(10L), any(Handler.class)); assertNull(tracker.updateNoOfDeviceConnections(0)); verify(vertx).cancelTimer(anyLong()); }