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

net.jqwik.engine.providers.HashMapArbitraryProvider Maven / Gradle / Ivy

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

import java.util.*;

import net.jqwik.api.*;
import net.jqwik.api.providers.*;
import net.jqwik.api.support.*;

public class HashMapArbitraryProvider implements ArbitraryProvider {
	@Override
	public boolean canProvideFor(TypeUsage targetType) {
		return targetType.isAssignableFrom(HashMap.class);
	}

	@Override
	public Set> provideFor(TypeUsage targetType, SubtypeProvider subtypeProvider) {
		TypeUsage keyType = targetType.getTypeArgument(0);
		TypeUsage valueType = targetType.getTypeArgument(1);

		return subtypeProvider
			.resolveAndCombine(keyType, valueType)
			.map(arbitraries -> {
				Arbitrary keyArbitrary = arbitraries.get(0);
				Arbitrary valueArbitrary = arbitraries.get(1);
				return Arbitraries.maps(keyArbitrary, valueArbitrary);
			})
			.collect(CollectorsSupport.toLinkedHashSet());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy