Search in sources :

Example 1 with DefaultLaunchTelemetry

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());
}
Also used : LaunchTelemetryDataSource(com.github.nagyesta.abortmission.core.telemetry.stats.LaunchTelemetryDataSource) DefaultLaunchTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.DefaultLaunchTelemetry) GsonBuilder(com.google.gson.GsonBuilder) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultLaunchTelemetry

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
}
Also used : LaunchTelemetryDataSource(com.github.nagyesta.abortmission.core.telemetry.stats.LaunchTelemetryDataSource) DefaultLaunchTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.DefaultLaunchTelemetry) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultLaunchTelemetry (com.github.nagyesta.abortmission.core.telemetry.stats.DefaultLaunchTelemetry)2 LaunchTelemetryDataSource (com.github.nagyesta.abortmission.core.telemetry.stats.LaunchTelemetryDataSource)2 Test (org.junit.jupiter.api.Test)2 GsonBuilder (com.google.gson.GsonBuilder)1 File (java.io.File)1