Clean up warnings and polish tests
This commit also modifies ResourceWebHandlerTests.getResourceFromFileSystem() so that it passes in the IDE.
This commit is contained in:
@@ -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.
|
||||
@@ -65,12 +65,11 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
|
||||
@Test
|
||||
public void extensionRegistryNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new ProtobufDecoder(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ProtobufDecoder(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@Override
|
||||
public void canDecode() {
|
||||
assertThat(this.decoder.canDecode(forClass(Msg.class), null)).isTrue();
|
||||
assertThat(this.decoder.canDecode(forClass(Msg.class), PROTOBUF_MIME_TYPE)).isTrue();
|
||||
@@ -79,8 +78,8 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
assertThat(this.decoder.canDecode(forClass(Object.class), PROTOBUF_MIME_TYPE)).isFalse();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@Override
|
||||
public void decodeToMono() {
|
||||
Mono<DataBuffer> input = dataBuffer(this.testMsg1);
|
||||
|
||||
@@ -107,8 +106,9 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
.verifyComplete());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void decode() {
|
||||
Flux<DataBuffer> input = Flux.just(this.testMsg1, this.testMsg2)
|
||||
.flatMap(msg -> Mono.defer(() -> {
|
||||
@@ -130,9 +130,8 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void decodeSplitChunks() {
|
||||
|
||||
|
||||
Flux<DataBuffer> input = Flux.just(this.testMsg1, this.testMsg2)
|
||||
.flatMap(msg -> Mono.defer(() -> {
|
||||
DataBuffer buffer = this.bufferFactory.allocateBuffer();
|
||||
@@ -163,6 +162,7 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
}
|
||||
|
||||
@Test // SPR-17429
|
||||
@SuppressWarnings("deprecation")
|
||||
public void decodeSplitMessageSize() {
|
||||
this.decoder.setMaxMessageSize(100009);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -201,6 +201,7 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void decodeMergedChunks() throws IOException {
|
||||
DataBuffer buffer = this.bufferFactory.allocateBuffer();
|
||||
this.testMsg1.writeDelimitedTo(buffer.asOutputStream());
|
||||
@@ -220,8 +221,7 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
this.decoder.setMaxMessageSize(1);
|
||||
Mono<DataBuffer> input = dataBuffer(this.testMsg1);
|
||||
|
||||
testDecode(input, Msg.class, step -> step
|
||||
.verifyError(DecodingException.class));
|
||||
testDecode(input, Msg.class, step -> step.verifyError(DecodingException.class));
|
||||
}
|
||||
|
||||
private Mono<DataBuffer> dataBuffer(Msg msg) {
|
||||
@@ -233,5 +233,4 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -61,6 +61,7 @@ class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
private class AsyncHandler implements HttpHandler {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
return response.writeWith(Flux.just("h", "e", "l", "l", "o")
|
||||
.delayElements(Duration.ofMillis(100))
|
||||
|
||||
@@ -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.
|
||||
@@ -43,13 +43,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Stephane Maldini
|
||||
*/
|
||||
public class ChannelSendOperatorTests {
|
||||
class ChannelSendOperatorTests {
|
||||
|
||||
private final OneByOneAsyncWriter writer = new OneByOneAsyncWriter();
|
||||
|
||||
|
||||
@Test
|
||||
public void errorBeforeFirstItem() throws Exception {
|
||||
void errorBeforeFirstItem() throws Exception {
|
||||
IllegalStateException error = new IllegalStateException("boo");
|
||||
Mono<Void> completion = Mono.<String>error(error).as(this::sendOperator);
|
||||
Signal<Void> signal = completion.materialize().block();
|
||||
@@ -59,7 +59,7 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void completionBeforeFirstItem() throws Exception {
|
||||
void completionBeforeFirstItem() throws Exception {
|
||||
Mono<Void> completion = Flux.<String>empty().as(this::sendOperator);
|
||||
Signal<Void> signal = completion.materialize().block();
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeOneItem() throws Exception {
|
||||
void writeOneItem() throws Exception {
|
||||
Mono<Void> completion = Flux.just("one").as(this::sendOperator);
|
||||
Signal<Void> signal = completion.materialize().block();
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ChannelSendOperatorTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void writeMultipleItems() {
|
||||
void writeMultipleItems() {
|
||||
List<String> items = Arrays.asList("one", "two", "three");
|
||||
Mono<Void> completion = Flux.fromIterable(items).as(this::sendOperator);
|
||||
Signal<Void> signal = completion.materialize().block();
|
||||
@@ -101,7 +101,7 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorAfterMultipleItems() {
|
||||
void errorAfterMultipleItems() {
|
||||
IllegalStateException error = new IllegalStateException("boo");
|
||||
Flux<String> publisher = Flux.generate(() -> 0, (idx , subscriber) -> {
|
||||
int i = ++idx;
|
||||
@@ -125,12 +125,12 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test // gh-22720
|
||||
public void cancelWhileItemCached() {
|
||||
void cancelWhileItemCached() {
|
||||
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
|
||||
|
||||
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(
|
||||
Mono.fromCallable(() -> {
|
||||
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
|
||||
DataBuffer dataBuffer = bufferFactory.allocateBuffer(256);
|
||||
dataBuffer.write("foo", StandardCharsets.UTF_8);
|
||||
return dataBuffer;
|
||||
}),
|
||||
@@ -148,7 +148,7 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test // gh-22720
|
||||
public void errorFromWriteSourceWhileItemCached() {
|
||||
void errorFromWriteSourceWhileItemCached() {
|
||||
|
||||
// 1. First item received
|
||||
// 2. writeFunction applied and writeCompletionBarrier subscribed to it
|
||||
@@ -159,7 +159,7 @@ public class ChannelSendOperatorTests {
|
||||
|
||||
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(
|
||||
Flux.create(sink -> {
|
||||
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
|
||||
DataBuffer dataBuffer = bufferFactory.allocateBuffer(256);
|
||||
dataBuffer.write("foo", StandardCharsets.UTF_8);
|
||||
sink.next(dataBuffer);
|
||||
sink.error(new IllegalStateException("err"));
|
||||
@@ -169,7 +169,6 @@ public class ChannelSendOperatorTests {
|
||||
return Mono.never();
|
||||
});
|
||||
|
||||
|
||||
operator.subscribe(new BaseSubscriber<Void>() {});
|
||||
try {
|
||||
writeSubscriber.signalDemand(1); // Let cached signals ("foo" and error) be published..
|
||||
@@ -183,7 +182,7 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test // gh-22720
|
||||
public void errorFromWriteFunctionWhileItemCached() {
|
||||
void errorFromWriteFunctionWhileItemCached() {
|
||||
|
||||
// 1. First item received
|
||||
// 2. writeFunction applied and writeCompletionBarrier subscribed to it
|
||||
@@ -193,7 +192,7 @@ public class ChannelSendOperatorTests {
|
||||
|
||||
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(
|
||||
Flux.create(sink -> {
|
||||
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
|
||||
DataBuffer dataBuffer = bufferFactory.allocateBuffer(256);
|
||||
dataBuffer.write("foo", StandardCharsets.UTF_8);
|
||||
sink.next(dataBuffer);
|
||||
}),
|
||||
@@ -207,7 +206,7 @@ public class ChannelSendOperatorTests {
|
||||
}
|
||||
|
||||
@Test // gh-23175
|
||||
public void errorInWriteFunction() {
|
||||
void errorInWriteFunction() {
|
||||
|
||||
StepVerifier
|
||||
.create(new ChannelSendOperator<>(Mono.just("one"), p -> {
|
||||
@@ -251,7 +250,7 @@ public class ChannelSendOperatorTests {
|
||||
|
||||
private final Subscriber<? super Void> subscriber;
|
||||
|
||||
public WriteSubscriber(Subscriber<? super Void> subscriber) {
|
||||
WriteSubscriber(Subscriber<? super Void> subscriber) {
|
||||
this.subscriber = subscriber;
|
||||
}
|
||||
|
||||
@@ -284,7 +283,6 @@ public class ChannelSendOperatorTests {
|
||||
|
||||
private static class ZeroDemandSubscriber extends BaseSubscriber<DataBuffer> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void hookOnSubscribe(Subscription subscription) {
|
||||
// Just subscribe without requesting
|
||||
|
||||
@@ -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.
|
||||
@@ -34,9 +34,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link HttpHeadResponseDecorator}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class HttpHeadResponseDecoratorTests {
|
||||
class HttpHeadResponseDecoratorTests {
|
||||
|
||||
private final LeakAwareDataBufferFactory bufferFactory =
|
||||
new LeakAwareDataBufferFactory(new NettyDataBufferFactory(PooledByteBufAllocator.DEFAULT));
|
||||
@@ -46,27 +47,27 @@ public class HttpHeadResponseDecoratorTests {
|
||||
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
this.bufferFactory.checkForLeaks();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void writeWithFlux() {
|
||||
void writeWithFlux() {
|
||||
Flux<DataBuffer> body = Flux.just(toDataBuffer("data1"), toDataBuffer("data2"));
|
||||
this.response.writeWith(body).block();
|
||||
assertThat(this.response.getHeaders().getContentLength()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeWithMono() {
|
||||
void writeWithMono() {
|
||||
Mono<DataBuffer> body = Mono.just(toDataBuffer("data1,data2"));
|
||||
this.response.writeWith(body).block();
|
||||
assertThat(this.response.getHeaders().getContentLength()).isEqualTo(11);
|
||||
}
|
||||
|
||||
@Test // gh-23484
|
||||
public void writeWithGivenContentLength() {
|
||||
void writeWithGivenContentLength() {
|
||||
int length = 15;
|
||||
this.response.getHeaders().setContentLength(length);
|
||||
this.response.writeWith(Flux.empty()).block();
|
||||
@@ -74,7 +75,7 @@ public class HttpHeadResponseDecoratorTests {
|
||||
}
|
||||
|
||||
@Test // gh-25908
|
||||
public void writeWithGivenTransferEncoding() {
|
||||
void writeWithGivenTransferEncoding() {
|
||||
Flux<DataBuffer> body = Flux.just(toDataBuffer("data1"), toDataBuffer("data2"));
|
||||
this.response.getHeaders().add(HttpHeaders.TRANSFER_ENCODING, "chunked");
|
||||
this.response.writeWith(body).block();
|
||||
@@ -82,7 +83,7 @@ public class HttpHeadResponseDecoratorTests {
|
||||
}
|
||||
|
||||
private DataBuffer toDataBuffer(String s) {
|
||||
DataBuffer buffer = this.bufferFactory.allocateBuffer();
|
||||
DataBuffer buffer = this.bufferFactory.allocateBuffer(256);
|
||||
buffer.write(s.getBytes(StandardCharsets.UTF_8));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Sebastien Deleuze
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class ServerHttpResponseTests {
|
||||
class ServerHttpResponseTests {
|
||||
|
||||
@Test
|
||||
void writeWith() {
|
||||
@@ -68,9 +68,9 @@ public class ServerHttpResponseTests {
|
||||
assertThat(response.cookiesWritten).isTrue();
|
||||
|
||||
assertThat(response.body.size()).isEqualTo(3);
|
||||
assertThat(new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("a");
|
||||
assertThat(new String(response.body.get(1).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("b");
|
||||
assertThat(new String(response.body.get(2).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("c");
|
||||
assertThat(new String(response.body.get(0).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("a");
|
||||
assertThat(new String(response.body.get(1).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("b");
|
||||
assertThat(new String(response.body.get(2).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("c");
|
||||
}
|
||||
|
||||
@Test // SPR-14952
|
||||
@@ -84,7 +84,7 @@ public class ServerHttpResponseTests {
|
||||
assertThat(response.cookiesWritten).isTrue();
|
||||
|
||||
assertThat(response.body.size()).isEqualTo(1);
|
||||
assertThat(new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("foo");
|
||||
assertThat(new String(response.body.get(0).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,9 +139,9 @@ public class ServerHttpResponseTests {
|
||||
assertThat(response.getCookies().getFirst("ID")).isSameAs(cookie);
|
||||
|
||||
assertThat(response.body.size()).isEqualTo(3);
|
||||
assertThat(new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("a");
|
||||
assertThat(new String(response.body.get(1).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("b");
|
||||
assertThat(new String(response.body.get(2).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("c");
|
||||
assertThat(new String(response.body.get(0).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("a");
|
||||
assertThat(new String(response.body.get(1).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("b");
|
||||
assertThat(new String(response.body.get(2).toByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("c");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user