@Test public void test_of_flows() { List<Integer> result = Flow.of(Flow.of(1), Flow.of(2, 3)).toList().get(); Assert.assertEquals(3, result.size()); Assert.assertEquals(Integer.valueOf(1), result.get(0)); Assert.assertEquals(Integer.valueOf(2), result.get(1)); Assert.assertEquals(Integer.valueOf(3), result.get(2)); }
@Test public void test_async_limit_queue() { List<String> result = Flow.of("a", "b", "c").async(1, new Mapper<String, Flow<String>>() { @Override public Flow<String> map(String s) { return Flow.of(s.toUpperCase()); } }).toList().get(); Assert.assertEquals(3, result.size()); Assert.assertTrue(result.containsAll(Arrays.asList("A", "B", "C"))); }
protected void processArgs(CollectionTools.Closure<String, String> args) { String value; if ((value = args.execute("env")) != null) environment = Environment.parse(value); if ((value = args.execute("environment")) != null) environment = Environment.parse(value); if ((value = args.execute("profiles.active")) != null) Flow.of(value.split(",")).each(this::addProfile).execute(); }
@Test public void test_of_iterable() { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); int result = Flow.of(list).count().get(); Assert.assertEquals(3, result); }
@Test public void test_sorted_list() { List<Integer> result = Flow.of(3, 2, 1).toSortedList().get(); Assert.assertEquals(3, result.size()); Assert.assertEquals(Integer.valueOf(1), result.get(0)); Assert.assertEquals(Integer.valueOf(2), result.get(1)); Assert.assertEquals(Integer.valueOf(3), result.get(2)); }
@Test public void test_each() { final AtomicInteger counter = new AtomicInteger(); Flow.of(1, 2, 3).each(new Consumer<Integer>() { @Override public void consume(Integer integer) { counter.incrementAndGet(); } }).execute(); Assert.assertEquals(3, counter.get()); }
@Test public void test_min_2() { Comparator<Number> comparator = new Comparator<Number>() { @Override public int compare(Number o1, Number o2) { return Integer.valueOf(o1.intValue()).compareTo(o2.intValue()); } }; Assert.assertEquals(Integer.valueOf(1), Flow.of(1, 2, 3).min(comparator).get()); Assert.assertEquals(Integer.valueOf(1), Flow.of(3, 2, 1).min(comparator).get()); }
@Test public void test_async() { List<String> result = Flow.of("a", "b", "c").async(new Mapper<String, Flow<String>>() { @Override public Flow<String> map(String s) { return Flow.of(s.toUpperCase()); } }).toList().get(); Assert.assertEquals(3, result.size()); Assert.assertTrue(result.containsAll(Arrays.asList("A", "B", "C"))); }
@Test public void test_orElse() { Assert.assertEquals(Integer.valueOf(-1), Flow.of(1, 2, 3) .filter(new Filter<Integer>() { @Override public boolean allow(Integer integer) { return integer > 10; } }) .first() .orElse(-1)); }
@Test public void test_map_to_null() { List<String> result = Flow.of(1, 2, 3) .map(new Mapper<Integer, String>() { @Override public String map(Integer integer) { return null; } }).toList().get(); Assert.assertEquals(0, result.size()); }
@Test public void test_until() { Assert.assertEquals("1,2,3", Flow.of(1, 2, 3, 4, 5) .until(new Filter<Integer>() { @Override public boolean allow(Integer integer) { return integer >= 4; } }) .join(",") .get()); }
@Test public void test_while() { Assert.assertEquals("1,2,3", Flow.of(1, 2, 3, 4, 5) .whilst(new Filter<Integer>() { @Override public boolean allow(Integer integer) { return integer < 4; } }) .join(",") .get()); }
@Test public void test_flow_of_one() { Assert.assertEquals("A", Flow.of("a").map(new Mapper<String, String>() { @Override public String map(String s) { return s.toUpperCase(); } }).first().get()); }