Class GuiceFactory

java.lang.Object
io.cucumber.guice.GuiceFactory
All Implemented Interfaces:
Container, Lookup, ObjectFactory

@API(status=STABLE) public final class GuiceFactory extends Object implements ObjectFactory
Guice implementation of the io.cucumber.core.backend.ObjectFactory.
  • Field Details

    • injector

      private @Nullable com.google.inject.Injector injector
    • stepClasses

      private final Collection<Class<?>> stepClasses
    • injectorSourceFromProperty

      private final @Nullable Class<?> injectorSourceFromProperty
    • withInjectorSource

      private @Nullable Class<?> withInjectorSource
    • scenarioScope

      private @Nullable ScenarioScope scenarioScope
  • Constructor Details

    • GuiceFactory

      public GuiceFactory()
  • Method Details

    • addClass

      public boolean addClass(Class<?> stepClass)
      Description copied from interface: Container
      Add a glue class to the test context.

      Invoked after creation but before ObjectFactory.start().

      Specified by:
      addClass in interface Container
      Parameters:
      stepClass - glue class to add to the text context.
      Returns:
      should always return true, should be ignored.
    • hasInjectorSource

      private boolean hasInjectorSource(Class<?> stepClass)
    • checkOnlyOneClassHasInjectorSource

      private void checkOnlyOneClassHasInjectorSource(Class<?> stepClass)
    • setInjector

      void setInjector(com.google.inject.Injector injector)
    • start

      public void start()
      Description copied from interface: ObjectFactory
      Start the object factory. Invoked once per scenario.

      While started Lookup.getInstance(Class) may be invoked.

      Specified by:
      start in interface ObjectFactory
    • stop

      public void stop()
      Description copied from interface: ObjectFactory
      Stops the object factory. Called once per scenario.

      When stopped the object factory should dispose of all glue instances.

      Specified by:
      stop in interface ObjectFactory
    • getInstance

      public <T> T getInstance(Class<T> clazz)
      Description copied from interface: Lookup
      Provides an instance of a glue class.
      Specified by:
      getInstance in interface Lookup
      Type Parameters:
      T - type of Glue class
      Parameters:
      clazz - type of instance to be created.
      Returns:
      new instance of type T