Browse Source

Use text blocks with JUnit Jupiter 5.8.1

See gh-27450
pull/27494/head
Sam Brannen 5 years ago
parent
commit
08bce08018
  1. 94
      spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java
  2. 36
      spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java
  3. 10
      spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java
  4. 32
      spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java

94
spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java

@ -90,11 +90,11 @@ class ScheduledAnnotationBeanPostProcessorTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"FixedDelay, 5000", FixedDelay, 5_000
"FixedDelayInSeconds, 5000", FixedDelayInSeconds, 5_000
"FixedDelayInMinutes, 180000" FixedDelayInMinutes, 180_000
}) """)
void fixedDelayTask(@NameToClass Class<?> beanClass, long expectedInterval) { void fixedDelayTask(@NameToClass Class<?> beanClass, long expectedInterval) {
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass); BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
@ -123,11 +123,11 @@ class ScheduledAnnotationBeanPostProcessorTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"FixedRate, 3000", FixedRate, 3_000
"FixedRateInSeconds, 5000", FixedRateInSeconds, 5_000
"FixedRateInMinutes, 180000" FixedRateInMinutes, 180_000
}) """)
void fixedRateTask(@NameToClass Class<?> beanClass, long expectedInterval) { void fixedRateTask(@NameToClass Class<?> beanClass, long expectedInterval) {
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass); BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
@ -158,11 +158,11 @@ class ScheduledAnnotationBeanPostProcessorTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"FixedRateWithInitialDelay, 1000, 3000", FixedRateWithInitialDelay, 1_000, 3_000
"FixedRateWithInitialDelayInSeconds, 5000, 3000", FixedRateWithInitialDelayInSeconds, 5_000, 3_000
"FixedRateWithInitialDelayInMinutes, 60000, 180000" FixedRateWithInitialDelayInMinutes, 60_000, 180_000
}) """)
void fixedRateTaskWithInitialDelay(@NameToClass Class<?> beanClass, long expectedInitialDelay, long expectedInterval) { void fixedRateTaskWithInitialDelay(@NameToClass Class<?> beanClass, long expectedInitialDelay, long expectedInterval) {
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass); BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
@ -252,15 +252,15 @@ class ScheduledAnnotationBeanPostProcessorTests {
assertThat(targetObject).isEqualTo(target); assertThat(targetObject).isEqualTo(target);
assertThat(targetMethod.getName()).isEqualTo("fixedRate"); assertThat(targetMethod.getName()).isEqualTo("fixedRate");
assertThat(task1.getInitialDelay()).isEqualTo(0); assertThat(task1.getInitialDelay()).isEqualTo(0);
assertThat(task1.getInterval()).isEqualTo(4000L); assertThat(task1.getInterval()).isEqualTo(4_000L);
IntervalTask task2 = fixedRateTasks.get(1); IntervalTask task2 = fixedRateTasks.get(1);
ScheduledMethodRunnable runnable2 = (ScheduledMethodRunnable) task2.getRunnable(); ScheduledMethodRunnable runnable2 = (ScheduledMethodRunnable) task2.getRunnable();
targetObject = runnable2.getTarget(); targetObject = runnable2.getTarget();
targetMethod = runnable2.getMethod(); targetMethod = runnable2.getMethod();
assertThat(targetObject).isEqualTo(target); assertThat(targetObject).isEqualTo(target);
assertThat(targetMethod.getName()).isEqualTo("fixedRate"); assertThat(targetMethod.getName()).isEqualTo("fixedRate");
assertThat(task2.getInitialDelay()).isEqualTo(2000L); assertThat(task2.getInitialDelay()).isEqualTo(2_000L);
assertThat(task2.getInterval()).isEqualTo(4000L); assertThat(task2.getInterval()).isEqualTo(4_000L);
} }
@Test @Test
@ -407,7 +407,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
Method targetMethod = runnable.getMethod(); Method targetMethod = runnable.getMethod();
assertThat(targetObject).isEqualTo(target); assertThat(targetObject).isEqualTo(target);
assertThat(targetMethod.getName()).isEqualTo("checkForUpdates"); assertThat(targetMethod.getName()).isEqualTo("checkForUpdates");
assertThat(task.getInterval()).isEqualTo(5000L); assertThat(task.getInterval()).isEqualTo(5_000L);
} }
@Test @Test
@ -434,8 +434,8 @@ class ScheduledAnnotationBeanPostProcessorTests {
Method targetMethod = runnable.getMethod(); Method targetMethod = runnable.getMethod();
assertThat(targetObject).isEqualTo(target); assertThat(targetObject).isEqualTo(target);
assertThat(targetMethod.getName()).isEqualTo("checkForUpdates"); assertThat(targetMethod.getName()).isEqualTo("checkForUpdates");
assertThat(task.getInterval()).isEqualTo(5000L); assertThat(task.getInterval()).isEqualTo(5_000L);
assertThat(task.getInitialDelay()).isEqualTo(1000L); assertThat(task.getInitialDelay()).isEqualTo(1_000L);
} }
@Test @Test
@ -517,12 +517,12 @@ class ScheduledAnnotationBeanPostProcessorTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"PropertyPlaceholderWithFixedDelay, 5000, 1000, 5000, 1000", PropertyPlaceholderWithFixedDelay, 5000, 1000, 5_000, 1_000
"PropertyPlaceholderWithFixedDelay, PT5S, PT1S, 5000, 1000", PropertyPlaceholderWithFixedDelay, PT5S, PT1S, 5_000, 1_000
"PropertyPlaceholderWithFixedDelayInSeconds, 5000, 1000, 5000000, 1000000", PropertyPlaceholderWithFixedDelayInSeconds, 5000, 1000, 5_000_000, 1_000_000
"PropertyPlaceholderWithFixedDelayInSeconds, PT5S, PT1S, 5000, 1000" PropertyPlaceholderWithFixedDelayInSeconds, PT5S, PT1S, 5_000, 1_000
}) """)
void propertyPlaceholderWithFixedDelay(@NameToClass Class<?> beanClass, String fixedDelay, String initialDelay, void propertyPlaceholderWithFixedDelay(@NameToClass Class<?> beanClass, String fixedDelay, String initialDelay,
long expectedInterval, long expectedInitialDelay) { long expectedInterval, long expectedInitialDelay) {
@ -561,12 +561,12 @@ class ScheduledAnnotationBeanPostProcessorTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"PropertyPlaceholderWithFixedRate, 3000, 1000, 3000, 1000", PropertyPlaceholderWithFixedRate, 3000, 1000, 3_000, 1_000
"PropertyPlaceholderWithFixedRate, PT3S, PT1S, 3000, 1000", PropertyPlaceholderWithFixedRate, PT3S, PT1S, 3_000, 1_000
"PropertyPlaceholderWithFixedRateInSeconds, 3000, 1000, 3000000, 1000000", PropertyPlaceholderWithFixedRateInSeconds, 3000, 1000, 3_000_000, 1_000_000
"PropertyPlaceholderWithFixedRateInSeconds, PT3S, PT1S, 3000, 1000" PropertyPlaceholderWithFixedRateInSeconds, PT3S, PT1S, 3_000, 1_000
}) """)
void propertyPlaceholderWithFixedRate(@NameToClass Class<?> beanClass, String fixedRate, String initialDelay, void propertyPlaceholderWithFixedRate(@NameToClass Class<?> beanClass, String fixedRate, String initialDelay,
long expectedInterval, long expectedInitialDelay) { long expectedInterval, long expectedInitialDelay) {
@ -728,7 +728,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class FixedDelay { static class FixedDelay {
@Scheduled(fixedDelay = 5000) @Scheduled(fixedDelay = 5_000)
void fixedDelay() { void fixedDelay() {
} }
} }
@ -750,7 +750,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class FixedRate { static class FixedRate {
@Scheduled(fixedRate = 3000) @Scheduled(fixedRate = 3_000)
void fixedRate() { void fixedRate() {
} }
} }
@ -772,7 +772,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class FixedRateWithInitialDelay { static class FixedRateWithInitialDelay {
@Scheduled(fixedRate = 3000, initialDelay = 1000) @Scheduled(fixedRate = 3_000, initialDelay = 1_000)
void fixedRate() { void fixedRate() {
} }
} }
@ -794,7 +794,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class SeveralFixedRatesWithSchedulesContainerAnnotationTestBean { static class SeveralFixedRatesWithSchedulesContainerAnnotationTestBean {
@Schedules({@Scheduled(fixedRate = 4000), @Scheduled(fixedRate = 4000, initialDelay = 2000)}) @Schedules({@Scheduled(fixedRate = 4_000), @Scheduled(fixedRate = 4_000, initialDelay = 2_000)})
void fixedRate() { void fixedRate() {
} }
} }
@ -802,8 +802,8 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean { static class SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean {
@Scheduled(fixedRate = 4000) @Scheduled(fixedRate = 4_000)
@Scheduled(fixedRate = 4000, initialDelay = 2000) @Scheduled(fixedRate = 4_000, initialDelay = 2_000)
void fixedRate() { void fixedRate() {
} }
@ -819,8 +819,8 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class FixedRatesBaseBean { static class FixedRatesBaseBean {
@Scheduled(fixedRate = 4000) @Scheduled(fixedRate = 4_000)
@Scheduled(fixedRate = 4000, initialDelay = 2000) @Scheduled(fixedRate = 4_000, initialDelay = 2_000)
void fixedRate() { void fixedRate() {
} }
} }
@ -832,8 +832,8 @@ class ScheduledAnnotationBeanPostProcessorTests {
interface FixedRatesDefaultMethod { interface FixedRatesDefaultMethod {
@Scheduled(fixedRate = 4000) @Scheduled(fixedRate = 4_000)
@Scheduled(fixedRate = 4000, initialDelay = 2000) @Scheduled(fixedRate = 4_000, initialDelay = 2_000)
default void fixedRate() { default void fixedRate() {
} }
} }
@ -916,13 +916,13 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class NonEmptyParamListTestBean { static class NonEmptyParamListTestBean {
@Scheduled(fixedRate = 3000) @Scheduled(fixedRate = 3_000)
void invalid(String oops) { void invalid(String oops) {
} }
} }
@Scheduled(fixedRate = 5000) @Scheduled(fixedRate = 5_000)
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
private @interface EveryFiveSeconds { private @interface EveryFiveSeconds {
@ -934,7 +934,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
private @interface Hourly { private @interface Hourly {
} }
@Scheduled(initialDelay = 1000) @Scheduled(initialDelay = 1_000)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
private @interface WaitASec { private @interface WaitASec {
@ -956,7 +956,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
static class ComposedAnnotationFixedRateTestBean { static class ComposedAnnotationFixedRateTestBean {
@WaitASec(fixedRate = 5000) @WaitASec(fixedRate = 5_000)
void checkForUpdates() { void checkForUpdates() {
} }
} }

36
spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java

@ -155,24 +155,24 @@ class ClassUtilsTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"boolean, boolean", boolean, boolean
"byte, byte", byte, byte
"char, char", char, char
"short, short", short, short
"int, int", int, int
"long, long", long, long
"float, float", float, float
"double, double", double, double
"[Z, boolean[]", [Z, boolean[]
"[B, byte[]", [B, byte[]
"[C, char[]", [C, char[]
"[S, short[]", [S, short[]
"[I, int[]", [I, int[]
"[J, long[]", [J, long[]
"[F, float[]", [F, float[]
"[D, double[]" [D, double[]
}) """)
void resolvePrimitiveClassName(String input, Class<?> output) { void resolvePrimitiveClassName(String input, Class<?> output) {
assertThat(ClassUtils.resolvePrimitiveClassName(input)).isEqualTo(output); assertThat(ClassUtils.resolvePrimitiveClassName(input)).isEqualTo(output);
} }

10
spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java

@ -37,11 +37,11 @@ class IntegerToEnumConverterFactoryTests {
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource(textBlock = """
"0, RED", 0, RED
"1, BLUE", 1, BLUE
"2, GREEN" 2, GREEN
}) """)
void convertsIntegerToEnum(int index, Color color) { void convertsIntegerToEnum(int index, Color color) {
assertThat(converter.convert(index)).isEqualTo(color); assertThat(converter.convert(index)).isEqualTo(color);
} }

32
spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java

@ -48,28 +48,28 @@ class SockJsUrlInfoTests {
} }
@ParameterizedTest @ParameterizedTest
@CsvSource( { @CsvSource(textBlock = """
"http, http", http, http
"https, https", https, https
"ws, http", ws, http
"wss, https", wss, https
}) """)
void infoUrl(String scheme, String expectedScheme) throws Exception { void infoUrl(String scheme, String expectedScheme) throws Exception {
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info")); assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info"));
} }
@ParameterizedTest @ParameterizedTest
@CsvSource( { @CsvSource(textBlock = """
"http, http, XHR_STREAMING", http, http, XHR_STREAMING
"http, ws, WEBSOCKET", http, ws, WEBSOCKET
"https, https, XHR_STREAMING", https, https, XHR_STREAMING
"https, wss, WEBSOCKET", https, wss, WEBSOCKET
"ws, http, XHR_STREAMING", ws, http, XHR_STREAMING
"ws, ws, WEBSOCKET", ws, ws, WEBSOCKET
"wss, https, XHR_STREAMING", wss, https, XHR_STREAMING
"wss, wss, WEBSOCKET" wss, wss, WEBSOCKET
}) """)
void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception {
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
String serverId = info.getServerId(); String serverId = info.getServerId();

Loading…
Cancel
Save