use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testForEach01.
@Test
public void testForEach01() {
ELProcessor processor = new ELProcessor();
processor.defineBean("beans", beans);
processor.getValue("beans.stream().forEach(b->b.setValLong(b.valLong + 1))", Object.class);
Assert.assertEquals(2, bean01.getValLong());
Assert.assertEquals(3, bean02.getValLong());
Assert.assertEquals(4, bean03.getValLong());
// Restore the beans to their default state
processor.getValue("beans.stream().forEach(b->b.setValLong(b.valLong - 1))", Object.class);
Assert.assertEquals(1, bean01.getValLong());
Assert.assertEquals(2, bean02.getValLong());
Assert.assertEquals(3, bean03.getValLong());
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testAverage01.
@Test
public void testAverage01() {
ELProcessor processor = new ELProcessor();
Object result = processor.getValue("[1,2,3,4,5].stream().average()", Object.class);
Number average = (Number) ((Optional) result).get();
Assert.assertTrue("Result: " + average.toString(), ELSupport.equals(null, Long.valueOf(3), average));
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testFindFirst01.
@Test
public void testFindFirst01() {
ELProcessor processor = new ELProcessor();
processor.defineBean("beans", beans);
Optional result = (Optional) processor.getValue("beans.stream().findFirst()", Object.class);
Assert.assertEquals(bean01, result.get());
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testReduceLambdaSeed01.
@Test
public void testReduceLambdaSeed01() {
ELProcessor processor = new ELProcessor();
Object result = processor.getValue("[1,2,3,4,5].stream().reduce(10, (x,y)->x+y)", Object.class);
Assert.assertEquals(Long.valueOf(25), result);
}
use of jakarta.el.ELProcessor in project tomcat by apache.
the class TestCollectionOperations method testAverage04.
@Test
public void testAverage04() {
ELProcessor processor = new ELProcessor();
Object result = processor.getValue("[].stream().average().orElseGet(()->10)", Object.class);
Assert.assertEquals(Long.valueOf(10), result);
}
Aggregations