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

autofixture.publicinterface.inline.ExplodingInstanceGenerator Maven / Gradle / Ivy

There is a newer version: 2.1.10
Show newest version
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!");
    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy