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

net.jqwik.engine.facades.StoreFacadeImpl 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 org.junit.platform.engine.*;

import net.jqwik.api.lifecycle.*;
import net.jqwik.engine.execution.lifecycle.*;

/**
 * Is loaded through reflection in api module
 */
public class StoreFacadeImpl extends Store.StoreFacade {

	@Override
	public  Store create(Object identifier, Lifespan lifespan, Supplier initialValueSupplier) {
		TestDescriptor scope = CurrentTestDescriptor.get();
		return StoreRepository.getCurrent().create(scope, identifier, lifespan, initialValueSupplier);
	}

	@Override
	public  Store get(Object identifier) {
		TestDescriptor retriever = CurrentTestDescriptor.get();
		Optional> store = StoreRepository.getCurrent().get(retriever, identifier);
		return store.orElseThrow(() -> new CannotFindStoreException(identifier, retriever.getUniqueId().toString()));
	}

	@Override
	public  Store free(Supplier initialValueSupplier) {
		return new Store() {
			T t = initialValueSupplier.get();

			@Override
			public T get() {
				return t;
			}

			@Override
			public Lifespan lifespan() {
				return Lifespan.RUN;
			}

			@Override
			public void update(Function updater) {
				t = updater.apply(t);
			}

			@Override
			public void reset() {
				t = initialValueSupplier.get();
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy