Skip to content

Commit

Permalink
Fix autoboxing warnings in unit tests for API
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Sep 6, 2021
1 parent 3d5c43d commit 0793096
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
20 changes: 11 additions & 9 deletions src/test/java/org/glassfish/el/test/ELProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testSetVariable () {
@Test
public void testConcat() {
Object result = elp.eval("'10' + 1");
assertEquals(result, 11L);
assertEquals(result, Long.valueOf(11));
result = elp.eval("10 += '1'");
assertEquals(result.toString(), "101");
}
Expand All @@ -98,7 +98,7 @@ public void testConcat() {
public void testParenthesis() {
elp.setVariable("xx", "1");
Object result = elp.eval("((xx)) + 1");
assertEquals(result, 2L);
assertEquals(result, Long.valueOf(2));
}

@Test
Expand All @@ -115,7 +115,7 @@ public void defineFuncTest() {
try {
elp.defineFunction("xx", "", meth);
Boolean ret = elp.eval("xx:getBar() == 64");
assertTrue(ret);
assertTrue(ret.booleanValue());
} catch (NoSuchMethodException ex) {

}
Expand All @@ -124,7 +124,7 @@ public void defineFuncTest() {
try {
elp.defineFunction("", "", meth2);
Boolean ret = elp.eval("getFoo() == 100");
assertTrue(ret);
assertTrue(ret.booleanValue());
} catch (NoSuchMethodException ex) {
caught = true;
}
Expand All @@ -133,7 +133,7 @@ public void defineFuncTest() {
try {
elp.defineFunction("yy", "", "org.glassfish.el.test.ELProcessorTest$MyBean", "getBar");
Boolean ret = elp.eval("yy:getBar() == 64");
assertTrue(ret);
assertTrue(ret.booleanValue());
} catch (ClassNotFoundException | NoSuchMethodException ex) {

}
Expand All @@ -142,7 +142,7 @@ public void defineFuncTest() {
try {
elp.defineFunction("yy", "", "org.glassfish.el.test.ELProcessorTest$MyBean", "getFooBar");
Boolean ret = elp.eval("yy:getBar() == 100");
assertTrue(ret);
assertTrue(ret.booleanValue());
} catch (ClassNotFoundException | NoSuchMethodException ex) {
caught = true;
}
Expand All @@ -152,7 +152,7 @@ public void defineFuncTest() {
try {
elp.defineFunction("yy", "", "testBean", "getFoo");
Boolean ret = elp.eval("yy:getBar() == 100");
assertTrue(ret);
assertTrue(ret.booleanValue());
} catch (ClassNotFoundException | NoSuchMethodException ex) {
caught = true;
}
Expand All @@ -170,8 +170,10 @@ public void testBean() {
@Test
public void testImport() {
elm.importClass("org.glassfish.el.test.ELProcessorTest$MyBean");
assertTrue(elp.eval("ELProcessorTest$MyBean.aaaa == 101"));
assertTrue(elp.eval("ELProcessorTest$MyBean.getBar() == 64"));
Boolean ret = elp.eval("ELProcessorTest$MyBean.aaaa == 101");
assertTrue(ret.booleanValue());
ret = elp.eval("ELProcessorTest$MyBean.getBar() == 64");
assertTrue(ret.booleanValue());
elm.importStatic("org.glassfish.el.test.ELProcessorTest$MyBean.aaaa");
assertEquals(Integer.valueOf(101), elp.eval("aaaa"));
elm.importStatic("org.glassfish.el.test.ELProcessorTest$MyBean.getBar");
Expand Down
43 changes: 22 additions & 21 deletions src/test/java/org/glassfish/el/test/LambdaTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -44,55 +45,55 @@ void testExpr(ELProcessor elp, String testname, String expr, Long expected) {
@Test
public void testImmediate() {
ELProcessor elp = new ELProcessor();
testExpr(elp, "immediate", "(x->x+1)(10)", 11L);
testExpr(elp, "immediate0", "(()->1001)()", 1001L);
testExpr(elp, "immediate1", "((x,y)->x+y)(null, null)", 0L);
testExpr(elp, "immediate 2", "(((x,y)->x+y)(3,4))", 7L);
testExpr(elp, "immediate 3", "(x->(y=x)+1)(10) + y", 21L);
testExpr(elp, "immediate", "(x->x+1)(10)", Long.valueOf(11));
testExpr(elp, "immediate0", "(()->1001)()", Long.valueOf(1001));
testExpr(elp, "immediate1", "((x,y)->x+y)(null, null)", Long.valueOf(0));
testExpr(elp, "immediate 2", "(((x,y)->x+y)(3,4))", Long.valueOf(7));
testExpr(elp, "immediate 3", "(x->(y=x)+1)(10) + y", Long.valueOf(21));
}

@Test
public void testAssignInvoke() {
ELProcessor elp = new ELProcessor();
testExpr(elp, "assign", "func = x->x+1; func(10)", 11L);
testExpr(elp, "assign 2", "func = (x,y)->x+y; func(3,4)", 7L);
testExpr(elp, "assign", "func = x->x+1; func(10)", Long.valueOf(11));
testExpr(elp, "assign 2", "func = (x,y)->x+y; func(3,4)", Long.valueOf(7));
}

@Test
public void testConditional() {
ELProcessor elp = new ELProcessor();
elp.eval("cond = true");
testExpr(elp, "conditional", "(x->cond? x+1: x+2)(10)", 11L);
testExpr(elp, "conditional", "(x->cond? x+1: x+2)(10)", Long.valueOf(11));
elp.eval("cond = false");
testExpr(elp, "conditional 2",
"func = cond? (x->x+1): (x->x+2); func(10)", 12L);
"func = cond? (x->x+1): (x->x+2); func(10)", Long.valueOf(12));
}

@Test
public void testFact() {
ELProcessor elp = new ELProcessor();
testExpr(elp, "factorial", "fact = n->n==0? 1: n*fact(n-1); fact(5)", 120L);
testExpr(elp, "fibonacci", "f = n->n==0? 0: n==1? 1: f(n-1)+f(n-2); f(10)", 55L);
testExpr(elp, "factorial", "fact = n->n==0? 1: n*fact(n-1); fact(5)", Long.valueOf(120));
testExpr(elp, "fibonacci", "f = n->n==0? 0: n==1? 1: f(n-1)+f(n-2); f(10)", Long.valueOf(55));
}

@Test
public void testVar() {
ELProcessor elp = new ELProcessor();
elp.setVariable("v", "x->x+1");
testExpr(elp, "assignment to variable", "v(10)", 11L);
testExpr(elp, "assignment to variable", "v(10)", Long.valueOf(11));
}

@Test
public void testLambda() {
ELProcessor elp = new ELProcessor();
testExpr(elp, "Lambda Lambda 1", "f = ()->y->y+1; f()(100)", 101L);
testExpr(elp, "Lambda Lambda 2", "f = (x)->(tem=x; y->tem+y); f(1)(100)", 101L);
testExpr(elp, "Lambda Lambda 3", "(()->y->y+1)()(100)", 101L);
testExpr(elp, "Lambda Lambda 4", "(x->(y->x+y)(1))(100)", 101L);
testExpr(elp, "Lambda Lambda 5", "((x)->(y->x+y))(1)(100)", 101L);
testExpr(elp, "Lambda Lambda 1", "f = ()->y->y+1; f()(100)", Long.valueOf(101));
testExpr(elp, "Lambda Lambda 2", "f = (x)->(tem=x; y->tem+y); f(1)(100)", Long.valueOf(101));
testExpr(elp, "Lambda Lambda 3", "(()->y->y+1)()(100)", Long.valueOf(101));
testExpr(elp, "Lambda Lambda 4", "(x->(y->x+y)(1))(100)", Long.valueOf(101));
testExpr(elp, "Lambda Lambda 5", "((x)->(y->x+y))(1)(100)", Long.valueOf(101));
testExpr(elp, "Lambda Lambda 6"
, "(x->y->x(0)+y)(x->x+1)(100)", 101L);
testExpr(elp, "Lambda Lambda 7", "f = ()->((1)); f()", 1L);
testExpr(elp, "Lambda Lambda 8", "f = ()->(y)->y+1; f()(100)", 101L);
, "(x->y->x(0)+y)(x->x+1)(100)", Long.valueOf(101));
testExpr(elp, "Lambda Lambda 7", "f = ()->((1)); f()", Long.valueOf(1));
testExpr(elp, "Lambda Lambda 8", "f = ()->(y)->y+1; f()(100)", Long.valueOf(101));
}
}
33 changes: 17 additions & 16 deletions src/test/java/org/glassfish/el/test/OperatorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -59,37 +60,37 @@ void testExpr(String testname, String expr, Object expected) {

@Test
public void testConcat() {
testExpr("concat", "a = null; b = null; a + b", 0L);
testExpr("add", "10 + 11", 21L);
testExpr("add 2", "((1)) + 1", 2L);
testExpr("concat", "'10' + 11", 21L);
testExpr("concat 2", "11 + '10'", 21L);
testExpr("concat", "a = null; b = null; a + b", Long.valueOf(0));
testExpr("add", "10 + 11", Long.valueOf(21));
testExpr("add 2", "((1)) + 1", Long.valueOf(2));
testExpr("concat", "'10' + 11", Long.valueOf(21));
testExpr("concat 2", "11 + '10'", Long.valueOf(21));
testExpr("concat 3", "100 += 10 ", "10010");
testExpr("concat 4", "'100' += 10", "10010");
testExpr("concat 5", "'100' + 10 + 1", 111L);
testExpr("concat 5", "'100' + 10 + 1", Long.valueOf(111));
testExpr("concat 6", "'100' += 10 + 1", "10011");
}

@Test
public void testAssign() {
elp.eval("vv = 10");
testExpr("assign", "vv+1", 11L);
testExpr("assign", "vv+1", Long.valueOf(11));
elp.eval("vv = 100");
testExpr("assign 2", "vv", 100L);
testExpr("assign 3", "x = vv = vv+1; x + vv", 202L);
testExpr("assign 2", "vv", Long.valueOf(100));
testExpr("assign 3", "x = vv = vv+1; x + vv", Long.valueOf(202));
elp.eval("map = {'one':100, 'two':200}");
testExpr("assign 4", "map.two = 201; map.two", 201L);
testExpr("assign 4", "map.two = 201; map.two", Long.valueOf(201));
testExpr("assign string", "x='string'; x += 1", "string1");
}

@Test
public void testSemi() {
testExpr("semi", "10; 20", 20L);
testExpr("semi0", "10; 20; 30", 30L);
testExpr("semi", "10; 20", Long.valueOf(20));
testExpr("semi0", "10; 20; 30", Long.valueOf(30));
elp.eval("x = 10; 20");
testExpr("semi 2", "x", 10L);
testExpr("semi 3", "(x = 10; 20) + (x ; x+1)", 31L);
testExpr("semi 4", "(x = 10; y) = 11; x + y", 21L);
testExpr("semi 2", "x", Long.valueOf(10));
testExpr("semi 3", "(x = 10; 20) + (x ; x+1)", Long.valueOf(31));
testExpr("semi 4", "(x = 10; y) = 11; x + y", Long.valueOf(21));
}
@Test
public void testMisc() {
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/org/glassfish/el/test/StaticRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public void tearDown() {
@Test
public void testStaticRef() {
// Pre imported java.lang classes
assertTrue((Boolean)elp.eval("Boolean.TRUE"));
assertTrue((Boolean)elp.eval("Boolean.TRUE")); // test caching Boolean
Boolean ret = elp.eval("Boolean.TRUE");
assertTrue(ret.booleanValue());
ret = elp.eval("Boolean.TRUE");
assertTrue(ret.booleanValue()); // test caching Boolean
}

/*
Expand Down

0 comments on commit 0793096

Please sign in to comment.