Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

DataSetBuilder.addDataSet() #4

Merged
merged 3 commits into from

2 participants

@mab

addDataSet() opens the possibility to add merge DataSets to improve the reuse of DataSets within different tests.

@marcphilipp marcphilipp merged commit 15e879d into marcphilipp:master
@marcphilipp
Owner

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 29, 2013
  1. @mab
  2. @mab

    Removed final modifiers.

    mab authored
  3. @mab

    Updated indentation.

    mab authored
This page is out of date. Refresh to see the latest.
View
16 src/main/java/org/dbunit/dataset/builder/DataSetBuilder.java
@@ -3,17 +3,14 @@
import java.util.HashMap;
import java.util.Map;
-import org.dbunit.dataset.CachedDataSet;
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.IDataSet;
-import org.dbunit.dataset.ITableMetaData;
+import org.dbunit.dataset.*;
import org.dbunit.dataset.stream.BufferedConsumer;
import org.dbunit.dataset.stream.IDataSetConsumer;
public class DataSetBuilder {
- private final CachedDataSet dataSet = new CachedDataSet();
- private final IDataSetConsumer consumer = new BufferedConsumer(dataSet);
+ private CachedDataSet dataSet = new CachedDataSet();
+ private IDataSetConsumer consumer = new BufferedConsumer(dataSet);
private final Map<String, TableMetaDataBuilder> tableNameToMetaData = new HashMap<String, TableMetaDataBuilder>();
private final StringPolicy stringPolicy;
@@ -53,6 +50,13 @@ public IDataSet build() throws DataSetException {
consumer.endDataSet();
return dataSet;
}
+
+ public void addDataSet(final IDataSet dataSet) throws DataSetException {
+ IDataSet[] dataSets = { build(), dataSet };
+ CompositeDataSet composite = new CompositeDataSet(dataSets);
+ this.dataSet = new CachedDataSet(composite);
+ consumer = new BufferedConsumer(this.dataSet);
+ }
protected void add(DataRowBuilder row) throws DataSetException {
ITableMetaData metaData = updateTableMetaData(row);
View
25 src/test/java/org/dbunit/dataset/builder/DataSetBuilderTest.java
@@ -106,4 +106,29 @@ public void addsNewColumnsOnTheFly() throws Exception {
assertNull(table.getValue(1, "NAME"));
assertEquals(18, table.getValue(1, "AGE"));
}
+
+ @Test
+ public void addDataSet() throws Exception {
+ DataSetBuilder builder = new DataSetBuilder();
+ builder.newRow("PERSON").with("NAME", "Bob").with("AGE", 18).add();
+
+ IDataSet dataSet = builder.build();
+ ITable table = dataSet.getTable("PERSON");
+
+ assertEquals(1, table.getRowCount());
+
+ builder = new DataSetBuilder();
+ builder.newRow("PERSON").with("NAME", "John").with("AGE", 19).add();
+ builder.addDataSet(dataSet);
+
+ IDataSet dataSet2 = builder.build();
+ ITable table2 = dataSet2.getTable("PERSON");
+
+ assertEquals(2, table2.getRowCount());
+ assertEquals("John", table2.getValue(0, "NAME"));
+ assertEquals(19, table2.getValue(0, "AGE"));
+
+ assertEquals("Bob", table2.getValue(1, "NAME"));
+ assertEquals(18, table2.getValue(1, "AGE"));
+ }
}
Something went wrong with that request. Please try again.