From ae5dd54115bd9e21917a66255a60f03d50d935f0 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:26:14 +0200 Subject: [PATCH] =?UTF-8?q?Add=20@=E2=81=A0Disabled=20tests=20for=20primit?= =?UTF-8?q?ive=20varargs=20array=20to=20Object[]=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DefaultConversionServiceTests.java | 36 +++++++++++++++++-- .../spel/MethodInvocationTests.java | 8 +++++ .../spel/VariableAndFunctionTests.java | 16 +++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java index 7bb04d558b..6a90a8f4cf 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java @@ -43,6 +43,7 @@ import java.util.UUID; import java.util.regex.Pattern; import java.util.stream.Stream; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; @@ -603,6 +604,12 @@ class DefaultConversionServiceTests { assertThat(result).containsExactly(1, 2, 3); } + @Test + void convertIntArrayToStringArray() { + String[] result = conversionService.convert(new int[] {1, 2, 3}, String[].class); + assertThat(result).containsExactly("1", "2", "3"); + } + @Test void convertIntegerArrayToIntegerArray() { Integer[] result = conversionService.convert(new Integer[] {1, 2, 3}, Integer[].class); @@ -615,6 +622,12 @@ class DefaultConversionServiceTests { assertThat(result).containsExactly(1, 2, 3); } + @Test + void convertIntArrayToIntegerArray() { + Integer[] result = conversionService.convert(new int[] {1, 2}, Integer[].class); + assertThat(result).containsExactly(1, 2); + } + @Test void convertObjectArrayToIntegerArray() { Integer[] result = conversionService.convert(new Object[] {1, 2, 3}, Integer[].class); @@ -627,15 +640,34 @@ class DefaultConversionServiceTests { assertThat(result).containsExactly(1, 2, 3); } + @Disabled("Primitive array to Object[] conversion is not currently supported") @Test - void convertByteArrayToWrapperArray() { + void convertIntArrayToObjectArray() { + Object[] result = conversionService.convert(new int[] {1, 2}, Object[].class); + assertThat(result).containsExactly(1, 2); + } + + @Test + void convertIntArrayToFloatArray() { + Float[] result = conversionService.convert(new int[] {1, 2}, Float[].class); + assertThat(result).containsExactly(1.0F, 2.0F); + } + + @Test + void convertIntArrayToPrimitiveFloatArray() { + float[] result = conversionService.convert(new int[] {1, 2}, float[].class); + assertThat(result).containsExactly(1.0F, 2.0F); + } + + @Test + void convertPrimitiveByteArrayToByteWrapperArray() { byte[] byteArray = {1, 2, 3}; Byte[] converted = conversionService.convert(byteArray, Byte[].class); assertThat(converted).isEqualTo(new Byte[]{1, 2, 3}); } @Test - void convertArrayToArrayAssignable() { + void convertIntArrayToIntArray() { int[] result = conversionService.convert(new int[] {1, 2, 3}, int[].class); assertThat(result).containsExactly(1, 2, 3); } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java index e54d175c45..ecd43f40ca 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/MethodInvocationTests.java @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.expression.Expression; @@ -356,6 +357,13 @@ class MethodInvocationTests extends AbstractExpressionTests { evaluate("formatPrimitiveVarargs('x -> %s %s', '2', 3.0d)", "x -> 2 3", String.class); } + @Disabled("Primitive array to Object[] conversion is not currently supported") + @Test + void testVarargsWithPrimitiveArrayToObjectArrayConversion() { + evaluate("formatObjectVarargs('x -> %s %s %s', new short[]{1, 2, 3})", "x -> 1 2 3", String.class); // short[] to Object[] + evaluate("formatObjectVarargs('x -> %s %s %s', new int[]{1, 2, 3})", "x -> 1 2 3", String.class); // int[] to Object[] + } + @Test void testVarargsOptionalInvocation() { // Calling 'public String optionalVarargsMethod(Optional... values)' diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java index 9cd3e21f3d..c6196bee8c 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java @@ -16,6 +16,7 @@ package org.springframework.expression.spel; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.expression.spel.standard.SpelExpressionParser; @@ -198,6 +199,21 @@ class VariableAndFunctionTests extends AbstractExpressionTests { evaluate("#formatPrimitiveVarargs('x -> %s %s %s', new String[]{'1', '2', '3'})", "x -> 1 2 3", String.class); // String[] to int[] } + @Disabled("Primitive array to Object[] conversion is not currently supported") + @Test + void functionFromMethodWithVarargsAndPrimitiveArrayToObjectArrayConversion() { + evaluate("#varargsObjectFunction(new short[]{1, 2, 3})", "[1, 2, 3]", String.class); // short[] to Object[] + evaluate("#varargsObjectFunction(new int[]{1, 2, 3})", "[1, 2, 3]", String.class); // int[] to Object[] + } + + @Disabled("Primitive array to Object[] conversion is not currently supported") + @Test + void functionFromMethodHandleWithVarargsAndPrimitiveArrayToObjectArrayConversion() { + evaluate("#message('x -> %s %s %s', new short[]{1, 2, 3})", "x -> 1 2 3", String.class); // short[] to Object[] + evaluate("#message('x -> %s %s %s', new int[]{1, 2, 3})", "x -> 1 2 3", String.class); // int[] to Object[] + evaluate("#formatObjectVarargs('x -> %s %s %s', new int[]{1, 2, 3})", "x -> 1 2 3", String.class); // int[] to Object[] + } + @Test void functionMethodMustBeStatic() throws Exception { SpelExpressionParser parser = new SpelExpressionParser();