Clean up warnings and polish tests

This commit also modifies ResourceWebHandlerTests.getResourceFromFileSystem()
so that it passes in the IDE.
This commit is contained in:
Sam Brannen
2022-08-26 15:20:16 +02:00
parent e53c7ae6f5
commit b50415062b
20 changed files with 206 additions and 214 deletions

View File

@@ -506,6 +506,7 @@ public class DefaultDataBuffer implements DataBuffer {
}
@Override
@SuppressWarnings("deprecation")
public DefaultDataBuffer capacity(int newCapacity) {
throw new UnsupportedOperationException("Changing the capacity of a sliced buffer is not supported");
}

View File

@@ -42,8 +42,8 @@ class Netty5BufferEncoderTests extends AbstractEncoderTests<Netty5BufferEncoder>
super(new Netty5BufferEncoder());
}
@Override
@Test
@Override
public void canEncode() {
assertThat(this.encoder.canEncode(ResolvableType.forClass(Buffer.class),
MimeTypeUtils.TEXT_PLAIN)).isTrue();
@@ -56,8 +56,9 @@ class Netty5BufferEncoderTests extends AbstractEncoderTests<Netty5BufferEncoder>
assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isFalse();
}
@Override
@Test
@Override
@SuppressWarnings("resource")
public void encode() {
Flux<Buffer> input = Flux.just(this.fooBytes, this.barBytes)
.map(DefaultBufferAllocators.preferredAllocator()::copyOf);
@@ -67,4 +68,5 @@ class Netty5BufferEncoderTests extends AbstractEncoderTests<Netty5BufferEncoder>
.consumeNextWith(expectBytes(this.barBytes))
.verifyComplete());
}
}

View File

@@ -389,6 +389,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
}
@ParameterizedDataBufferAllocatingTest
@SuppressWarnings("deprecation")
void increaseCapacity(DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;
@@ -402,6 +403,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
}
@ParameterizedDataBufferAllocatingTest
@SuppressWarnings("deprecation")
void decreaseCapacityLowReadPosition(DataBufferFactory bufferFactory) {
assumeFalse(bufferFactory instanceof Netty5DataBufferFactory,
"Netty 5 does not support decreasing the capacity");
@@ -417,6 +419,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
}
@ParameterizedDataBufferAllocatingTest
@SuppressWarnings("deprecation")
void decreaseCapacityHighReadPosition(DataBufferFactory bufferFactory) {
assumeFalse(bufferFactory instanceof Netty5DataBufferFactory,
"Netty 5 does not support decreasing the capacity");
@@ -433,13 +436,13 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
}
@ParameterizedDataBufferAllocatingTest
@SuppressWarnings("deprecation")
void capacityLessThanZero(DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;
DataBuffer buffer = createDataBuffer(1);
try {
assertThatIllegalArgumentException().isThrownBy(() ->
buffer.capacity(-1));
assertThatIllegalArgumentException().isThrownBy(() -> buffer.capacity(-1));
}
finally {
release(buffer);
@@ -754,6 +757,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
}
@ParameterizedDataBufferAllocatingTest
@SuppressWarnings("deprecation")
void spr16351(DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;

View File

@@ -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.
@@ -32,11 +32,11 @@ class LeakAwareDataBufferFactoryTests {
@Test
@SuppressWarnings("deprecation")
void leak() {
DataBuffer dataBuffer = this.bufferFactory.allocateBuffer();
try {
assertThatExceptionOfType(AssertionError.class).isThrownBy(
this.bufferFactory::checkForLeaks);
assertThatExceptionOfType(AssertionError.class).isThrownBy(this.bufferFactory::checkForLeaks);
}
finally {
release(dataBuffer);
@@ -45,7 +45,7 @@ class LeakAwareDataBufferFactoryTests {
@Test
void noLeak() {
DataBuffer dataBuffer = this.bufferFactory.allocateBuffer();
DataBuffer dataBuffer = this.bufferFactory.allocateBuffer(256);
release(dataBuffer);
this.bufferFactory.checkForLeaks();
}

View File

@@ -99,7 +99,7 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory {
List<AssertionError> errors = this.created.stream()
.filter(LeakAwareDataBuffer::isAllocated)
.map(LeakAwareDataBuffer::leakError)
.collect(Collectors.toList());
.toList();
errors.forEach(it -> logger.error("Leaked error: ", it));
throw new AssertionError(errors.size() + " buffer leaks detected (see logs above)");