autofixture.publicinterface.inline.ExplodingInstanceGenerator Maven / Gradle / Ivy
package autofixture.publicinterface.inline;
import autofixture.exceptions.OnlyInterfacesAreSupportedException;
import autofixture.publicinterface.inline.implementationdetails.ExplodingInstanceHandler;
import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InlineInstanceGenerator;
import com.google.common.reflect.Reflection;
import com.google.common.reflect.TypeToken;
public class ExplodingInstanceGenerator implements InlineInstanceGenerator {
private final TypeToken instance;
public ExplodingInstanceGenerator(final TypeToken instance2) {
this.instance = instance2;
}
@SuppressWarnings("unchecked")
@Override
public T next(final FixtureContract fixture) {
if (instance.getRawType().isInterface()) {
return (T) Reflection.newProxy(instance.getRawType(),
new ExplodingInstanceHandler());
} else {
throw new OnlyInterfacesAreSupportedException(
"Exploding instances can be created out of interfaces only!");
}
}
}