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

net.jqwik.engine.DefaultJqwikConfiguration Maven / Gradle / Ivy

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

import java.nio.file.*;
import java.util.*;
import java.util.stream.*;

import org.junit.platform.engine.*;

import net.jqwik.engine.recording.*;

public class DefaultJqwikConfiguration implements JqwikConfiguration {

	private final JqwikProperties properties;
	private TestEngineConfiguration testEngineConfiguration = null;

	DefaultJqwikConfiguration() {
		this(new JqwikProperties());
	}

	private DefaultJqwikConfiguration(JqwikProperties properties) {
		this.properties = properties;
	}

	@Override
	public PropertyDefaultValues propertyDefaultValues() {
		return PropertyDefaultValues.with(properties.defaultTries(), properties.defaultMaxDiscardRatio(), properties.defaultAfterFailure());
	}

	@Override
	public TestEngineConfiguration testEngineConfiguration() {
		if (null == testEngineConfiguration) {
			testEngineConfiguration = createTestEngineConfiguration();
		}
		return testEngineConfiguration;
	}

	@Override
	public boolean useJunitPlatformReporter() {
		return properties.useJunitPlatformReporter();
	}

	@Override
	public boolean reportOnlyFailures() {
		return properties.reportOnlyFailures();
	}

	private TestEngineConfiguration createTestEngineConfiguration() {
		TestRunDatabase database = new TestRunDatabase(Paths.get(properties.databasePath()));
		TestRunData previousRun = database.previousRun();
		return new TestEngineConfiguration() {
			@Override
			public TestRunRecorder recorder() {
				return database.recorder();
			}

			@Override
			public TestRunData previousRun() {
				return database.previousRun();
			}

			@Override
			public Set previousFailures() {
				if (!properties.runFailuresFirst())
					return Collections.emptySet();
				return previousRun.allNonSuccessfulTests().map(TestRun::getUniqueId).collect(Collectors.toSet());
			}
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy