From c462fe30ede2ee7e8d41c1a19596aaec19b3750a Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 16 Mar 2022 14:45:47 +0100 Subject: [PATCH] Use Named arguments in parameterized tests --- .../core/io/buffer/DataBufferTests.java | 78 ++++++++-------- .../core/io/buffer/DataBufferUtilsTests.java | 92 +++++++++---------- .../support/DataBufferTestUtilsTests.java | 6 +- .../AbstractDataBufferAllocatingTests.java | 27 +++--- .../reactive/MockServerHttpRequestTests.java | 30 +++--- .../test/context/BootstrapUtilsTests.java | 7 +- ...mlContextLoaderResourceLocationsTests.java | 35 +++---- .../reactive/ClientHttpConnectorTests.java | 16 ++-- ...ServerSentEventHttpMessageWriterTests.java | 18 ++-- .../DefaultPartHttpMessageReaderTests.java | 51 +++++----- .../server/reactive/HeadersAdaptersTests.java | 33 +++---- ...ltResponseErrorHandlerHttpStatusTests.java | 53 ++++++----- .../client/RestTemplateIntegrationTests.java | 14 +-- .../UrlBasedCorsConfigurationSourceTests.java | 66 ++++++------- .../AbstractHttpHandlerIntegrationTests.java | 15 +-- .../WebClientDataBufferAllocatingTests.java | 20 ++-- .../client/WebClientIntegrationTests.java | 11 ++- .../annotation/SseIntegrationTests.java | 61 ++++++------ .../servlet/handler/HandlerMappingTests.java | 16 +--- .../handler/MappedInterceptorTests.java | 5 +- .../PathPatternsParameterizedTest.java | 9 +- .../handler/PathPatternsTestUtils.java | 18 ++-- .../mvc/UrlFilenameViewControllerTests.java | 5 +- .../mvc/WebContentInterceptorTests.java | 5 +- ...HandlerMethodAnnotationDetectionTests.java | 51 +++++----- ...faultRequestToViewNameTranslatorTests.java | 28 +++--- .../AbstractWebSocketIntegrationTests.java | 11 ++- src/checkstyle/checkstyle-suppressions.xml | 1 + 28 files changed, 416 insertions(+), 366 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java index 619b9ce037f1..2d6b7e02aec5 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -35,7 +35,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest - void byteCountsAndPositions(String displayName, DataBufferFactory bufferFactory) { + void byteCountsAndPositions(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(2); @@ -78,7 +78,7 @@ void byteCountsAndPositions(String displayName, DataBufferFactory bufferFactory) } @ParameterizedDataBufferAllocatingTest - void readPositionSmallerThanZero(String displayName, DataBufferFactory bufferFactory) { + void readPositionSmallerThanZero(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -92,7 +92,7 @@ void readPositionSmallerThanZero(String displayName, DataBufferFactory bufferFac } @ParameterizedDataBufferAllocatingTest - void readPositionGreaterThanWritePosition(String displayName, DataBufferFactory bufferFactory) { + void readPositionGreaterThanWritePosition(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -106,7 +106,7 @@ void readPositionGreaterThanWritePosition(String displayName, DataBufferFactory } @ParameterizedDataBufferAllocatingTest - void writePositionSmallerThanReadPosition(String displayName, DataBufferFactory bufferFactory) { + void writePositionSmallerThanReadPosition(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(2); @@ -122,7 +122,7 @@ void writePositionSmallerThanReadPosition(String displayName, DataBufferFactory } @ParameterizedDataBufferAllocatingTest - void writePositionGreaterThanCapacity(String displayName, DataBufferFactory bufferFactory) { + void writePositionGreaterThanCapacity(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -136,7 +136,7 @@ void writePositionGreaterThanCapacity(String displayName, DataBufferFactory buff } @ParameterizedDataBufferAllocatingTest - void writeAndRead(String displayName, DataBufferFactory bufferFactory) { + void writeAndRead(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(5); @@ -157,7 +157,7 @@ void writeAndRead(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeNullString(String displayName, DataBufferFactory bufferFactory) { + void writeNullString(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -171,7 +171,7 @@ void writeNullString(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeNullCharset(String displayName, DataBufferFactory bufferFactory) { + void writeNullCharset(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -185,7 +185,7 @@ void writeNullCharset(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeEmptyString(String displayName, DataBufferFactory bufferFactory) { + void writeEmptyString(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -197,7 +197,7 @@ void writeEmptyString(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeUtf8String(String displayName, DataBufferFactory bufferFactory) { + void writeUtf8String(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(6); @@ -211,7 +211,7 @@ void writeUtf8String(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeUtf8StringOutGrowsCapacity(String displayName, DataBufferFactory bufferFactory) { + void writeUtf8StringOutGrowsCapacity(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(5); @@ -225,7 +225,7 @@ void writeUtf8StringOutGrowsCapacity(String displayName, DataBufferFactory buffe } @ParameterizedDataBufferAllocatingTest - void writeIsoString(String displayName, DataBufferFactory bufferFactory) { + void writeIsoString(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -239,7 +239,7 @@ void writeIsoString(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeMultipleUtf8String(String displayName, DataBufferFactory bufferFactory) { + void writeMultipleUtf8String(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -261,7 +261,7 @@ void writeMultipleUtf8String(String displayName, DataBufferFactory bufferFactory } @ParameterizedDataBufferAllocatingTest - void toStringNullCharset(String displayName, DataBufferFactory bufferFactory) { + void toStringNullCharset(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -275,7 +275,7 @@ void toStringNullCharset(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void toStringUtf8(String displayName, DataBufferFactory bufferFactory) { + void toStringUtf8(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; String spring = "Spring"; @@ -290,7 +290,7 @@ void toStringUtf8(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void toStringSection(String displayName, DataBufferFactory bufferFactory) { + void toStringSection(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; String spring = "Spring"; @@ -305,7 +305,7 @@ void toStringSection(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void inputStream(String displayName, DataBufferFactory bufferFactory) throws Exception { + void inputStream(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(4); @@ -339,7 +339,7 @@ void inputStream(String displayName, DataBufferFactory bufferFactory) throws Exc } @ParameterizedDataBufferAllocatingTest - void inputStreamReleaseOnClose(String displayName, DataBufferFactory bufferFactory) throws Exception { + void inputStreamReleaseOnClose(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -357,7 +357,7 @@ void inputStreamReleaseOnClose(String displayName, DataBufferFactory bufferFacto } @ParameterizedDataBufferAllocatingTest - void outputStream(String displayName, DataBufferFactory bufferFactory) throws Exception { + void outputStream(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(4); @@ -377,7 +377,7 @@ void outputStream(String displayName, DataBufferFactory bufferFactory) throws Ex } @ParameterizedDataBufferAllocatingTest - void expand(String displayName, DataBufferFactory bufferFactory) { + void expand(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -391,7 +391,7 @@ void expand(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void increaseCapacity(String displayName, DataBufferFactory bufferFactory) { + void increaseCapacity(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -404,7 +404,7 @@ void increaseCapacity(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void decreaseCapacityLowReadPosition(String displayName, DataBufferFactory bufferFactory) { + void decreaseCapacityLowReadPosition(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(2); @@ -416,7 +416,7 @@ void decreaseCapacityLowReadPosition(String displayName, DataBufferFactory buffe } @ParameterizedDataBufferAllocatingTest - void decreaseCapacityHighReadPosition(String displayName, DataBufferFactory bufferFactory) { + void decreaseCapacityHighReadPosition(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(2); @@ -429,7 +429,7 @@ void decreaseCapacityHighReadPosition(String displayName, DataBufferFactory buff } @ParameterizedDataBufferAllocatingTest - void capacityLessThanZero(String displayName, DataBufferFactory bufferFactory) { + void capacityLessThanZero(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -443,7 +443,7 @@ void capacityLessThanZero(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeByteBuffer(String displayName, DataBufferFactory bufferFactory) { + void writeByteBuffer(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer1 = createDataBuffer(1); @@ -472,7 +472,7 @@ private ByteBuffer createByteBuffer(int capacity) { } @ParameterizedDataBufferAllocatingTest - void writeDataBuffer(String displayName, DataBufferFactory bufferFactory) { + void writeDataBuffer(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer1 = createDataBuffer(1); @@ -495,7 +495,7 @@ void writeDataBuffer(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void asByteBuffer(String displayName, DataBufferFactory bufferFactory) { + void asByteBuffer(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(4); @@ -516,7 +516,7 @@ void asByteBuffer(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void asByteBufferIndexLength(String displayName, DataBufferFactory bufferFactory) { + void asByteBufferIndexLength(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -536,7 +536,7 @@ void asByteBufferIndexLength(String displayName, DataBufferFactory bufferFactory } @ParameterizedDataBufferAllocatingTest - void byteBufferContainsDataBufferChanges(String displayName, DataBufferFactory bufferFactory) { + void byteBufferContainsDataBufferChanges(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer dataBuffer = createDataBuffer(1); @@ -552,7 +552,7 @@ void byteBufferContainsDataBufferChanges(String displayName, DataBufferFactory b } @ParameterizedDataBufferAllocatingTest - void dataBufferContainsByteBufferChanges(String displayName, DataBufferFactory bufferFactory) { + void dataBufferContainsByteBufferChanges(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer dataBuffer = createDataBuffer(1); @@ -568,7 +568,7 @@ void dataBufferContainsByteBufferChanges(String displayName, DataBufferFactory b } @ParameterizedDataBufferAllocatingTest - void emptyAsByteBuffer(String displayName, DataBufferFactory bufferFactory) { + void emptyAsByteBuffer(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(1); @@ -580,7 +580,7 @@ void emptyAsByteBuffer(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void indexOf(String displayName, DataBufferFactory bufferFactory) { + void indexOf(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -602,7 +602,7 @@ void indexOf(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void lastIndexOf(String displayName, DataBufferFactory bufferFactory) { + void lastIndexOf(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -633,7 +633,7 @@ void lastIndexOf(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void slice(String displayName, DataBufferFactory bufferFactory) { + void slice(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -662,7 +662,7 @@ void slice(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void retainedSlice(String displayName, DataBufferFactory bufferFactory) { + void retainedSlice(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(3); @@ -691,7 +691,7 @@ void retainedSlice(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void spr16351(String displayName, DataBufferFactory bufferFactory) { + void spr16351(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = createDataBuffer(6); @@ -711,7 +711,7 @@ void spr16351(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void join(String displayName, DataBufferFactory bufferFactory) { + void join(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer composite = this.bufferFactory.join(Arrays.asList(stringBuffer("a"), @@ -726,7 +726,7 @@ void join(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void getByte(String displayName, DataBufferFactory bufferFactory) { + void getByte(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer buffer = stringBuffer("abc"); diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java index d20247862395..fb1b9c8700f6 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -76,7 +76,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest - void readInputStream(String displayName, DataBufferFactory bufferFactory) { + void readInputStream(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux flux = DataBufferUtils.readInputStream( @@ -86,7 +86,7 @@ void readInputStream(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void readByteChannel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readByteChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; URI uri = this.resource.getURI(); @@ -98,7 +98,7 @@ void readByteChannel(String displayName, DataBufferFactory bufferFactory) throws } @ParameterizedDataBufferAllocatingTest - void readByteChannelError(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readByteChannelError(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; ReadableByteChannel channel = mock(ReadableByteChannel.class); @@ -121,7 +121,7 @@ void readByteChannelError(String displayName, DataBufferFactory bufferFactory) t } @ParameterizedDataBufferAllocatingTest - void readByteChannelCancel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readByteChannelCancel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; URI uri = this.resource.getURI(); @@ -136,7 +136,7 @@ void readByteChannelCancel(String displayName, DataBufferFactory bufferFactory) } @ParameterizedDataBufferAllocatingTest - void readAsynchronousFileChannel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAsynchronousFileChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; URI uri = this.resource.getURI(); @@ -148,7 +148,7 @@ void readAsynchronousFileChannel(String displayName, DataBufferFactory bufferFac } @ParameterizedDataBufferAllocatingTest - void readAsynchronousFileChannelPosition(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAsynchronousFileChannelPosition(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; URI uri = this.resource.getURI(); @@ -163,7 +163,7 @@ void readAsynchronousFileChannelPosition(String displayName, DataBufferFactory b } @ParameterizedDataBufferAllocatingTest - void readAsynchronousFileChannelError(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAsynchronousFileChannelError(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; AsynchronousFileChannel channel = mock(AsynchronousFileChannel.class); @@ -195,7 +195,7 @@ void readAsynchronousFileChannelError(String displayName, DataBufferFactory buff } @ParameterizedDataBufferAllocatingTest - void readAsynchronousFileChannelCancel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAsynchronousFileChannelCancel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; URI uri = this.resource.getURI(); @@ -210,7 +210,7 @@ void readAsynchronousFileChannelCancel(String displayName, DataBufferFactory buf } @ParameterizedDataBufferAllocatingTest // gh-22107 - void readAsynchronousFileChannelCancelWithoutDemand(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAsynchronousFileChannelCancelWithoutDemand(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; URI uri = this.resource.getURI(); @@ -224,7 +224,7 @@ void readAsynchronousFileChannelCancelWithoutDemand(String displayName, DataBuff } @ParameterizedDataBufferAllocatingTest - void readPath(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readPath(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Flux flux = DataBufferUtils.read(this.resource.getFile().toPath(), super.bufferFactory, 3); @@ -233,7 +233,7 @@ void readPath(String displayName, DataBufferFactory bufferFactory) throws Except } @ParameterizedDataBufferAllocatingTest - void readResource(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readResource(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Flux flux = DataBufferUtils.read(this.resource, super.bufferFactory, 3); @@ -242,7 +242,7 @@ void readResource(String displayName, DataBufferFactory bufferFactory) throws Ex } @ParameterizedDataBufferAllocatingTest - void readResourcePosition(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readResourcePosition(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Flux flux = DataBufferUtils.read(this.resource, 9, super.bufferFactory, 3); @@ -264,7 +264,7 @@ private void verifyReadData(Flux buffers) { } @ParameterizedDataBufferAllocatingTest - void readResourcePositionAndTakeUntil(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readResourcePositionAndTakeUntil(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Resource resource = new ClassPathResource("DataBufferUtilsTests.txt", getClass()); @@ -281,7 +281,7 @@ void readResourcePositionAndTakeUntil(String displayName, DataBufferFactory buff } @ParameterizedDataBufferAllocatingTest - void readByteArrayResourcePositionAndTakeUntil(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readByteArrayResourcePositionAndTakeUntil(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Resource resource = new ByteArrayResource("foobarbazqux" .getBytes()); @@ -298,7 +298,7 @@ void readByteArrayResourcePositionAndTakeUntil(String displayName, DataBufferFac } @ParameterizedDataBufferAllocatingTest - void writeOutputStream(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeOutputStream(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -315,7 +315,7 @@ void writeOutputStream(String displayName, DataBufferFactory bufferFactory) thro } @ParameterizedDataBufferAllocatingTest - void writeWritableByteChannel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeWritableByteChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -332,7 +332,7 @@ void writeWritableByteChannel(String displayName, DataBufferFactory bufferFactor } @ParameterizedDataBufferAllocatingTest - void writeWritableByteChannelErrorInFlux(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeWritableByteChannelErrorInFlux(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -355,7 +355,7 @@ void writeWritableByteChannelErrorInFlux(String displayName, DataBufferFactory b } @ParameterizedDataBufferAllocatingTest - void writeWritableByteChannelErrorInWrite(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeWritableByteChannelErrorInWrite(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -383,7 +383,7 @@ void writeWritableByteChannelErrorInWrite(String displayName, DataBufferFactory } @ParameterizedDataBufferAllocatingTest - void writeWritableByteChannelCancel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeWritableByteChannelCancel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -407,7 +407,7 @@ void writeWritableByteChannelCancel(String displayName, DataBufferFactory buffer } @ParameterizedDataBufferAllocatingTest - void writeAsynchronousFileChannel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeAsynchronousFileChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -439,7 +439,7 @@ private void verifyWrittenData(Flux writeResult) throws IOException } @ParameterizedDataBufferAllocatingTest - void writeAsynchronousFileChannelErrorInFlux(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeAsynchronousFileChannelErrorInFlux(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -465,7 +465,7 @@ void writeAsynchronousFileChannelErrorInFlux(String displayName, DataBufferFacto @ParameterizedDataBufferAllocatingTest @SuppressWarnings("unchecked") - void writeAsynchronousFileChannelErrorInWrite(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeAsynchronousFileChannelErrorInWrite(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -506,7 +506,7 @@ void writeAsynchronousFileChannelErrorInWrite(String displayName, DataBufferFact } @ParameterizedDataBufferAllocatingTest - void writeAsynchronousFileChannelCanceled(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writeAsynchronousFileChannelCanceled(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -531,7 +531,7 @@ void writeAsynchronousFileChannelCanceled(String displayName, DataBufferFactory } @ParameterizedDataBufferAllocatingTest - void writePath(String displayName, DataBufferFactory bufferFactory) throws Exception { + void writePath(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -548,7 +548,7 @@ void writePath(String displayName, DataBufferFactory bufferFactory) throws Excep } @ParameterizedDataBufferAllocatingTest - void readAndWriteByteChannel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAndWriteByteChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Path source = Paths.get( @@ -582,7 +582,7 @@ void readAndWriteByteChannel(String displayName, DataBufferFactory bufferFactory } @ParameterizedDataBufferAllocatingTest - void readAndWriteAsynchronousFileChannel(String displayName, DataBufferFactory bufferFactory) throws Exception { + void readAndWriteAsynchronousFileChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; Path source = Paths.get( @@ -623,7 +623,7 @@ void readAndWriteAsynchronousFileChannel(String displayName, DataBufferFactory b } @ParameterizedDataBufferAllocatingTest - void takeUntilByteCount(String displayName, DataBufferFactory bufferFactory) { + void takeUntilByteCount(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux result = DataBufferUtils.takeUntilByteCount( @@ -637,7 +637,7 @@ void takeUntilByteCount(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void takeUntilByteCountCanceled(String displayName, DataBufferFactory bufferFactory) { + void takeUntilByteCountCanceled(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux source = Flux.concat( @@ -654,7 +654,7 @@ void takeUntilByteCountCanceled(String displayName, DataBufferFactory bufferFact } @ParameterizedDataBufferAllocatingTest - void takeUntilByteCountError(String displayName, DataBufferFactory bufferFactory) { + void takeUntilByteCountError(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux source = Flux.concat( @@ -671,7 +671,7 @@ void takeUntilByteCountError(String displayName, DataBufferFactory bufferFactory } @ParameterizedDataBufferAllocatingTest - void takeUntilByteCountExact(String displayName, DataBufferFactory bufferFactory) { + void takeUntilByteCountExact(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux source = Flux.concat( @@ -690,7 +690,7 @@ void takeUntilByteCountExact(String displayName, DataBufferFactory bufferFactory } @ParameterizedDataBufferAllocatingTest - void skipUntilByteCount(String displayName, DataBufferFactory bufferFactory) { + void skipUntilByteCount(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux source = Flux.concat( @@ -708,7 +708,7 @@ void skipUntilByteCount(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void skipUntilByteCountCancelled(String displayName, DataBufferFactory bufferFactory) { + void skipUntilByteCountCancelled(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux source = Flux.concat( @@ -724,7 +724,7 @@ void skipUntilByteCountCancelled(String displayName, DataBufferFactory bufferFac } @ParameterizedDataBufferAllocatingTest - void skipUntilByteCountErrorInFlux(String displayName, DataBufferFactory bufferFactory) { + void skipUntilByteCountErrorInFlux(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -738,7 +738,7 @@ void skipUntilByteCountErrorInFlux(String displayName, DataBufferFactory bufferF } @ParameterizedDataBufferAllocatingTest - void skipUntilByteCountShouldSkipAll(String displayName, DataBufferFactory bufferFactory) { + void skipUntilByteCountShouldSkipAll(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -753,7 +753,7 @@ void skipUntilByteCountShouldSkipAll(String displayName, DataBufferFactory buffe } @ParameterizedDataBufferAllocatingTest - void releaseConsumer(String displayName, DataBufferFactory bufferFactory) { + void releaseConsumer(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -776,7 +776,7 @@ private static void assertReleased(DataBuffer dataBuffer) { } @ParameterizedDataBufferAllocatingTest - void SPR16070(String displayName, DataBufferFactory bufferFactory) throws Exception { + void SPR16070(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; ReadableByteChannel channel = mock(ReadableByteChannel.class); @@ -807,7 +807,7 @@ private Answer putByte(int b) { } @ParameterizedDataBufferAllocatingTest - void join(String displayName, DataBufferFactory bufferFactory) { + void join(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -825,7 +825,7 @@ void join(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void joinWithLimit(String displayName, DataBufferFactory bufferFactory) { + void joinWithLimit(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -855,7 +855,7 @@ void joinWithLimitDoesNotOverRelease() { } @ParameterizedDataBufferAllocatingTest - void joinErrors(String displayName, DataBufferFactory bufferFactory) { + void joinErrors(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -869,7 +869,7 @@ void joinErrors(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void joinCanceled(String displayName, DataBufferFactory bufferFactory) { + void joinCanceled(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; Flux source = Flux.concat( @@ -885,7 +885,7 @@ void joinCanceled(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void matcher(String displayName, DataBufferFactory bufferFactory) { + void matcher(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foo"); @@ -903,7 +903,7 @@ void matcher(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void matcher2(String displayName, DataBufferFactory bufferFactory) { + void matcher2(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foooobar"); @@ -923,7 +923,7 @@ void matcher2(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void matcher3(String displayName, DataBufferFactory bufferFactory) { + void matcher3(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; DataBuffer foo = stringBuffer("foooobar"); @@ -943,7 +943,7 @@ void matcher3(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void propagateContextByteChannel(String displayName, DataBufferFactory bufferFactory) throws IOException { + void propagateContextByteChannel(DataBufferFactory bufferFactory) throws IOException { Path path = Paths.get(this.resource.getURI()); try (SeekableByteChannel out = Files.newByteChannel(this.tempFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { Flux result = DataBufferUtils.read(path, bufferFactory, 1024, StandardOpenOption.READ) @@ -967,7 +967,7 @@ void propagateContextByteChannel(String displayName, DataBufferFactory bufferFac } @ParameterizedDataBufferAllocatingTest - void propagateContextAsynchronousFileChannel(String displayName, DataBufferFactory bufferFactory) throws IOException { + void propagateContextAsynchronousFileChannel(DataBufferFactory bufferFactory) throws IOException { Path path = Paths.get(this.resource.getURI()); try (AsynchronousFileChannel out = AsynchronousFileChannel.open(this.tempFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { Flux result = DataBufferUtils.read(path, bufferFactory, 1024, StandardOpenOption.READ) diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java index 96f720ffdf00..4a9a0bb69fd2 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -32,7 +32,7 @@ class DataBufferTestUtilsTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest - void dumpBytes(String displayName, DataBufferFactory bufferFactory) { + void dumpBytes(DataBufferFactory bufferFactory) { this.bufferFactory = bufferFactory; DataBuffer buffer = this.bufferFactory.allocateBuffer(4); @@ -47,7 +47,7 @@ void dumpBytes(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void dumpString(String displayName, DataBufferFactory bufferFactory) { + void dumpString(DataBufferFactory bufferFactory) { this.bufferFactory = bufferFactory; DataBuffer buffer = this.bufferFactory.allocateBuffer(4); diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java index b76d13fe2406..25d4ee978adb 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/AbstractDataBufferAllocatingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -49,6 +49,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; /** @@ -161,20 +162,20 @@ private static long getAllocations(List metrics) { @SuppressWarnings("deprecation") // PooledByteBufAllocator no longer supports tinyCacheSize. public static Stream dataBufferFactories() { return Stream.of( - arguments("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = true", - new NettyDataBufferFactory(new UnpooledByteBufAllocator(true))), - arguments("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = false", - new NettyDataBufferFactory(new UnpooledByteBufAllocator(false))), + arguments(named("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = true", + new NettyDataBufferFactory(new UnpooledByteBufAllocator(true)))), + arguments(named("NettyDataBufferFactory - UnpooledByteBufAllocator - preferDirect = false", + new NettyDataBufferFactory(new UnpooledByteBufAllocator(false)))), // 1) Disable caching for reliable leak detection, see https://github.com/netty/netty/issues/5275 // 2) maxOrder is 4 (vs default 11) but can be increased if necessary - arguments("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = true", - new NettyDataBufferFactory(new PooledByteBufAllocator(true, 1, 1, 4096, 4, 0, 0, 0, true))), - arguments("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = false", - new NettyDataBufferFactory(new PooledByteBufAllocator(false, 1, 1, 4096, 4, 0, 0, 0, true))), - arguments("DefaultDataBufferFactory - preferDirect = true", - new DefaultDataBufferFactory(true)), - arguments("DefaultDataBufferFactory - preferDirect = false", - new DefaultDataBufferFactory(false)) + arguments(named("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = true", + new NettyDataBufferFactory(new PooledByteBufAllocator(true, 1, 1, 4096, 4, 0, 0, 0, true)))), + arguments(named("NettyDataBufferFactory - PooledByteBufAllocator - preferDirect = false", + new NettyDataBufferFactory(new PooledByteBufAllocator(false, 1, 1, 4096, 4, 0, 0, 0, true)))), + arguments(named("DefaultDataBufferFactory - preferDirect = true", + new DefaultDataBufferFactory(true))), + arguments(named("DefaultDataBufferFactory - preferDirect = false", + new DefaultDataBufferFactory(false))) ); } diff --git a/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java b/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java index 1fecf99f478b..95460ac5a257 100644 --- a/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java +++ b/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -19,9 +19,9 @@ import java.util.Arrays; import java.util.stream.Stream; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -31,6 +31,8 @@ import org.springframework.web.util.UriComponentsBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.junit.jupiter.api.Named.named; /** * Unit tests for {@link MockServerHttpRequest}. @@ -63,21 +65,23 @@ void queryParams() { assertThat(request.getURI().toString()).isEqualTo("/foo%20bar?a=b&name%20A=value%20A1&name%20A=value%20A2&name%20B=value%20B1"); } - @ParameterizedTest + @ParameterizedTest(name = "[{index}] {0}") @MethodSource - void httpMethodNotNullOrEmpty(Executable executable) { - Exception ex = Assertions.assertThrows(IllegalArgumentException.class, executable); - assertThat(ex.getMessage()).contains("HTTP method is required."); + void httpMethodNotNullOrEmpty(ThrowingCallable callable) { + assertThatIllegalArgumentException() + .isThrownBy(callable) + .withMessageContaining("HTTP method is required."); } - static Stream httpMethodNotNullOrEmpty() { + static Stream> httpMethodNotNullOrEmpty() { String uriTemplate = "/foo bar?a=b"; return Stream.of( - () -> MockServerHttpRequest.method(null, UriComponentsBuilder.fromUriString(uriTemplate).build("")).build(), - () -> MockServerHttpRequest.method((HttpMethod) null, uriTemplate).build(), - () -> MockServerHttpRequest.method((String) null, uriTemplate).build(), - () -> MockServerHttpRequest.method("", uriTemplate).build(), - () -> MockServerHttpRequest.method(" ", uriTemplate).build() + named("null HttpMethod, URI", () -> MockServerHttpRequest.method(null, UriComponentsBuilder.fromUriString(uriTemplate).build("")).build()), + named("null HttpMethod, uriTemplate", () -> MockServerHttpRequest.method((HttpMethod) null, uriTemplate).build()), + named("null String, uriTemplate", () -> MockServerHttpRequest.method((String) null, uriTemplate).build()), + named("empty String, uriTemplate", () -> MockServerHttpRequest.method("", uriTemplate).build()), + named("blank String, uriTemplate", () -> MockServerHttpRequest.method(" ", uriTemplate).build()) ); } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java index 5c409d880449..14d45f1b3b30 100644 --- a/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java @@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; +import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.Mockito.mock; import static org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper; @@ -104,9 +105,9 @@ void resolveTestContextBootstrapperWithDuplicatingMetaBootstrapWithAnnotations() /** * @since 5.3 */ - @ParameterizedTest(name = "{0}") + @ParameterizedTest(name = "[{index}] {0}") @MethodSource - void resolveTestContextBootstrapperInEnclosingClassHierarchy(String name, Class testClass, Class expectedBootstrapper) { + void resolveTestContextBootstrapperInEnclosingClassHierarchy(Class testClass, Class expectedBootstrapper) { assertBootstrapper(testClass, expectedBootstrapper); } @@ -129,7 +130,7 @@ static Stream resolveTestContextBootstrapperInEnclosingClassHierarchy } private static Arguments args(Class testClass, Class expectedBootstrapper) { - return arguments(testClass.getSimpleName(), testClass, expectedBootstrapper); + return arguments(named(testClass.getSimpleName(), testClass), expectedBootstrapper); } /** diff --git a/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java index 5a4cf5ec56c8..f94735e3fe57 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -27,10 +27,10 @@ import org.springframework.core.annotation.AnnotationUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextLoader; -import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; /** @@ -53,13 +53,11 @@ class GenericXmlContextLoaderResourceLocationsTests { @ParameterizedTest(name = "[{index}] {0}") @MethodSource("contextConfigurationLocationsData") - void assertContextConfigurationLocations(String testClassName, String[] expectedLocations) throws Exception { - Class testClass = ClassUtils.forName(getClass().getName() + "$" + testClassName, getClass().getClassLoader()); - - final ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class); - final ContextLoader contextLoader = new GenericXmlContextLoader(); - final String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig); - final String[] processedLocations = contextLoader.processLocations(testClass, configuredLocations); + void assertContextConfigurationLocations(Class testClass, String[] expectedLocations) throws Exception { + ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class); + ContextLoader contextLoader = new GenericXmlContextLoader(); + String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig); + String[] processedLocations = contextLoader.processLocations(testClass, configuredLocations); if (logger.isDebugEnabled()) { logger.debug("----------------------------------------------------------------------"); @@ -73,29 +71,32 @@ void assertContextConfigurationLocations(String testClassName, String[] expected static Stream contextConfigurationLocationsData() { return Stream.of( - arguments(ClasspathNonExistentDefaultLocationsTestCase.class.getSimpleName(), array()), + args(ClasspathNonExistentDefaultLocationsTestCase.class, array()), - arguments(ClasspathExistentDefaultLocationsTestCase.class.getSimpleName(), array( + args(ClasspathExistentDefaultLocationsTestCase.class, array( "classpath:org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests$ClasspathExistentDefaultLocationsTestCase-context.xml")), - arguments(ImplicitClasspathLocationsTestCase.class.getSimpleName(), + args(ImplicitClasspathLocationsTestCase.class, array("classpath:/org/springframework/test/context/support/context1.xml", "classpath:/org/springframework/test/context/support/context2.xml")), - arguments(ExplicitClasspathLocationsTestCase.class.getSimpleName(), array("classpath:context.xml")), + args(ExplicitClasspathLocationsTestCase.class, array("classpath:context.xml")), - arguments(ExplicitFileLocationsTestCase.class.getSimpleName(), - array("file:/testing/directory/context.xml")), + args(ExplicitFileLocationsTestCase.class, array("file:/testing/directory/context.xml")), - arguments(ExplicitUrlLocationsTestCase.class.getSimpleName(), array("https://example.com/context.xml")), + args(ExplicitUrlLocationsTestCase.class, array("https://example.com/context.xml")), - arguments(ExplicitMixedPathTypesLocationsTestCase.class.getSimpleName(), + args(ExplicitMixedPathTypesLocationsTestCase.class, array("classpath:/org/springframework/test/context/support/context1.xml", "classpath:context2.xml", "classpath:/context3.xml", "file:/testing/directory/context.xml", "https://example.com/context.xml")) ); } + private static Arguments args(Class testClass, String[] expectedLocations) { + return arguments(named(testClass.getSimpleName(), testClass), expectedLocations); + } + private static String[] array(String... elements) { return elements; } diff --git a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java index 0f30c2391e05..3082fe0c31fb 100644 --- a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -37,6 +37,7 @@ import okio.Buffer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Named; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -54,6 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Named.named; /** * @author Arjen Poutsma @@ -202,22 +204,22 @@ private void expectRequest(Consumer consumer) { @Target(ElementType.METHOD) // Do not auto-close arguments since HttpComponentsClientHttpConnector implements // AutoCloseable and is shared between parameterized test invocations. - @ParameterizedTest(autoCloseArguments = false) + @ParameterizedTest(name = "{0}", autoCloseArguments = false) @MethodSource("org.springframework.http.client.reactive.ClientHttpConnectorTests#connectors") public @interface ParameterizedConnectorTest { } - static List connectors() { + static List> connectors() { return Arrays.asList( - new ReactorClientHttpConnector(), - new JettyClientHttpConnector(), - new HttpComponentsClientHttpConnector() + named("Reactor Netty", new ReactorClientHttpConnector()), + named("Jetty", new JettyClientHttpConnector()), + named("HttpComponents", new HttpComponentsClientHttpConnector()) ); } static List methodsWithConnectors() { List result = new ArrayList<>(); - for (ClientHttpConnector connector : connectors()) { + for (Named connector : connectors()) { for (HttpMethod method : HttpMethod.values()) { result.add(Arguments.of(connector, method)); } diff --git a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java index aa2cd5835485..da1b820830b8 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -58,7 +58,7 @@ class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocating @ParameterizedDataBufferAllocatingTest - void canWrite(String displayName, DataBufferFactory bufferFactory) { + void canWrite(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; assertThat(this.messageWriter.canWrite(forClass(Object.class), null)).isTrue(); @@ -73,7 +73,7 @@ void canWrite(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeServerSentEvent(String displayName, DataBufferFactory bufferFactory) { + void writeServerSentEvent(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; ServerSentEvent event = ServerSentEvent.builder().data("bar").id("c42").event("foo") @@ -91,7 +91,7 @@ void writeServerSentEvent(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeString(String displayName, DataBufferFactory bufferFactory) { + void writeString(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -106,7 +106,7 @@ void writeString(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void writeMultiLineString(String displayName, DataBufferFactory bufferFactory) { + void writeMultiLineString(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -121,7 +121,7 @@ void writeMultiLineString(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest // SPR-16516 - void writeStringWithCustomCharset(String displayName, DataBufferFactory bufferFactory) { + void writeStringWithCustomCharset(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -142,7 +142,7 @@ void writeStringWithCustomCharset(String displayName, DataBufferFactory bufferFa } @ParameterizedDataBufferAllocatingTest - void writePojo(String displayName, DataBufferFactory bufferFactory) { + void writePojo(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -161,7 +161,7 @@ void writePojo(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest // SPR-14899 - void writePojoWithPrettyPrint(String displayName, DataBufferFactory bufferFactory) { + void writePojoWithPrettyPrint(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().indentOutput(true).build(); @@ -187,7 +187,7 @@ void writePojoWithPrettyPrint(String displayName, DataBufferFactory bufferFactor } @ParameterizedDataBufferAllocatingTest // SPR-16516, SPR-16539 - void writePojoWithCustomEncoding(String displayName, DataBufferFactory bufferFactory) { + void writePojoWithCustomEncoding(DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java index 9179a546820f..a35555a3d3fe 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -55,6 +55,7 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.springframework.core.ResolvableType.forClass; import static org.springframework.core.io.buffer.DataBufferUtils.release; @@ -62,7 +63,7 @@ /** * @author Arjen Poutsma */ -public class DefaultPartHttpMessageReaderTests { +class DefaultPartHttpMessageReaderTests { private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer iaculis metus id vestibulum nullam."; @@ -73,12 +74,12 @@ public class DefaultPartHttpMessageReaderTests { private static final DataBufferFactory bufferFactory = new NettyDataBufferFactory(new PooledByteBufAllocator()); @ParameterizedDefaultPartHttpMessageReaderTest - public void canRead(String displayName, DefaultPartHttpMessageReader reader) { + void canRead(DefaultPartHttpMessageReader reader) { assertThat(reader.canRead(forClass(Part.class), MediaType.MULTIPART_FORM_DATA)).isTrue(); } @ParameterizedDefaultPartHttpMessageReaderTest - public void simple(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException { + void simple(DefaultPartHttpMessageReader reader) throws InterruptedException { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); @@ -96,7 +97,7 @@ public void simple(String displayName, DefaultPartHttpMessageReader reader) thro } @ParameterizedDefaultPartHttpMessageReaderTest - public void noHeaders(String displayName, DefaultPartHttpMessageReader reader) { + void noHeaders(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("no-header.multipart", getClass()), "boundary"); Flux result = reader.read(forClass(Part.class), request, emptyMap()); @@ -110,7 +111,7 @@ public void noHeaders(String displayName, DefaultPartHttpMessageReader reader) { } @ParameterizedDefaultPartHttpMessageReaderTest - public void noEndBoundary(String displayName, DefaultPartHttpMessageReader reader) { + void noEndBoundary(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("no-end-boundary.multipart", getClass()), "boundary"); @@ -122,7 +123,7 @@ public void noEndBoundary(String displayName, DefaultPartHttpMessageReader reade } @ParameterizedDefaultPartHttpMessageReaderTest - public void garbage(String displayName, DefaultPartHttpMessageReader reader) { + void garbage(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("garbage-1.multipart", getClass()), "boundary"); @@ -134,7 +135,7 @@ public void garbage(String displayName, DefaultPartHttpMessageReader reader) { } @ParameterizedDefaultPartHttpMessageReaderTest - public void noEndHeader(String displayName, DefaultPartHttpMessageReader reader) { + void noEndHeader(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("no-end-header.multipart", getClass()), "boundary"); Flux result = reader.read(forClass(Part.class), request, emptyMap()); @@ -145,7 +146,7 @@ public void noEndHeader(String displayName, DefaultPartHttpMessageReader reader) } @ParameterizedDefaultPartHttpMessageReaderTest - public void noEndBody(String displayName, DefaultPartHttpMessageReader reader) { + void noEndBody(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("no-end-body.multipart", getClass()), "boundary"); Flux result = reader.read(forClass(Part.class), request, emptyMap()); @@ -156,7 +157,7 @@ public void noEndBody(String displayName, DefaultPartHttpMessageReader reader) { } @ParameterizedDefaultPartHttpMessageReaderTest - public void cancelPart(String displayName, DefaultPartHttpMessageReader reader) { + void cancelPart(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); Flux result = reader.read(forClass(Part.class), request, emptyMap()); @@ -168,7 +169,7 @@ public void cancelPart(String displayName, DefaultPartHttpMessageReader reader) } @ParameterizedDefaultPartHttpMessageReaderTest - public void cancelBody(String displayName, DefaultPartHttpMessageReader reader) throws Exception { + void cancelBody(DefaultPartHttpMessageReader reader) throws Exception { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); Flux result = reader.read(forClass(Part.class), request, emptyMap()); @@ -185,7 +186,7 @@ public void cancelBody(String displayName, DefaultPartHttpMessageReader reader) } @ParameterizedDefaultPartHttpMessageReaderTest - public void cancelBodyThenPart(String displayName, DefaultPartHttpMessageReader reader) { + void cancelBodyThenPart(DefaultPartHttpMessageReader reader) { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); Flux result = reader.read(forClass(Part.class), request, emptyMap()); @@ -197,25 +198,25 @@ public void cancelBodyThenPart(String displayName, DefaultPartHttpMessageReader } @ParameterizedDefaultPartHttpMessageReaderTest - public void firefox(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException { + void firefox(DefaultPartHttpMessageReader reader) throws InterruptedException { testBrowser(reader, new ClassPathResource("firefox.multipart", getClass()), "---------------------------18399284482060392383840973206"); } @ParameterizedDefaultPartHttpMessageReaderTest - public void chrome(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException { + void chrome(DefaultPartHttpMessageReader reader) throws InterruptedException { testBrowser(reader, new ClassPathResource("chrome.multipart", getClass()), "----WebKitFormBoundaryEveBLvRT65n21fwU"); } @ParameterizedDefaultPartHttpMessageReaderTest - public void safari(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException { + void safari(DefaultPartHttpMessageReader reader) throws InterruptedException { testBrowser(reader, new ClassPathResource("safari.multipart", getClass()), "----WebKitFormBoundaryG8fJ50opQOML0oGD"); } @Test - public void tooManyParts() throws InterruptedException { + void tooManyParts() throws InterruptedException { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "simple-boundary"); @@ -235,7 +236,7 @@ public void tooManyParts() throws InterruptedException { } @ParameterizedDefaultPartHttpMessageReaderTest - public void quotedBoundary(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException { + void quotedBoundary(DefaultPartHttpMessageReader reader) throws InterruptedException { MockServerHttpRequest request = createRequest( new ClassPathResource("simple.multipart", getClass()), "\"simple-boundary\""); @@ -253,7 +254,7 @@ public void quotedBoundary(String displayName, DefaultPartHttpMessageReader read } @ParameterizedDefaultPartHttpMessageReaderTest - public void utf8Headers(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException { + void utf8Headers(DefaultPartHttpMessageReader reader) throws InterruptedException { MockServerHttpRequest request = createRequest( new ClassPathResource("utf8.multipart", getClass()), "\"simple-boundary\""); @@ -272,7 +273,7 @@ public void utf8Headers(String displayName, DefaultPartHttpMessageReader reader) // gh-27612 @Test - public void exceedHeaderLimit() throws InterruptedException { + void exceedHeaderLimit() throws InterruptedException { Flux body = DataBufferUtils .readByteChannel((new ClassPathResource("files.multipart", getClass()))::readableChannel, bufferFactory, 282); @@ -410,10 +411,10 @@ protected void hookOnNext(DataBuffer buffer) { @Target(ElementType.METHOD) @ParameterizedTest(name = "[{index}] {0}") @MethodSource("org.springframework.http.codec.multipart.DefaultPartHttpMessageReaderTests#messageReaders()") - public @interface ParameterizedDefaultPartHttpMessageReaderTest { + @interface ParameterizedDefaultPartHttpMessageReaderTest { } - public static Stream messageReaders() { + static Stream messageReaders() { DefaultPartHttpMessageReader streaming = new DefaultPartHttpMessageReader(); streaming.setStreaming(true); @@ -426,11 +427,9 @@ public static Stream messageReaders() { onDisk.setMaxInMemorySize(100); return Stream.of( - arguments("streaming", streaming), - arguments("in-memory", inMemory), - arguments("on-disk", onDisk) - ); + arguments(named("streaming", streaming)), + arguments(named("in-memory", inMemory)), + arguments(named("on-disk", onDisk))); } - } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java index ce7e1b14fbdc..4948d776bb32 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -39,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; /** @@ -50,24 +51,24 @@ class HeadersAdaptersTests { @ParameterizedHeadersTest - void getWithUnknownHeaderShouldReturnNull(String displayName, MultiValueMap headers) { + void getWithUnknownHeaderShouldReturnNull(MultiValueMap headers) { assertThat(headers.get("Unknown")).isNull(); } @ParameterizedHeadersTest - void getFirstWithUnknownHeaderShouldReturnNull(String displayName, MultiValueMap headers) { + void getFirstWithUnknownHeaderShouldReturnNull(MultiValueMap headers) { assertThat(headers.getFirst("Unknown")).isNull(); } @ParameterizedHeadersTest - void sizeWithMultipleValuesForHeaderShouldCountHeaders(String displayName, MultiValueMap headers) { + void sizeWithMultipleValuesForHeaderShouldCountHeaders(MultiValueMap headers) { headers.add("TestHeader", "first"); headers.add("TestHeader", "second"); assertThat(headers.size()).isEqualTo(1); } @ParameterizedHeadersTest - void keySetShouldNotDuplicateHeaderNames(String displayName, MultiValueMap headers) { + void keySetShouldNotDuplicateHeaderNames(MultiValueMap headers) { headers.add("TestHeader", "first"); headers.add("OtherHeader", "test"); headers.add("TestHeader", "second"); @@ -75,13 +76,13 @@ void keySetShouldNotDuplicateHeaderNames(String displayName, MultiValueMap headers) { + void containsKeyShouldBeCaseInsensitive(MultiValueMap headers) { headers.add("TestHeader", "first"); assertThat(headers.containsKey("testheader")).isTrue(); } @ParameterizedHeadersTest - void addShouldKeepOrdering(String displayName, MultiValueMap headers) { + void addShouldKeepOrdering(MultiValueMap headers) { headers.add("TestHeader", "first"); headers.add("TestHeader", "second"); assertThat(headers.getFirst("TestHeader")).isEqualTo("first"); @@ -89,7 +90,7 @@ void addShouldKeepOrdering(String displayName, MultiValueMap hea } @ParameterizedHeadersTest - void putShouldOverrideExisting(String displayName, MultiValueMap headers) { + void putShouldOverrideExisting(MultiValueMap headers) { headers.add("TestHeader", "first"); headers.put("TestHeader", Arrays.asList("override")); assertThat(headers.getFirst("TestHeader")).isEqualTo("override"); @@ -97,7 +98,7 @@ void putShouldOverrideExisting(String displayName, MultiValueMap } @ParameterizedHeadersTest - void nullValuesShouldNotFail(String displayName, MultiValueMap headers) { + void nullValuesShouldNotFail(MultiValueMap headers) { headers.add("TestHeader", null); assertThat(headers.getFirst("TestHeader")).isNull(); headers.set("TestHeader", null); @@ -105,7 +106,7 @@ void nullValuesShouldNotFail(String displayName, MultiValueMap h } @ParameterizedHeadersTest - void shouldReflectChangesOnKeyset(String displayName, MultiValueMap headers) { + void shouldReflectChangesOnKeyset(MultiValueMap headers) { headers.add("TestHeader", "first"); assertThat(headers.keySet()).hasSize(1); headers.keySet().removeIf("TestHeader"::equals); @@ -113,7 +114,7 @@ void shouldReflectChangesOnKeyset(String displayName, MultiValueMap headers) { + void shouldFailIfHeaderRemovedFromKeyset(MultiValueMap headers) { headers.add("TestHeader", "first"); assertThat(headers.keySet()).hasSize(1); Iterator names = headers.keySet().iterator(); @@ -132,11 +133,11 @@ void shouldFailIfHeaderRemovedFromKeyset(String displayName, MultiValueMap headers() { return Stream.of( - arguments("Map", CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))), - arguments("Netty", new NettyHeadersAdapter(new DefaultHttpHeaders())), - arguments("Tomcat", new TomcatHeadersAdapter(new MimeHeaders())), - arguments("Undertow", new UndertowHeadersAdapter(new HeaderMap())), - arguments("Jetty", new JettyHeadersAdapter(new HttpFields())) + arguments(named("Map", CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH)))), + arguments(named("Netty", new NettyHeadersAdapter(new DefaultHttpHeaders()))), + arguments(named("Tomcat", new TomcatHeadersAdapter(new MimeHeaders()))), + arguments(named("Undertow", new UndertowHeadersAdapter(new HeaderMap()))), + arguments(named("Jetty", new JettyHeadersAdapter(new HttpFields()))) ); } diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java index 85c3b2eefec2..a56a39488083 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -16,8 +16,11 @@ package org.springframework.web.client; +import java.util.stream.Stream; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.http.HttpHeaders; @@ -27,6 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.jupiter.api.Named.named; +import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.springframework.http.HttpStatus.BAD_GATEWAY; @@ -65,7 +70,7 @@ void hasErrorTrue(HttpStatus httpStatus) throws Exception { assertThat(this.handler.hasError(this.response)).isTrue(); } - @ParameterizedTest(name = "[{index}] error: [{0}], exception: [{1}]") + @ParameterizedTest(name = "[{index}] error: {0}, exception: {1}") @DisplayName("handleError() throws an exception") @MethodSource("errorCodes") void handleErrorException(HttpStatus httpStatus, Class expectedExceptionClass) throws Exception { @@ -78,27 +83,33 @@ void handleErrorException(HttpStatus httpStatus, Class expe assertThatExceptionOfType(expectedExceptionClass).isThrownBy(() -> this.handler.handleError(this.response)); } - static Object[][] errorCodes() { - return new Object[][]{ + static Stream errorCodes() { + return Stream.of( // 4xx - {BAD_REQUEST, HttpClientErrorException.BadRequest.class}, - {UNAUTHORIZED, HttpClientErrorException.Unauthorized.class}, - {FORBIDDEN, HttpClientErrorException.Forbidden.class}, - {NOT_FOUND, HttpClientErrorException.NotFound.class}, - {METHOD_NOT_ALLOWED, HttpClientErrorException.MethodNotAllowed.class}, - {NOT_ACCEPTABLE, HttpClientErrorException.NotAcceptable.class}, - {CONFLICT, HttpClientErrorException.Conflict.class}, - {TOO_MANY_REQUESTS, HttpClientErrorException.TooManyRequests.class}, - {UNPROCESSABLE_ENTITY, HttpClientErrorException.UnprocessableEntity.class}, - {I_AM_A_TEAPOT, HttpClientErrorException.class}, + args(BAD_REQUEST, HttpClientErrorException.BadRequest.class), + args(UNAUTHORIZED, HttpClientErrorException.Unauthorized.class), + args(FORBIDDEN, HttpClientErrorException.Forbidden.class), + args(NOT_FOUND, HttpClientErrorException.NotFound.class), + args(METHOD_NOT_ALLOWED, HttpClientErrorException.MethodNotAllowed.class), + args(NOT_ACCEPTABLE, HttpClientErrorException.NotAcceptable.class), + args(CONFLICT, HttpClientErrorException.Conflict.class), + args(TOO_MANY_REQUESTS, HttpClientErrorException.TooManyRequests.class), + args(UNPROCESSABLE_ENTITY, HttpClientErrorException.UnprocessableEntity.class), + args(I_AM_A_TEAPOT, HttpClientErrorException.class), // 5xx - {INTERNAL_SERVER_ERROR, HttpServerErrorException.InternalServerError.class}, - {NOT_IMPLEMENTED, HttpServerErrorException.NotImplemented.class}, - {BAD_GATEWAY, HttpServerErrorException.BadGateway.class}, - {SERVICE_UNAVAILABLE, HttpServerErrorException.ServiceUnavailable.class}, - {GATEWAY_TIMEOUT, HttpServerErrorException.GatewayTimeout.class}, - {HTTP_VERSION_NOT_SUPPORTED, HttpServerErrorException.class} - }; + args(INTERNAL_SERVER_ERROR, HttpServerErrorException.InternalServerError.class), + args(NOT_IMPLEMENTED, HttpServerErrorException.NotImplemented.class), + args(BAD_GATEWAY, HttpServerErrorException.BadGateway.class), + args(SERVICE_UNAVAILABLE, HttpServerErrorException.ServiceUnavailable.class), + args(GATEWAY_TIMEOUT, HttpServerErrorException.GatewayTimeout.class), + args(HTTP_VERSION_NOT_SUPPORTED, HttpServerErrorException.class) + ); + } + + private static Arguments args(HttpStatus httpStatus, Class exceptionType) { + return arguments( + named(String.valueOf(httpStatus.value()), httpStatus), + named(exceptionType.getSimpleName(), exceptionType)); } } diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java index f53cf890c79b..9bdaeda8dfda 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonView; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; import org.junit.jupiter.params.ParameterizedTest; @@ -58,6 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Named.named; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.MediaType.MULTIPART_MIXED; @@ -88,12 +90,12 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { } @SuppressWarnings("deprecation") - static Stream clientHttpRequestFactories() { + static Stream> clientHttpRequestFactories() { return Stream.of( - new SimpleClientHttpRequestFactory(), - new HttpComponentsClientHttpRequestFactory(), - new org.springframework.http.client.Netty4ClientHttpRequestFactory(), - new OkHttp3ClientHttpRequestFactory() + named("JDK", new SimpleClientHttpRequestFactory()), + named("HttpComponents", new HttpComponentsClientHttpRequestFactory()), + named("Netty", new org.springframework.http.client.Netty4ClientHttpRequestFactory()), + named("OkHttp", new OkHttp3ClientHttpRequestFactory()) ); } diff --git a/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java b/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java index 02e6779e49be..77debe059aa5 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -23,6 +23,7 @@ import java.util.function.Function; import java.util.stream.Stream; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.junit.jupiter.api.Named.named; /** * Unit tests for {@link UrlBasedCorsConfigurationSource}. @@ -42,62 +44,35 @@ */ class UrlBasedCorsConfigurationSourceTests { - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - @ParameterizedTest - @MethodSource("pathPatternsArguments") - @interface PathPatternsParameterizedTest { - } - - @SuppressWarnings("unused") - private static Stream> pathPatternsArguments() { - return Stream.of( - requestUri -> { - MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); - ServletRequestPathUtils.parseAndCache(request); - return request; - }, - requestUri -> { - MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); - UrlPathHelper.defaultInstance.getLookupPathForRequest(request); - return request; - } - ); - } + private final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); @PathPatternsParameterizedTest void empty(Function requestFactory) { - CorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); assertThat(source.getCorsConfiguration(requestFactory.apply("/bar/test.html"))).isNull(); } @PathPatternsParameterizedTest void registerAndMatch(Function requestFactory) { CorsConfiguration config = new CorsConfiguration(); - UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); - configSource.registerCorsConfiguration("/bar/**", config); + source.registerCorsConfiguration("/bar/**", config); MockHttpServletRequest request = requestFactory.apply("/foo/test.html"); - assertThat(configSource.getCorsConfiguration(request)).isNull(); + assertThat(source.getCorsConfiguration(request)).isNull(); request = requestFactory.apply("/bar/test.html"); - assertThat(configSource.getCorsConfiguration(request)).isEqualTo(config); + assertThat(source.getCorsConfiguration(request)).isEqualTo(config); } @Test void unmodifiableConfigurationsMap() { assertThatExceptionOfType(UnsupportedOperationException.class) - .isThrownBy(() -> { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.getCorsConfigurations().put("/**", new CorsConfiguration()); - }); + .isThrownBy(() -> source.getCorsConfigurations().put("/**", new CorsConfiguration())); } @Test void allowInitLookupPath() { CorsConfiguration config = new CorsConfiguration(); - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); @@ -108,4 +83,29 @@ void allowInitLookupPath() { source.setAllowInitLookupPath(false); assertThatIllegalArgumentException().isThrownBy(() -> source.getCorsConfiguration(request)); } + + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @ParameterizedTest(name = "[{index}] {0}") + @MethodSource("pathPatternsArguments") + private @interface PathPatternsParameterizedTest { + } + + @SuppressWarnings("unused") + private static Stream>> pathPatternsArguments() { + return Stream.of( + named("ServletRequestPathUtils", requestUri -> { + MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); + ServletRequestPathUtils.parseAndCache(request); + return request; + }), + named("UrlPathHelper", requestUri -> { + MockHttpServletRequest request = new MockHttpServletRequest("GET", requestUri); + UrlPathHelper.defaultInstance.getLookupPathForRequest(request); + return request; + }) + ); + } + } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java index 90d05db9f20a..10ba25d40d16 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; import org.junit.jupiter.params.ParameterizedTest; @@ -36,6 +37,8 @@ import org.springframework.util.StringUtils; import org.springframework.web.client.HttpServerErrorException; +import static org.junit.jupiter.api.Named.named; + public abstract class AbstractHttpHandlerIntegrationTests { /** @@ -121,12 +124,12 @@ public static Flux testInterval(Duration period, int count) { public @interface ParameterizedHttpServerTest { } - static Stream httpServers() { + static Stream> httpServers() { return Stream.of( - new JettyHttpServer(), - new ReactorHttpServer(), - new TomcatHttpServer(), - new UndertowHttpServer() + named("Jetty", new JettyHttpServer()), + named("Reactor Netty", new ReactorHttpServer()), + named("Tomcat", new TomcatHttpServer()), + named("Undertow", new UndertowHttpServer()) ); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java index 33202d48f465..57357d0854ac 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -96,7 +96,7 @@ private ReactorClientHttpConnector initConnector() { @ParameterizedDataBufferAllocatingTest - void bodyToMonoVoid(String displayName, DataBufferFactory bufferFactory) { + void bodyToMonoVoid(DataBufferFactory bufferFactory) { setUp(bufferFactory); this.server.enqueue(new MockResponse() @@ -114,7 +114,7 @@ void bodyToMonoVoid(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest // SPR-17482 - void bodyToMonoVoidWithoutContentType(String displayName, DataBufferFactory bufferFactory) { + void bodyToMonoVoidWithoutContentType(DataBufferFactory bufferFactory) { setUp(bufferFactory); this.server.enqueue(new MockResponse() @@ -131,7 +131,7 @@ void bodyToMonoVoidWithoutContentType(String displayName, DataBufferFactory buff } @ParameterizedDataBufferAllocatingTest - void onStatusWithBodyNotConsumed(String displayName, DataBufferFactory bufferFactory) { + void onStatusWithBodyNotConsumed(DataBufferFactory bufferFactory) { setUp(bufferFactory); RuntimeException ex = new RuntimeException("response error"); @@ -139,7 +139,7 @@ void onStatusWithBodyNotConsumed(String displayName, DataBufferFactory bufferFac } @ParameterizedDataBufferAllocatingTest - void onStatusWithBodyConsumed(String displayName, DataBufferFactory bufferFactory) { + void onStatusWithBodyConsumed(DataBufferFactory bufferFactory) { setUp(bufferFactory); RuntimeException ex = new RuntimeException("response error"); @@ -147,7 +147,7 @@ void onStatusWithBodyConsumed(String displayName, DataBufferFactory bufferFactor } @ParameterizedDataBufferAllocatingTest // SPR-17473 - void onStatusWithMonoErrorAndBodyNotConsumed(String displayName, DataBufferFactory bufferFactory) { + void onStatusWithMonoErrorAndBodyNotConsumed(DataBufferFactory bufferFactory) { setUp(bufferFactory); RuntimeException ex = new RuntimeException("response error"); @@ -155,7 +155,7 @@ void onStatusWithMonoErrorAndBodyNotConsumed(String displayName, DataBufferFacto } @ParameterizedDataBufferAllocatingTest - void onStatusWithMonoErrorAndBodyConsumed(String displayName, DataBufferFactory bufferFactory) { + void onStatusWithMonoErrorAndBodyConsumed(DataBufferFactory bufferFactory) { setUp(bufferFactory); RuntimeException ex = new RuntimeException("response error"); @@ -163,7 +163,7 @@ void onStatusWithMonoErrorAndBodyConsumed(String displayName, DataBufferFactory } @ParameterizedDataBufferAllocatingTest // gh-23230 - void onStatusWithImmediateErrorAndBodyNotConsumed(String displayName, DataBufferFactory bufferFactory) { + void onStatusWithImmediateErrorAndBodyNotConsumed(DataBufferFactory bufferFactory) { setUp(bufferFactory); RuntimeException ex = new RuntimeException("response error"); @@ -173,7 +173,7 @@ void onStatusWithImmediateErrorAndBodyNotConsumed(String displayName, DataBuffer } @ParameterizedDataBufferAllocatingTest - void releaseBody(String displayName, DataBufferFactory bufferFactory) { + void releaseBody(DataBufferFactory bufferFactory) { setUp(bufferFactory); this.server.enqueue(new MockResponse() @@ -190,7 +190,7 @@ void releaseBody(String displayName, DataBufferFactory bufferFactory) { } @ParameterizedDataBufferAllocatingTest - void exchangeToBodilessEntity(String displayName, DataBufferFactory bufferFactory) { + void exchangeToBodilessEntity(DataBufferFactory bufferFactory) { setUp(bufferFactory); this.server.enqueue(new MockResponse() diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 4410e2102266..4a3e21645241 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -43,6 +43,7 @@ import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -89,16 +90,16 @@ class WebClientIntegrationTests { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - @ParameterizedTest(name = "[{index}] {displayName} [{0}]") + @ParameterizedTest(name = "[{index}] {0}") @MethodSource("arguments") @interface ParameterizedWebClientTest { } - static Stream arguments() { + static Stream> arguments() { return Stream.of( - new ReactorClientHttpConnector(), - new JettyClientHttpConnector(), - new HttpComponentsClientHttpConnector() + Named.named("Reactor Netty", new ReactorClientHttpConnector()), + Named.named("Jetty", new JettyClientHttpConnector()), + Named.named("HttpComponents", new HttpComponentsClientHttpConnector()) ); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 7cc9a20e0c08..4293bb486a8d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -21,9 +21,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.time.Duration; +import java.util.stream.Stream; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -56,6 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.junit.jupiter.api.Named.named; import static org.springframework.http.MediaType.TEXT_EVENT_STREAM; /** @@ -64,31 +67,6 @@ */ class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - @ParameterizedTest(name = "[{index}] server [{0}], webClient [{1}]") - @MethodSource("arguments") - protected @interface ParameterizedSseTest { - } - - static Object[][] arguments() { - return new Object[][] { - {new JettyHttpServer(), new ReactorClientHttpConnector()}, - {new JettyHttpServer(), new JettyClientHttpConnector()}, - {new JettyHttpServer(), new HttpComponentsClientHttpConnector()}, - {new ReactorHttpServer(), new ReactorClientHttpConnector()}, - {new ReactorHttpServer(), new JettyClientHttpConnector()}, - {new ReactorHttpServer(), new HttpComponentsClientHttpConnector()}, - {new TomcatHttpServer(), new ReactorClientHttpConnector()}, - {new TomcatHttpServer(), new JettyClientHttpConnector()}, - {new TomcatHttpServer(), new HttpComponentsClientHttpConnector()}, - {new UndertowHttpServer(), new ReactorClientHttpConnector()}, - {new UndertowHttpServer(), new JettyClientHttpConnector()}, - {new UndertowHttpServer(), new HttpComponentsClientHttpConnector()} - }; - } - - private AnnotationConfigApplicationContext wac; private WebClient webClient; @@ -312,4 +290,35 @@ public String toString() { } } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @ParameterizedTest(name = "[{index}] server = {0}, webClient = {1}") + @MethodSource("arguments") + private @interface ParameterizedSseTest { + } + + static Stream arguments() { + return Stream.of( + args(new JettyHttpServer(), new ReactorClientHttpConnector()), + args(new JettyHttpServer(), new JettyClientHttpConnector()), + args(new JettyHttpServer(), new HttpComponentsClientHttpConnector()), + args(new ReactorHttpServer(), new ReactorClientHttpConnector()), + args(new ReactorHttpServer(), new JettyClientHttpConnector()), + args(new ReactorHttpServer(), new HttpComponentsClientHttpConnector()), + args(new TomcatHttpServer(), new ReactorClientHttpConnector()), + args(new TomcatHttpServer(), new JettyClientHttpConnector()), + args(new TomcatHttpServer(), new HttpComponentsClientHttpConnector()), + args(new UndertowHttpServer(), new ReactorClientHttpConnector()), + args(new UndertowHttpServer(), new JettyClientHttpConnector()), + args(new UndertowHttpServer(), new HttpComponentsClientHttpConnector()) + ); + } + + private static Arguments args(HttpServer httpServer, ClientHttpConnector connector) { + return Arguments.of( + named(httpServer.getClass().getSimpleName(), httpServer), + named(connector.getClass().getSimpleName(), connector)); + } + } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingTests.java index 7273780514ec..8904339b5da3 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -16,9 +16,7 @@ package org.springframework.web.servlet.handler; -import java.util.List; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.servlet.http.HttpServletRequest; @@ -32,6 +30,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.Mockito.mock; /** @@ -44,19 +43,12 @@ class HandlerMappingTests { @SuppressWarnings("unused") private static Stream pathPatternsArguments() { - List> factories = - PathPatternsTestUtils.requestArguments().collect(Collectors.toList()); - return Stream.of( - Arguments.arguments(new TestHandlerMapping(), factories.get(0)), - Arguments.arguments(new TestHandlerMapping(), factories.get(1)) - ); + return PathPatternsTestUtils.requestArguments().map(function -> arguments(function, new TestHandlerMapping())); } @PathPatternsParameterizedTest - void orderedInterceptors( - TestHandlerMapping mapping, Function requestFactory) - throws Exception { + void orderedInterceptors(Function requestFactory, TestHandlerMapping mapping) throws Exception { MappedInterceptor i1 = new MappedInterceptor(new String[] {"/**"}, mock(HandlerInterceptor.class)); HandlerInterceptor i2 = mock(HandlerInterceptor.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java index 799969a25e8d..8221ceb66cf6 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; import org.springframework.util.PathMatcher; @@ -47,7 +48,7 @@ class MappedInterceptorTests { @SuppressWarnings("unused") - private static Stream> pathPatternsArguments() { + private static Stream>> pathPatternsArguments() { return PathPatternsTestUtils.requestArguments(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsParameterizedTest.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsParameterizedTest.java index ead6e38ab1da..81c9e88a43d1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsParameterizedTest.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsParameterizedTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -21,6 +21,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + /** * Annotation for tests parameterized to use either * {@link org.springframework.web.util.pattern.PathPatternParser} or @@ -33,7 +36,7 @@ @Target(ElementType.METHOD) // Do not auto-close arguments since ConfigurableWebApplicationContext implements // AutoCloseable and is shared between parameterized test invocations. -@org.junit.jupiter.params.ParameterizedTest(autoCloseArguments = false) -@org.junit.jupiter.params.provider.MethodSource("pathPatternsArguments") +@ParameterizedTest(name = "[{index}] {0}", autoCloseArguments = false) +@MethodSource("pathPatternsArguments") public @interface PathPatternsParameterizedTest { } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsTestUtils.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsTestUtils.java index 04291a3c9ded..9cc7d08ba4cd 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsTestUtils.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathPatternsTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -20,11 +20,15 @@ import java.util.function.Function; import java.util.stream.Stream; +import org.junit.jupiter.api.Named; + import org.springframework.lang.Nullable; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.util.ServletRequestPathUtils; import org.springframework.web.util.UrlPathHelper; +import static org.junit.jupiter.api.Named.named; + /** * Utility methods to help with parameterized tests for URL pattern matching * via pre-parsed {@code PathPattern}s or String pattern matching with @@ -35,22 +39,22 @@ */ public abstract class PathPatternsTestUtils { - public static Stream> requestArguments() { + public static Stream>> requestArguments() { return requestArguments(null); } - public static Stream> requestArguments(@Nullable String contextPath) { + public static Stream>> requestArguments(@Nullable String contextPath) { return Stream.of( - path -> { + named("ServletRequestPathUtils", path -> { MockHttpServletRequest request = createRequest("GET", contextPath, path); ServletRequestPathUtils.parseAndCache(request); return request; - }, - path -> { + }), + named("UrlPathHelper", path -> { MockHttpServletRequest request = createRequest("GET", contextPath, path); UrlPathHelper.defaultInstance.resolveAndCacheLookupPath(request); return request; - } + }) ); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/UrlFilenameViewControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/UrlFilenameViewControllerTests.java index fa103a3a3a44..a43e86e9ab58 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/UrlFilenameViewControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/UrlFilenameViewControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -19,6 +19,7 @@ import java.util.function.Function; import java.util.stream.Stream; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; import org.springframework.ui.ModelMap; @@ -42,7 +43,7 @@ class UrlFilenameViewControllerTests { @SuppressWarnings("unused") - private static Stream> pathPatternsArguments() { + private static Stream>> pathPatternsArguments() { return PathPatternsTestUtils.requestArguments(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java index 73678e8948aa..32058dd2fac7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -20,6 +20,7 @@ import java.util.function.Function; import java.util.stream.Stream; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; import org.springframework.web.servlet.handler.PathPatternsParameterizedTest; @@ -46,7 +47,7 @@ class WebContentInterceptorTests { @SuppressWarnings("unused") - private static Stream> pathPatternsArguments() { + private static Stream>> pathPatternsArguments() { return PathPatternsTestUtils.requestArguments(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java index e0b9c866a787..f89b1308fa6c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -19,8 +19,10 @@ import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; @@ -49,6 +51,8 @@ import org.springframework.web.testfixture.servlet.MockHttpServletResponse; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Named.named; +import static org.junit.jupiter.params.provider.Arguments.arguments; /** * Test various scenarios for detecting method-level and method parameter annotations depending @@ -60,34 +64,39 @@ */ class HandlerMethodAnnotationDetectionTests { - static Object[][] handlerTypes() { - return new Object[][] { - { SimpleController.class, true }, // CGLIB proxy - { SimpleController.class, false }, + static Stream handlerTypes() { + return Stream.of( + args(SimpleController.class, true), // CGLIB proxy + args(SimpleController.class, false), - { AbstractClassController.class, true }, // CGLIB proxy - { AbstractClassController.class, false }, + args(AbstractClassController.class, true), // CGLIB proxy + args(AbstractClassController.class, false), - { ParameterizedAbstractClassController.class, true }, // CGLIB proxy - { ParameterizedAbstractClassController.class, false }, + args(ParameterizedAbstractClassController.class, true), // CGLIB proxy + args(ParameterizedAbstractClassController.class, false), - { ParameterizedSubclassOverridesDefaultMappings.class, true }, // CGLIB proxy - { ParameterizedSubclassOverridesDefaultMappings.class, false }, + args(ParameterizedSubclassOverridesDefaultMappings.class, true), // CGLIB proxy + args(ParameterizedSubclassOverridesDefaultMappings.class, false), // TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases - // { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGLIB proxy - // { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false }, + // args(ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true), // CGLIB proxy + // args(ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false), - { InterfaceController.class, true }, // JDK dynamic proxy - { InterfaceController.class, false }, + args(InterfaceController.class, true), // JDK dynamic proxy + args(InterfaceController.class, false), - { ParameterizedInterfaceController.class, false }, // no AOP + args(ParameterizedInterfaceController.class, false), // no AOP - { SupportClassController.class, true }, // CGLIB proxy - { SupportClassController.class, false } - }; + args(SupportClassController.class, true), // CGLIB proxy + args(SupportClassController.class, false) + ); } + private static Arguments args(Class controllerType, boolean useAutoProxy) { + return arguments(named(controllerType.getSimpleName(), controllerType), useAutoProxy); + } + + private RequestMappingHandlerMapping handlerMapping; private RequestMappingHandlerAdapter handlerAdapter; @@ -116,9 +125,9 @@ private void setUp(Class controllerType, boolean useAutoProxy) { } - @ParameterizedTest(name = "[{index}] controller [{0}], auto-proxy [{1}]") + @ParameterizedTest(name = "[{index}] controller = {0}, auto-proxy = {1}") @MethodSource("handlerTypes") - void testRequestMappingMethod(Class controllerType, boolean useAutoProxy) throws Exception { + void requestMappingMethod(Class controllerType, boolean useAutoProxy) throws Exception { setUp(controllerType, useAutoProxy); String datePattern = "MM:dd:yyyy"; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/DefaultRequestToViewNameTranslatorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/DefaultRequestToViewNameTranslatorTests.java index c1ed9b9c2dd8..96d30b4bd6cc 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/DefaultRequestToViewNameTranslatorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/DefaultRequestToViewNameTranslatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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. @@ -19,6 +19,8 @@ import java.util.function.Function; import java.util.stream.Stream; +import org.junit.jupiter.api.Named; + import org.springframework.web.servlet.handler.PathPatternsParameterizedTest; import org.springframework.web.servlet.handler.PathPatternsTestUtils; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; @@ -38,59 +40,59 @@ public class DefaultRequestToViewNameTranslatorTests { @SuppressWarnings("unused") - private static Stream> pathPatternsArguments() { + private static Stream>> pathPatternsArguments() { return PathPatternsTestUtils.requestArguments("/sundays"); } @PathPatternsParameterizedTest - void testGetViewNameLeavesLeadingSlashIfSoConfigured(Function requestFactory) { + void getViewNameLeavesLeadingSlashIfSoConfigured(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + "/"); this.translator.setStripLeadingSlash(false); assertViewName(request, "/" + VIEW_NAME); } @PathPatternsParameterizedTest - void testGetViewNameLeavesTrailingSlashIfSoConfigured(Function requestFactory) { + void getViewNameLeavesTrailingSlashIfSoConfigured(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + "/"); this.translator.setStripTrailingSlash(false); assertViewName(request, VIEW_NAME + "/"); } @PathPatternsParameterizedTest - void testGetViewNameLeavesExtensionIfSoConfigured(Function requestFactory) { + void getViewNameLeavesExtensionIfSoConfigured(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + EXTENSION); this.translator.setStripExtension(false); assertViewName(request, VIEW_NAME + EXTENSION); } @PathPatternsParameterizedTest - void testGetViewNameWithDefaultConfiguration(Function requestFactory) { + void getViewNameWithDefaultConfiguration(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + EXTENSION); assertViewName(request, VIEW_NAME); } @PathPatternsParameterizedTest - void testGetViewNameWithCustomSeparator(Function requestFactory) { + void getViewNameWithCustomSeparator(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + "/fiona" + EXTENSION); this.translator.setSeparator("_"); assertViewName(request, VIEW_NAME + "_fiona"); } @PathPatternsParameterizedTest - void testGetViewNameWithNoExtension(Function requestFactory) { + void getViewNameWithNoExtension(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME); assertViewName(request, VIEW_NAME); } @PathPatternsParameterizedTest - void testGetViewNameWithSemicolonContent(Function requestFactory) { + void getViewNameWithSemicolonContent(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME + ";a=A;b=B"); assertViewName(request, VIEW_NAME); } @PathPatternsParameterizedTest - void testGetViewNameWithPrefix(Function requestFactory) { + void getViewNameWithPrefix(Function requestFactory) { final String prefix = "fiona_"; MockHttpServletRequest request = requestFactory.apply(VIEW_NAME); this.translator.setPrefix(prefix); @@ -98,14 +100,14 @@ void testGetViewNameWithPrefix(Function requestF } @PathPatternsParameterizedTest - void testGetViewNameWithNullPrefix(Function requestFactory) { + void getViewNameWithNullPrefix(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME); this.translator.setPrefix(null); assertViewName(request, VIEW_NAME); } @PathPatternsParameterizedTest - void testGetViewNameWithSuffix(Function requestFactory) { + void getViewNameWithSuffix(Function requestFactory) { final String suffix = ".fiona"; MockHttpServletRequest request = requestFactory.apply(VIEW_NAME); this.translator.setSuffix(suffix); @@ -113,7 +115,7 @@ void testGetViewNameWithSuffix(Function requestF } @PathPatternsParameterizedTest - void testGetViewNameWithNullSuffix(Function requestFactory) { + void getViewNameWithNullSuffix(Function requestFactory) { MockHttpServletRequest request = requestFactory.apply(VIEW_NAME); this.translator.setSuffix(null); assertViewName(request, VIEW_NAME); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java index ec9f90bfccaf..ea71fba3bc7b 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -46,6 +46,7 @@ import org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy; import org.springframework.web.socket.server.support.DefaultHandshakeHandler; +import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; /** @@ -66,15 +67,15 @@ public abstract class AbstractWebSocketIntegrationTests { static Stream argumentsFactory() { return Stream.of( - arguments(new JettyWebSocketTestServer(), new JettyWebSocketClient()), - arguments(new TomcatWebSocketTestServer(), new StandardWebSocketClient()), - arguments(new UndertowTestServer(), new StandardWebSocketClient())); + arguments(named("Jetty", new JettyWebSocketTestServer()), named("Jetty", new JettyWebSocketClient())), + arguments(named("Tomcat", new TomcatWebSocketTestServer()), named("Standard", new StandardWebSocketClient())), + arguments(named("Undertow", new UndertowTestServer()), named("Standard", new StandardWebSocketClient()))); } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - @ParameterizedTest(name = "[{index}] server [{0}], client [{1}]") + @ParameterizedTest(name = "[{index}] server = {0}, client = {1}") @MethodSource("argumentsFactory") protected @interface ParameterizedWebSocketTest { } diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 4a6ec9023c3e..6e27de7f0729 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -104,6 +104,7 @@ +