All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jqwik.engine.facades.TestingSupportFacadeImpl Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.facades;

import java.util.*;
import java.util.function.*;

import net.jqwik.api.*;
import net.jqwik.api.facades.*;
import net.jqwik.engine.execution.reporting.*;

public class TestingSupportFacadeImpl extends TestingSupportFacade {

	@Override
	public   Shrinkable generateUntil(RandomGenerator generator, Random random, Function condition) {
		long maxTries = 1000;
		return generator
					   .stream(random)
					   .limit(maxTries)
					   .filter(shrinkable -> condition.apply(shrinkable.value()))
					   .findFirst()
					   .orElseThrow(() -> new JqwikException("Failed to generate value that fits condition after " + maxTries + " tries."));
	}

	@Override
	public String singleLineReport(Object any) {
		ValueReport report = ValueReport.of(any, getSampleReportingFormats());
		return report.singleLineReport();
	}

	@Override
	public List multiLineReport(Object any) {
		// TODO: Add formats from current domain context
		ValueReport report = ValueReport.of(any, getSampleReportingFormats());
		SimpleLineReporter lineReporter = new SimpleLineReporter();
		report.report(lineReporter, 0, "");
		return lineReporter.lines;
	}

	private Collection getSampleReportingFormats() {
		return SampleReportingFormats.getReportingFormats();
	}

	private static class SimpleLineReporter implements LineReporter {

		final List lines = new ArrayList<>();

		@Override
		public void addLine(int indentLevel, String line) {
			String indentation = LineReporter.multiply(' ', indentLevel * 2);
			this.lines.add(indentation + line.trim());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy