Module io.cucumber.picocontainer
Package io.cucumber.picocontainer
Annotation 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
CucumberPicoProviderannotations. All of these annotations will be considered when preparing thePicoContainer. - If there is no
CucumberPicoProviderannotation at all then (beside the basic preparation) no additional PicoContainer preparation will be done. - Cucumber PicoContainer uses PicoContainer's
MutablePicoContainerinternally. Doing so, allProviders will be added byMutablePicoContainer#addAdapter(new ProviderAdapter(provider)). (If any of the providers additionally extendsProviderAdapterthen 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.PicoCompositionExceptionwith message "Duplicate Keys not allowed ..."