diff --git a/src/test/java/org/codelibs/fess/util/StreamUtilTest.java b/src/test/java/org/codelibs/fess/util/StreamUtilTest.java new file mode 100644 index 000000000..e8a19fafd --- /dev/null +++ b/src/test/java/org/codelibs/fess/util/StreamUtilTest.java @@ -0,0 +1,36 @@ +package org.codelibs.fess.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +import org.codelibs.fess.unit.UnitFessTestCase; + +public class StreamUtilTest extends UnitFessTestCase { + + public void test_ofValues() { + String[] values = { "value1", "value2" }; + Stream stream = StreamUtil.of(values[0], values[1]); + Object[] array = stream.toArray(); + for (int i = 0; i < 2; i++) { + assertEquals(values[i], array[i]); + } + } + + public void test_ofNull() { + assertEquals(0, StreamUtil.of().toArray().length); + Object[] o = {}; + assertEquals(0, StreamUtil.of(o).toArray().length); + Map map = new HashMap(); + assertEquals(0, StreamUtil.of(map).toArray().length); + } + + public void test_ofMap() { + Map map = new HashMap(); + map.put("key1", "value1"); + map.put("key2", "value2"); + Stream> stream = StreamUtil.of(map); + stream.forEach(m -> assertEquals(map.get(m.getKey()), m.getValue())); + } + +}