diff --git a/waltz-common/src/test/java/org/finos/waltz/common/BatchProcessingCollectorTest.java b/waltz-common/src/test/java/org/finos/waltz/common/BatchProcessingCollectorTest.java new file mode 100644 index 0000000000..0996c88228 --- /dev/null +++ b/waltz-common/src/test/java/org/finos/waltz/common/BatchProcessingCollectorTest.java @@ -0,0 +1,31 @@ +package org.finos.waltz.common; + +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BatchProcessingCollectorTest { + + @Test + public void batchingWorksAndReportsNumberOfItemsProcessed() { + ArrayList data = ListUtilities.newArrayList("A", "B", "C", "D"); + List batched = new ArrayList<>(); + + BatchProcessingCollector batchProcessor = new BatchProcessingCollector<>( + 3, + xs -> { + batched.add(StringUtilities.join(xs, "!")); + }); + + Integer rc = data + .stream() + .collect(batchProcessor); + + assertEquals(4, rc, "Should have processed all input items"); + assertEquals(ListUtilities.asList("A!B!C", "D"), batched); + } +} diff --git a/waltz-common/src/test/java/org/finos/waltz/common/Columns_toOffsetTest.java b/waltz-common/src/test/java/org/finos/waltz/common/Columns_toOffsetTest.java new file mode 100644 index 0000000000..9df97a5b89 --- /dev/null +++ b/waltz-common/src/test/java/org/finos/waltz/common/Columns_toOffsetTest.java @@ -0,0 +1,15 @@ +package org.finos.waltz.common; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Columns_toOffsetTest { + + @Test + public void toOffset() { + assertEquals(Columns.A, Columns.toOffset("A")); + assertEquals(Columns.BA, Columns.toOffset("BA")); + assertEquals(53, Columns.toOffset("BB")); + } +} diff --git a/waltz-common/src/test/java/org/finos/waltz/common/ListUtilities_getOrDefaultTest.java b/waltz-common/src/test/java/org/finos/waltz/common/ListUtilities_getOrDefaultTest.java new file mode 100644 index 0000000000..a44c877994 --- /dev/null +++ b/waltz-common/src/test/java/org/finos/waltz/common/ListUtilities_getOrDefaultTest.java @@ -0,0 +1,22 @@ +package org.finos.waltz.common; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.finos.waltz.common.ListUtilities.getOrDefault; +import static org.finos.waltz.common.TestUtilities.assertLength; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ListUtilities_getOrDefaultTest { + + @Test + public void getOrDefaultTests(){ + List arr = ListUtilities.newArrayList("a", "b"); + assertEquals("a", getOrDefault(arr, 0, "z")); + assertEquals("b", getOrDefault(arr, 1, "z")); + assertEquals("z", getOrDefault(arr, 100, "z")); + assertEquals("z", getOrDefault(arr, -1, "z")); + + } +} diff --git a/waltz-common/src/test/java/org/finos/waltz/common/StreamUtilities_siphonTest.java b/waltz-common/src/test/java/org/finos/waltz/common/StreamUtilities_siphonTest.java new file mode 100644 index 0000000000..87669459e8 --- /dev/null +++ b/waltz-common/src/test/java/org/finos/waltz/common/StreamUtilities_siphonTest.java @@ -0,0 +1,32 @@ +package org.finos.waltz.common; + +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.finos.waltz.common.StreamUtilities.mkSiphon; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class StreamUtilities_siphonTest { + + @Test + public void siphon(){ + StreamUtilities.Siphon siphon = mkSiphon(x -> x.startsWith("h")); + + List result = Stream + .of("hello", "world", "happy", "earth", "hip", "hip", "hooray") + .filter(siphon) + .collect(Collectors.toList()); + + assertEquals(ListUtilities.asList("world", "earth"), result); + assertTrue(siphon.hasResults()); + assertEquals(ListUtilities.asList("hello", "happy", "hip", "hip", "hooray"), siphon.getResults()); + + } +}