Package guru.mikelue.jdut.junit4
Class JdutYamlFactory
- java.lang.Object
-
- guru.mikelue.jdut.junit4.JdutYamlFactory
-
- All Implemented Interfaces:
TestRule
public class JdutYamlFactory extends Object implements TestRule
ThisTestRuleis used to construct the data conduction byYamlConductorFactory.Since
TestRulewould initialize new instance of rule for every test(method), this implementation forYamlConductorFactoryis set by constructor of this object.This rule could be used with
RuleorClassRule.@ClassRule public final static TestRule dataConductor = JdutYamlFactory.buildByDataSource(DataSourceGeter::get);
-
-
Constructor Summary
Constructors Constructor Description JdutYamlFactory(YamlConductorFactory yamlConductorFacotry)Constructs this object by a instance ofYamlConductorFactory.JdutYamlFactory(DataSource dataSource)Constructs this object by data source.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Statementapply(Statement base, Description description)This method would check theJdutResourceon test method, if conditions match, the conduction of data would be triggered.static JdutYamlFactorybuildByDataSource(Supplier<DataSource> supplier)Constructs this object bySupplierofDataSource.static JdutYamlFactorybuildByFactory(Supplier<YamlConductorFactory> supplier)Constructs this object bySupplierofYamlConductorFactory.protected DuetConductorbuildDuetConductor(Description description)BuildsDuetConductor(Optional) by default convention.static Consumer<ConductorConfig.Builder>defaultBuilderOfConductorConfig(Description desc)Constructs a builder forConductorConfigby default convention for resource loading(from testing class).protected booleanneedConductData(Description description)Checks if the test should conduct data.
-
-
-
Constructor Detail
-
JdutYamlFactory
public JdutYamlFactory(DataSource dataSource)
Constructs this object by data source.- Parameters:
dataSource- The object of data source- See Also:
JdutYamlFactory(YamlConductorFactory)
-
JdutYamlFactory
public JdutYamlFactory(YamlConductorFactory yamlConductorFacotry)
Constructs this object by a instance ofYamlConductorFactory.- Parameters:
yamlConductorFacotry- The instance of factory for conducting data
-
-
Method Detail
-
buildByDataSource
public static JdutYamlFactory buildByDataSource(Supplier<DataSource> supplier)
Constructs this object bySupplierofDataSource.- Parameters:
supplier- ProvidesDataSource- Returns:
- new object
-
buildByFactory
public static JdutYamlFactory buildByFactory(Supplier<YamlConductorFactory> supplier)
Constructs this object bySupplierofYamlConductorFactory.- Parameters:
supplier- ProvidesYamlConductorFactory- Returns:
- new object
-
defaultBuilderOfConductorConfig
public static Consumer<ConductorConfig.Builder> defaultBuilderOfConductorConfig(Description desc)
Constructs a builder forConductorConfigby default convention for resource loading(from testing class).- Parameters:
desc- The test information provided by JUnit 4- Returns:
- new builder
-
apply
public Statement apply(Statement base, Description description)
This method would check theJdutResourceon test method, if conditions match, the conduction of data would be triggered.This method would call
buildDuetConductor(org.junit.runner.Description)to buildDuetConductorif the conditions is matched.
-
needConductData
protected boolean needConductData(Description description)
Checks if the test should conduct data.- Parameters:
description- The context of test- Returns:
- true if the conduction should be executed
-
buildDuetConductor
protected DuetConductor buildDuetConductor(Description description)
BuildsDuetConductor(Optional) by default convention.- When used by
Rule, the naming is<class_name>-<method_name>.yaml). - When used by
ClassRule, the naming is<class_name>.yaml).
This method is called by
applyif the method is annotatedJdutResource.- Parameters:
description- the description of test- Returns:
- The initialized conductor for testing
- When used by
-
-