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
ThisTestRule
is used to construct the data conduction byYamlConductorFactory
.Since
TestRule
would initialize new instance of rule for every test(method), this implementation forYamlConductorFactory
is set by constructor of this object.This rule could be used with
Rule
orClassRule
.@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 Statement
apply(Statement base, Description description)
This method would check theJdutResource
on test method, if conditions match, the conduction of data would be triggered.static JdutYamlFactory
buildByDataSource(Supplier<DataSource> supplier)
Constructs this object bySupplier
ofDataSource
.static JdutYamlFactory
buildByFactory(Supplier<YamlConductorFactory> supplier)
Constructs this object bySupplier
ofYamlConductorFactory
.protected DuetConductor
buildDuetConductor(Description description)
BuildsDuetConductor
(Optional
) by default convention.static Consumer<ConductorConfig.Builder>
defaultBuilderOfConductorConfig(Description desc)
Constructs a builder forConductorConfig
by default convention for resource loading(from testing class).protected boolean
needConductData(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 bySupplier
ofDataSource
.- Parameters:
supplier
- ProvidesDataSource
- Returns:
- new object
-
buildByFactory
public static JdutYamlFactory buildByFactory(Supplier<YamlConductorFactory> supplier)
Constructs this object bySupplier
ofYamlConductorFactory
.- Parameters:
supplier
- ProvidesYamlConductorFactory
- Returns:
- new object
-
defaultBuilderOfConductorConfig
public static Consumer<ConductorConfig.Builder> defaultBuilderOfConductorConfig(Description desc)
Constructs a builder forConductorConfig
by 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 theJdutResource
on test method, if conditions match, the conduction of data would be triggered.This method would call
buildDuetConductor(org.junit.runner.Description)
to buildDuetConductor
if 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
apply
if the method is annotatedJdutResource
.- Parameters:
description
- the description of test- Returns:
- The initialized conductor for testing
- When used by
-
-