aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/com/healthmarketscience/jackcess
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2020-04-24 19:55:52 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2020-04-24 19:55:52 +0000
commit11bf84249c9eea4fedacd12b9339fc197521d266 (patch)
tree342114d32173bfaf8f9e34bd794f0ca0a02f9b65 /src/test/java/com/healthmarketscience/jackcess
parentbd9509e6828e5a1ef6619efcdf55385de2725e9f (diff)
downloadjackcess-11bf84249c9eea4fedacd12b9339fc197521d266.tar.gz
jackcess-11bf84249c9eea4fedacd12b9339fc197521d266.zip
add stream support to Iterable classes; add some unit tests with streaming
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1321 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience/jackcess')
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/CursorTest.java22
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java22
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java34
3 files changed, 35 insertions, 43 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java
index e108ae4..c208605 100644
--- a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeSet;
+import java.util.stream.Collectors;
import static com.healthmarketscience.jackcess.Database.*;
import com.healthmarketscience.jackcess.impl.ColumnImpl;
@@ -1102,11 +1103,10 @@ public class CursorTest extends TestCase {
Index idx = t1.getIndex("Table2Table1");
IndexCursor cursor = CursorBuilder.createCursor(idx);
- List<String> expectedData = new ArrayList<String>();
- for(Row row : cursor.newEntryIterable(1)
- .addColumnNames("data")) {
- expectedData.add(row.getString("data"));
- }
+ List<String> expectedData = cursor.newEntryIterable(1)
+ .addColumnNames("data")
+ .stream().map(r -> r.getString("data"))
+ .collect(Collectors.toList());
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
@@ -1155,13 +1155,11 @@ public class CursorTest extends TestCase {
Table t1 = db.getTable("Table1");
Cursor cursor = CursorBuilder.createCursor(t1);
- List<String> expectedData = new ArrayList<String>();
- for(Row row : cursor.newIterable().setColumnNames(
- Arrays.asList("otherfk1", "data"))) {
- if(row.get("otherfk1").equals(1)) {
- expectedData.add(row.getString("data"));
- }
- }
+ List<String> expectedData = cursor.newIterable().setColumnNames(
+ Arrays.asList("otherfk1", "data")).stream()
+ .filter(r -> r.get("otherfk1").equals(1))
+ .map(r -> r.getString("data"))
+ .collect(Collectors.toList());
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
index 2e5c35e..e2e16e5 100644
--- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -35,6 +35,7 @@ import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.UUID;
+import java.util.stream.Collectors;
import static com.healthmarketscience.jackcess.Database.*;
import com.healthmarketscience.jackcess.impl.ColumnImpl;
@@ -571,10 +572,9 @@ public class DatabaseTest extends TestCase
((DatabaseImpl)db).getPageChannel().finishWrite();
}
- Set<Integer> ids = new HashSet<Integer>();
- for(Row row : t) {
- ids.add(row.getInt("ID"));
- }
+ Set<Integer> ids = t.stream()
+ .map(r -> r.getInt("ID"))
+ .collect(Collectors.toSet());
assertEquals(1000, ids.size());
assertTrue(((TableImpl)t).getOwnedPagesCursor().getUsageMap().toString()
@@ -666,10 +666,9 @@ public class DatabaseTest extends TestCase
((DatabaseImpl)db).getPageChannel().finishWrite();
}
- List<Date> foundDates = new ArrayList<Date>();
- for(Row row : table) {
- foundDates.add(row.getDate("date"));
- }
+ List<Date> foundDates = table.stream()
+ .map(r -> r.getDate("date"))
+ .collect(Collectors.toList());
assertEquals(dates.size(), foundDates.size());
for(int i = 0; i < dates.size(); ++i) {
@@ -706,10 +705,9 @@ public class DatabaseTest extends TestCase
table.addRow("row " + dateStr, d);
}
- List<String> foundDates = new ArrayList<String>();
- for(Row row : table) {
- foundDates.add(sdf.format(row.getDate("date")));
- }
+ List<String> foundDates = table.stream()
+ .map(r -> sdf.format(r.getDate("date")))
+ .collect(Collectors.toList());
assertEquals(dates, foundDates);
diff --git a/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java b/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java
index 986c8b5..51017d6 100644
--- a/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java
@@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.Index;
@@ -63,9 +64,9 @@ public class JoinerTest extends TestCase {
assertSame(t2t1, t2t1Join.getFromIndex());
assertSame(t1, t2t1Join.getToTable());
assertSame(t1t2, t2t1Join.getToIndex());
-
+
doTestJoiner(t2t1Join, createT2T1Data());
-
+
Index t3t1 = t1t3.getReferencedIndex();
assertSame(t3, t3t1.getTable());
Joiner t3t1Join = Joiner.create(t3t1);
@@ -74,11 +75,11 @@ public class JoinerTest extends TestCase {
assertSame(t3t1, t3t1Join.getFromIndex());
assertSame(t1, t3t1Join.getToTable());
assertSame(t1t3, t3t1Join.getToIndex());
-
- doTestJoiner(t3t1Join, createT3T1Data());
+
+ doTestJoiner(t3t1Join, createT3T1Data());
doTestJoinerDelete(t2t1Join);
- }
+ }
}
private static void doTestJoiner(
@@ -92,11 +93,8 @@ public class JoinerTest extends TestCase {
for(Row row : join.getFromTable()) {
Integer id = row.getInt("id");
- List<Row> joinedRows =
- new ArrayList<Row>();
- for(Row t1Row : join.findRows(row)) {
- joinedRows.add(t1Row);
- }
+ List<Row> joinedRows = join.findRows(row).stream()
+ .collect(Collectors.toList());
List<Row> expectedRows = expectedData.get(id);
assertEquals(expectedData.get(id), joinedRows);
@@ -110,18 +108,16 @@ public class JoinerTest extends TestCase {
assertFalse(join.hasRows(row));
assertNull(join.findFirstRow(row));
}
-
+
List<Row> expectedRows2 = new ArrayList<Row>();
for(Row tmpRow : expectedRows) {
Row tmpRow2 = new RowImpl(tmpRow);
tmpRow2.keySet().retainAll(colNames);
expectedRows2.add(tmpRow2);
}
-
- joinedRows = new ArrayList<Row>();
- for(Row t1Row : join.findRows(row).setColumnNames(colNames)) {
- joinedRows.add(t1Row);
- }
+
+ joinedRows = join.findRows(row).setColumnNames(colNames)
+ .stream().collect(Collectors.toList());
assertEquals(expectedRows2, joinedRows);
@@ -129,7 +125,7 @@ public class JoinerTest extends TestCase {
assertEquals(expectedRows2.get(0), join.findFirstRow(row, colNames));
} else {
assertNull(join.findFirstRow(row, colNames));
- }
+ }
}
}
@@ -175,7 +171,7 @@ public class JoinerTest extends TestCase {
return data;
}
-
+
private static Map<Integer,List<Row>> createT3T1Data()
{
Map<Integer,List<Row>> data = new HashMap<Integer,List<Row>>();
@@ -202,5 +198,5 @@ public class JoinerTest extends TestCase {
return data;
}
-
+
}