From acb7acd5d954cfa2798cc2ce0fe477e509f4bfa2 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Sun, 25 Jun 2023 11:01:53 +0800 Subject: [PATCH 1/2] Replace @CsvSource with @ValueSource where feasible @ValueSource is more appropriate for single parameter. See gh-36062 --- .../ModifiedClassPathExtensionForkParameterizedTests.java | 5 +++-- .../boot/context/config/ConfigDataEnvironmentTests.java | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java index 10360fd282..849d027ff8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import static org.assertj.core.api.Assertions.assertThat; @@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link ForkedClassPath @ForkedClassPath}. * * @author Andy Wilkinson + * @author Yanming Zhou */ @ForkedClassPath class ModifiedClassPathExtensionForkParameterizedTests { @@ -35,7 +36,7 @@ class ModifiedClassPathExtensionForkParameterizedTests { private static final List arguments = new ArrayList<>(); @ParameterizedTest - @CsvSource({ "one", "two", "three" }) + @ValueSource(strings = { "one", "two", "three" }) void testIsInvokedOnceForEachArgument(String argument) { if (argument.equals("one")) { assertThat(arguments).isEmpty(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java index db19c960f7..0346cb92d2 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java @@ -28,7 +28,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.boot.ConfigurableBootstrapContext; import org.springframework.boot.DefaultBootstrapContext; @@ -54,6 +54,7 @@ import static org.mockito.Mockito.mock; * * @author Phillip Webb * @author Madhura Bhave + * @author Yanming Zhou */ class ConfigDataEnvironmentTests { @@ -229,7 +230,7 @@ class ConfigDataEnvironmentTests { } @ParameterizedTest - @CsvSource({ "include", "include[0]" }) + @ValueSource(strings = { "include", "include[0]" }) void processAndApplyWhenHasProfileIncludeInProfileSpecificDocumentThrowsException(String property, TestInfo info) { this.environment.setProperty("spring.config.location", getConfigLocation(info)); ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.logFactory, this.bootstrapContext, @@ -253,7 +254,7 @@ class ConfigDataEnvironmentTests { } @ParameterizedTest - @CsvSource({ "spring.profiles.include", "spring.profiles.include[0]" }) + @ValueSource(strings = { "spring.profiles.include", "spring.profiles.include[0]" }) void processAndApplyIncludesProfilesFromSpringProfilesInclude(String property, TestInfo info) { this.environment.setProperty("spring.config.location", getConfigLocation(info)); ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.logFactory, this.bootstrapContext, From 09e5d38348bedffbc711cd874a3891bc12cc5534 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 17 Jul 2023 15:15:25 +0200 Subject: [PATCH 2/2] Polish "Replace @CsvSource with @ValueSource where feasible" See gh-36062 --- .../ModifiedClassPathExtensionForkParameterizedTests.java | 3 +-- .../boot/context/config/ConfigDataEnvironmentTests.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java index 849d027ff8..2a1bc4f47e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link ForkedClassPath @ForkedClassPath}. * * @author Andy Wilkinson - * @author Yanming Zhou */ @ForkedClassPath class ModifiedClassPathExtensionForkParameterizedTests { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java index 0346cb92d2..29764106da 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentTests.java @@ -54,7 +54,6 @@ import static org.mockito.Mockito.mock; * * @author Phillip Webb * @author Madhura Bhave - * @author Yanming Zhou */ class ConfigDataEnvironmentTests {