Test status quo for null-safe Void method references in SpEL
This commit is contained in:
parent
5ff9e6955c
commit
1fe2216c59
|
@ -3898,6 +3898,40 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullSafeInvocationOfNonStaticVoidWrapperMethod() {
|
||||
// non-static method, no args, Void return
|
||||
expression = parser.parseExpression("new %s()?.oneVoidWrapper()".formatted(TestClass5.class.getName()));
|
||||
|
||||
assertCantCompile(expression);
|
||||
|
||||
TestClass5._i = 0;
|
||||
expression.getValue();
|
||||
assertThat(TestClass5._i).isEqualTo(1);
|
||||
|
||||
TestClass5._i = 0;
|
||||
assertCanCompile(expression);
|
||||
expression.getValue();
|
||||
assertThat(TestClass5._i).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullSafeInvocationOfStaticVoidWrapperMethod() {
|
||||
// static method, no args, Void return
|
||||
expression = parser.parseExpression("T(%s)?.twoVoidWrapper()".formatted(TestClass5.class.getName()));
|
||||
|
||||
assertCantCompile(expression);
|
||||
|
||||
TestClass5._i = 0;
|
||||
expression.getValue();
|
||||
assertThat(TestClass5._i).isEqualTo(1);
|
||||
|
||||
TestClass5._i = 0;
|
||||
assertCanCompile(expression);
|
||||
expression.getValue();
|
||||
assertThat(TestClass5._i).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void methodReference() {
|
||||
TestClass5 tc = new TestClass5();
|
||||
|
@ -5712,8 +5746,19 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
public void one() { i = 1; }
|
||||
|
||||
public Void oneVoidWrapper() {
|
||||
_i = 1;
|
||||
this.i = 1;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void two() { _i = 1; }
|
||||
|
||||
public static Void twoVoidWrapper() {
|
||||
_i = 1;
|
||||
return null;
|
||||
}
|
||||
|
||||
public String three() { return "hello"; }
|
||||
public long four() { return 3277700L; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue