/** * Sets the timestamp to 'now' unless the timestamp is already set. * @param telemetry The {@link com.microsoft.applicationinsights.telemetry.Telemetry} to initialize. */ @Override public void initialize(Telemetry telemetry) { if (telemetry.getTimestamp() == null) { telemetry.setTimestamp(new Date()); } } }
@Test public void testSetTimestampWithNonNull() { Telemetry telemetry = createMockTelemetryAndActivateInitializer(new Date()); Mockito.verify(telemetry, Mockito.never()).setTimestamp((Date)anyObject()); }
@Test public void testMethodsOnTelemetryAreCalledWhenTracking() { TelemetryChannel mockChannel = Mockito.mock(TelemetryChannel.class); configuration.setChannel(mockChannel); TelemetryContext mockContext = new TelemetryContext(); Telemetry mockTelemetry = Mockito.mock(Telemetry.class); Mockito.doReturn(mockContext).when(mockTelemetry).getContext(); TelemetryClient telemetryClient = new TelemetryClient(configuration); telemetryClient.track(mockTelemetry); Mockito.verify(mockChannel, Mockito.times(1)).send(mockTelemetry); Mockito.verify(mockTelemetry, Mockito.times(1)).setTimestamp(any(Date.class)); }
@Test public void testSetTimestampWithNull() { Telemetry telemetry = createMockTelemetryAndActivateInitializer(null); Mockito.verify(telemetry, Mockito.times(1)).setTimestamp((Date)anyObject()); }
telemetry.setTimestamp(new Date());