-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace static method with separate class (PrepareDatabase)
- Loading branch information
1 parent
56f9a04
commit 7bb4b3f
Showing
5 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.marcphilipp.dbunit.example.builder; | ||
|
||
import static org.dbunit.dataset.builder.ColumnSpec.newColumn; | ||
|
||
import org.dbunit.dataset.builder.ColumnSpec; | ||
|
||
class Schema { | ||
|
||
static class Tables { | ||
static final String PERSON = "PERSON"; | ||
} | ||
|
||
static class PersonTable { | ||
static final ColumnSpec<String> NAME = newColumn("NAME"); | ||
static final ColumnSpec<String> LAST_NAME = newColumn("LAST_NAME"); | ||
static final ColumnSpec<Integer> AGE = newColumn("AGE"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/de/marcphilipp/dbunit/example/rules/CustomRowBuilderDatabaseTestWithRules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/de/marcphilipp/dbunit/example/rules/PrepareDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.marcphilipp.dbunit.example.rules; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.rules.RuleChain; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
public class PrepareDatabase implements TestRule { | ||
|
||
private final DataSource dataSource; | ||
private final Object testInstance; | ||
|
||
public PrepareDatabase(DataSource dataSource, Object testInstance) { | ||
this.dataSource = dataSource; | ||
this.testInstance = testInstance; | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
return chain().apply(base, description); | ||
} | ||
|
||
private RuleChain chain() { | ||
return RuleChain.outerRule(new OnlyRunOracleTestsOnOracle(dataSource)) | ||
.around(new CreateSchemaIfNecessary(dataSource, "schema.sql")) | ||
.around(new ImportDataSet(dataSource, testInstance)); | ||
} | ||
|
||
} |