use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testLimit01.
@Test
public void testLimit01() {
ELProcessor processor = new ELProcessor();
processor.defineBean("beans", beans);
Object result = processor.getValue("beans.stream().limit(2).toList()", Object.class);
List<TesterBeanA> expected = new ArrayList<>(2);
expected.add(bean01);
expected.add(bean02);
Assert.assertEquals(expected, result);
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testFlatMap01.
@Test
public void testFlatMap01() {
ELProcessor processor = new ELProcessor();
processor.defineBean("beans", beans);
Object result = processor.getValue("beans.stream().flatMap(b->b.name.toCharArray().stream()).toList()", List.class);
List<Character> expected = new ArrayList<>(18);
expected.add(Character.valueOf('b'));
expected.add(Character.valueOf('e'));
expected.add(Character.valueOf('a'));
expected.add(Character.valueOf('n'));
expected.add(Character.valueOf('0'));
expected.add(Character.valueOf('1'));
expected.add(Character.valueOf('b'));
expected.add(Character.valueOf('e'));
expected.add(Character.valueOf('a'));
expected.add(Character.valueOf('n'));
expected.add(Character.valueOf('0'));
expected.add(Character.valueOf('2'));
expected.add(Character.valueOf('b'));
expected.add(Character.valueOf('e'));
expected.add(Character.valueOf('a'));
expected.add(Character.valueOf('n'));
expected.add(Character.valueOf('0'));
expected.add(Character.valueOf('3'));
Assert.assertEquals(expected, result);
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testMaxLambda02.
@Test
public void testMaxLambda02() {
ELProcessor processor = new ELProcessor();
processor.defineBean("beans", beans);
processor.setVariable("comparison", "v->(x,y)->v(x).compareTo(v(y))");
Object result = processor.getValue("beans.stream().max(comparison(x->x.name))", Object.class);
Assert.assertEquals(bean03, ((Optional) result).get());
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testMap02.
@Test
public void testMap02() {
ELProcessor processor = new ELProcessor();
processor.defineBean("beans", beans);
Object result = processor.getValue("beans.stream().filter(b->b.valLong > 1).map(b->[b.name, b.valLong]).toList()", List.class);
@SuppressWarnings("unchecked") List<List<Object>> list = (List<List<Object>>) result;
Assert.assertEquals(2, list.size());
Assert.assertEquals("bean02", list.get(0).get(0));
Assert.assertEquals(Long.valueOf(2), list.get(0).get(1));
Assert.assertEquals("bean03", list.get(1).get(0));
Assert.assertEquals(Long.valueOf(3), list.get(1).get(1));
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testAllMatch03.
@Test
public void testAllMatch03() {
ELProcessor processor = new ELProcessor();
Optional result = (Optional) processor.getValue("[1,2,3,4,5].stream().allMatch(x->x>10)", Object.class);
Assert.assertEquals(Boolean.FALSE, result.get());
}
Aggregations