Annotation Type CucumberPicoProvider


@Retention(RUNTIME) @Target(TYPE) @API(status=EXPERIMENTAL) public @interface CucumberPicoProvider
This annotation is used to provide some additional PicoContainer Provider classes.

An example is:

 package some.example;

 import java.sql.*;
 import io.cucumber.picocontainer.CucumberPicoProvider;
 import org.picocontainer.injectors.Provider;

 @CucumberPicoProvider
 public class DatabaseConnectionProvider implements Provider {
     public Connection provide() throws ClassNotFoundException, ReflectiveOperationException, SQLException {
         // Connecting to MySQL Using the JDBC DriverManager Interface
         // https://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html
         Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
         return DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "mydbuser", "mydbpassword");
     }
 }
 

Notes:

  • Currently, there is no limitation to the number of CucumberPicoProvider annotations. All of these annotations will be considered when preparing the PicoContainer.
  • If there is no CucumberPicoProvider annotation at all then (beside the basic preparation) no additional PicoContainer preparation will be done.
  • Cucumber PicoContainer uses PicoContainer's MutablePicoContainer internally. Doing so, all Providers will be added by MutablePicoContainer#addAdapter(new ProviderAdapter(provider)). (If any of the providers additionally extends ProviderAdapter then these will be added directly without being wrapped again.)
  • For each class there can be only one Provider. Otherwise an according exception will be thrown (e.g. PicoCompositionException with message "Duplicate Keys not allowed ..."