Search in sources :

Example 11 with ELProcessor

use of jakarta.el.ELProcessor in project tomcat by apache.

the class TestCollectionOperations method testAllMatch02.

@Test
public void testAllMatch02() {
    ELProcessor processor = new ELProcessor();
    Optional result = (Optional) processor.getValue("[1,2,3,4,5].stream().allMatch(x->x>0)", Object.class);
    Assert.assertEquals(Boolean.TRUE, result.get());
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 12 with ELProcessor

use of jakarta.el.ELProcessor in project tomcat by apache.

the class TestCollectionOperations method testDistinct01.

@Test
public void testDistinct01() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("['a', 'b', 'b', 'c'].stream().distinct().toList()", List.class);
    List<String> expected = new ArrayList<>(3);
    expected.add("a");
    expected.add("b");
    expected.add("c");
    Assert.assertEquals(expected, result);
}
Also used : ELProcessor(jakarta.el.ELProcessor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with ELProcessor

use of jakarta.el.ELProcessor in project tomcat by apache.

the class TestCollectionOperations method testReduceLambda02.

@Test(expected = ELException.class)
public void testReduceLambda02() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[].stream().reduce((x,y)->x+y)", Object.class);
    ((Optional) result).get();
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 14 with ELProcessor

use of jakarta.el.ELProcessor in project tomcat by apache.

the class TestCollectionOperations method testMin04.

@Test(expected = ELException.class)
public void testMin04() {
    ELProcessor processor = new ELProcessor();
    processor.defineBean("beans", beans);
    processor.getValue("beans.stream().min()", Object.class);
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Example 15 with ELProcessor

use of jakarta.el.ELProcessor in project tomcat by apache.

the class TestCollectionOperations method testAverage02.

@Test
public void testAverage02() {
    ELProcessor processor = new ELProcessor();
    Object result = processor.getValue("[1,2,3,4,5,6].stream().average()", Object.class);
    Number average = (Number) ((Optional) result).get();
    Assert.assertTrue("Result: " + average.toString(), ELSupport.equals(null, Double.valueOf(3.5), average));
}
Also used : ELProcessor(jakarta.el.ELProcessor) Test(org.junit.Test)

Aggregations

ELProcessor (jakarta.el.ELProcessor)138 Test (org.junit.Test)133 ArrayList (java.util.ArrayList)13 ELContext (jakarta.el.ELContext)8 ValueExpression (jakarta.el.ValueExpression)8 ExpressionFactory (jakarta.el.ExpressionFactory)7 TesterBeanA (org.apache.el.TesterBeanA)5 List (java.util.List)1