autofixture.generators.UrlGenerator Maven / Gradle / Ivy
package autofixture.generators;
import autofixture.exceptions.ObjectCreationException;
import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InstanceGenerator;
import autofixture.interfaces.InstanceType;
import java.net.MalformedURLException;
import java.net.URL;
public class UrlGenerator implements InstanceGenerator {
@Override
public boolean appliesTo(final InstanceType instanceType) {
return instanceType.isRawTypeAssignableFrom(URL.class);
}
@SuppressWarnings("unchecked")
@Override
public T next(final InstanceType instanceType, final FixtureContract fixture) {
try {
return (T) new URL("https://github.com/grzesiek-galezowski/jfixture/" + fixture.create(int.class));
} catch (final MalformedURLException e) {
throw new ObjectCreationException(instanceType, e);
}
}
@Override
public void setOmittingAutoProperties(final boolean isOn) {
}
}