use of com.github.nagyesta.abortmission.core.telemetry.stats.DefaultLaunchTelemetry in project abort-mission by nagyesta.
the class ReportingHelperTest method testTestExecutionFinishedShouldSaveProvidedData.
@Test
void testTestExecutionFinishedShouldSaveProvidedData() throws IOException {
// given
final ReportingHelper underTest = spy(new ReportingHelper());
final String dirname = System.getProperty("java.io.tmpdir") + "/abort-mission/";
doReturn(Optional.of(dirname)).when(underTest).reportingRoot();
final LaunchTelemetryDataSource dataSource = mock(LaunchTelemetryDataSource.class);
when(dataSource.fetchClassStatistics()).thenReturn(Collections.emptySortedMap());
final DefaultLaunchTelemetry telemetry = new DefaultLaunchTelemetry(dataSource);
doReturn(dataSource).when(underTest).launchTelemetryDataSource();
final ArgumentCaptor<File> fileCaptor = ArgumentCaptor.forClass(File.class);
doCallRealMethod().when(underTest).writeJson(any(DefaultLaunchTelemetry.class), fileCaptor.capture());
// when
underTest.report();
// then
verify(underTest).reportingRoot();
verify(underTest).launchTelemetryDataSource();
final File file = fileCaptor.getValue();
Files.readAllLines(file.toPath()).forEach(line -> Assertions.assertEquals(new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create().toJson(telemetry), line));
Assertions.assertTrue(file.delete());
}
use of com.github.nagyesta.abortmission.core.telemetry.stats.DefaultLaunchTelemetry in project abort-mission by nagyesta.
the class ReportingHelperTest method testWriteShouldCatchExceptionsWhenThrown.
@Test
void testWriteShouldCatchExceptionsWhenThrown() {
// given
final ReportingHelper underTest = new ReportingHelper();
final LaunchTelemetryDataSource dataSource = mock(LaunchTelemetryDataSource.class);
when(dataSource.fetchClassStatistics()).thenReturn(Collections.emptySortedMap());
final DefaultLaunchTelemetry telemetry = new DefaultLaunchTelemetry(dataSource);
// when
underTest.writeJson(telemetry, null);
// then no exception
}
Aggregations