@Override public void publishReportEntry(Map<String, String> values) { this.engineExecutionListener.reportingEntryPublished(this.testDescriptor, ReportEntry.from(values)); }
private void printReportEntry(String indent, ReportEntry reportEntry) { out.println(); out.print(indent); out.print(reportEntry.getTimestamp()); Set<Map.Entry<String, String>> entries = reportEntry.getKeyValuePairs().entrySet(); if (entries.size() == 1) { printReportEntry(" ", getOnlyElement(entries)); return; } for (Map.Entry<String, String> entry : entries) { out.println(); printReportEntry(indent + theme.blank(), entry); } }
private List<String> parseStatistics(ReportEntry entry) { return Arrays.stream(entry.getKeyValuePairs().get(StatisticsCollector.KEY_STATISTICS).split(System.getProperty("line.separator"))) // .map(String::trim) // .filter(s -> !s.isEmpty()) // .collect(Collectors.toList()); }
/** * Factory for creating a new {@code ReportEntry} from a key-value pair. * * @param key the key under which the value should published; never * {@code null} or blank * @param value the value to publish; never {@code null} or blank */ public static ReportEntry from(String key, String value) { ReportEntry reportEntry = new ReportEntry(); reportEntry.add(key, value); return reportEntry; }
@Override public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry entry) { printDetail(Color.REPORTED, "reports", entry.toString()); }
/** * Factory for creating a new {@code ReportEntry} from a map of key-value pairs. * * @param keyValuePairs the map of key-value pairs to be published; never * {@code null}; keys and values within entries in the map also must not be * {@code null} or blank */ public static ReportEntry from(Map<String, String> keyValuePairs) { Preconditions.notNull(keyValuePairs, "keyValuePairs must not be null"); ReportEntry reportEntry = new ReportEntry(); keyValuePairs.forEach(reportEntry::add); return reportEntry; }
private void collectReportEntries(TestIdentifier testIdentifier, List<String> systemOutElements, List<String> systemErrElements) { List<ReportEntry> entries = this.reportData.getReportEntries(testIdentifier); if (!entries.isEmpty()) { List<String> systemOutElementsForCapturedOutput = new ArrayList<>(); StringBuilder formattedReportEntries = new StringBuilder(); for (int i = 0; i < entries.size(); i++) { ReportEntry reportEntry = entries.get(i); Map<String, String> keyValuePairs = new LinkedHashMap<>(reportEntry.getKeyValuePairs()); removeIfPresentAndAddAsSeparateElement(keyValuePairs, STDOUT_REPORT_ENTRY_KEY, systemOutElementsForCapturedOutput); removeIfPresentAndAddAsSeparateElement(keyValuePairs, STDERR_REPORT_ENTRY_KEY, systemErrElements); if (!keyValuePairs.isEmpty()) { buildReportEntryDescription(reportEntry.getTimestamp(), keyValuePairs, i + 1, formattedReportEntries); } } systemOutElements.add(formattedReportEntries.toString().trim()); systemOutElements.addAll(systemOutElementsForCapturedOutput); } }
@Example void withBoundedShrinkingBreakOffAfter1000Steps() { List<Shrinkable> parameters = asList( new OneStepShrinkable(900), new OneStepShrinkable(900) ); PropertyShrinker shrinker = new PropertyShrinker(parameters, ShrinkingMode.BOUNDED, reporter, new Reporting[0]); PropertyShrinkingResult result = shrinker.shrink(ignore -> false, null); assertThat(result.values()).isEqualTo(asList(0, 800)); ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); verify(reporter, times(1)).accept(entryCaptor.capture()); assertThat(entryCaptor.getValue().getKeyValuePairs()).containsKeys("shrinking bound reached"); }
@Override public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry entry) { printlnTestDescriptor(Color.REPORTED, "Reported:", testIdentifier); printlnMessage(Color.REPORTED, "Reported values", entry.toString()); }
@Example void succeedWithSingleNumber() { PropertyMethodDescriptor descriptor = (PropertyMethodDescriptor) forMethod(ContainerClass.class, "succeedWithANumber", int.class) .build(); executeTests(descriptor); InOrder events = Mockito.inOrder(eventRecorder); events.verify(eventRecorder).executionStarted(isPropertyDescriptorFor(ContainerClass.class, "succeedWithANumber")); events.verify(eventRecorder).reportingEntryPublished(isPropertyDescriptorFor(ContainerClass.class, "succeedWithANumber"), reportEntryCaptor.capture()); events.verify(eventRecorder).executionFinished(isPropertyDescriptorFor(ContainerClass.class, "succeedWithANumber"), isSuccessful()); Assertions.assertThat(reportEntryCaptor.getValue().getKeyValuePairs()).containsKey("seed"); }
@Override public void publishReportEntry(Map<String, String> values) { this.engineExecutionListener.reportingEntryPublished(this.benchmarkDescriptor, ReportEntry.from(values)); }
@Example void collectStatistics() { ForAllSpy forAllFunction = new ForAllSpy(value -> { Statistics.collect(value); return true; }, value -> true); Arbitrary<Integer> arbitrary = Arbitraries.samples(1); ShrinkablesGenerator shrinkablesGenerator = randomizedShrinkablesGenerator(arbitrary); GenericProperty property = new GenericProperty("simple", aConfig().build(), shrinkablesGenerator, forAllFunction); Consumer<ReportEntry> mockPublisher = mock(Consumer.class); PropertyCheckResult result = property.check(mockPublisher, new Reporting[0]); ArgumentCaptor<ReportEntry> reportEntryCaptor = ArgumentCaptor.forClass(ReportEntry.class); verify(mockPublisher, atLeast(2)).accept(reportEntryCaptor.capture()); Set<String> keys = reportEntryCaptor.getAllValues().stream() // .flatMap(entry -> entry.getKeyValuePairs().keySet().stream()) // .collect(Collectors.toSet()); Assertions.assertThat(keys).contains("collected statistics"); // Remove statistics from this test from ThreadLocal<Collector>: StatisticsCollector.clearAll(); }
@Example void failWithSingleNumber() { PropertyMethodDescriptor descriptor = (PropertyMethodDescriptor) forMethod(ContainerClass.class, "failWithANumber", int.class) .build(); executeTests(descriptor); InOrder events = Mockito.inOrder(eventRecorder); events.verify(eventRecorder).executionStarted(isPropertyDescriptorFor(ContainerClass.class, "failWithANumber")); events.verify(eventRecorder).reportingEntryPublished(isPropertyDescriptorFor(ContainerClass.class, "failWithANumber"), reportEntryCaptor.capture()); events.verify(eventRecorder).executionFinished(isPropertyDescriptorFor(ContainerClass.class, "failWithANumber"), isFailed()); Assertions.assertThat(reportEntryCaptor.getValue().getKeyValuePairs()).containsKey("seed"); }