Skip to content

Commit 2575621

Browse files
dreis2211snicoll
authored andcommitted
Fix some illegal reflective access warnings
See gh-25531
1 parent c7c3365 commit 2575621

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
1818

19+
import java.util.concurrent.LinkedBlockingQueue;
20+
1921
import com.wavefront.sdk.common.WavefrontSender;
2022
import io.micrometer.core.instrument.Clock;
2123
import io.micrometer.wavefront.WavefrontConfig;
2224
import io.micrometer.wavefront.WavefrontMeterRegistry;
25+
import org.assertj.core.api.InstanceOfAssertFactories;
2326
import org.junit.jupiter.api.Test;
2427

2528
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -28,6 +31,7 @@
2831
import org.springframework.context.annotation.Configuration;
2932
import org.springframework.context.annotation.Import;
3033

34+
import static org.assertj.core.api.Assertions.as;
3135
import static org.assertj.core.api.Assertions.assertThat;
3236
import static org.mockito.Mockito.mock;
3337

@@ -85,8 +89,10 @@ void defaultWavefrontSenderSettingsAreConsistent() {
8589
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde").run((context) -> {
8690
WavefrontProperties properties = new WavefrontProperties();
8791
WavefrontSender sender = context.getBean(WavefrontSender.class);
88-
assertThat(sender).extracting("metricsBuffer").hasFieldOrPropertyWithValue("capacity",
89-
properties.getSender().getMaxQueueSize());
92+
assertThat(sender)
93+
.extracting("metricsBuffer", as(InstanceOfAssertFactories.type(LinkedBlockingQueue.class)))
94+
.satisfies((queue) -> assertThat(queue.remainingCapacity() + queue.size())
95+
.isEqualTo(properties.getSender().getMaxQueueSize()));
9096
assertThat(sender).hasFieldOrPropertyWithValue("batchSize", properties.getBatchSize());
9197
assertThat(sender).hasFieldOrPropertyWithValue("messageSizeBytes",
9298
(int) properties.getSender().getMessageSize().toBytes());
@@ -103,7 +109,9 @@ void configureWavefrontSender() {
103109
.run((context) -> {
104110
WavefrontSender sender = context.getBean(WavefrontSender.class);
105111
assertThat(sender).hasFieldOrPropertyWithValue("batchSize", 50);
106-
assertThat(sender).extracting("metricsBuffer").hasFieldOrPropertyWithValue("capacity", 100);
112+
assertThat(sender)
113+
.extracting("metricsBuffer", as(InstanceOfAssertFactories.type(LinkedBlockingQueue.class)))
114+
.satisfies((queue) -> assertThat(queue.remainingCapacity() + queue.size()).isEqualTo(100));
107115
assertThat(sender).hasFieldOrPropertyWithValue("messageSizeBytes", 1024);
108116
});
109117
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesKafka24Tests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,11 +32,12 @@
3232
@ClassPathOverrides("org.apache.kafka:kafka-clients:2.4.1")
3333
class KafkaPropertiesKafka24Tests {
3434

35+
@SuppressWarnings("rawtypes")
3536
@Test
3637
void isolationLevelEnumConsistentWithKafkaVersion() throws ClassNotFoundException {
3738
Class<?> isolationLevelClass = Class.forName("org.apache.kafka.common.requests.IsolationLevel");
38-
Object[] original = ReflectionTestUtils.invokeMethod(isolationLevelClass, "values");
39-
assertThat(original).extracting("name").containsExactly(IsolationLevel.READ_UNCOMMITTED.name(),
39+
Enum[] original = ReflectionTestUtils.invokeMethod(isolationLevelClass, "values");
40+
assertThat(original).extracting(Enum::name).containsExactly(IsolationLevel.READ_UNCOMMITTED.name(),
4041
IsolationLevel.READ_COMMITTED.name());
4142
assertThat(original).extracting("id").containsExactly(IsolationLevel.READ_UNCOMMITTED.id(),
4243
IsolationLevel.READ_COMMITTED.id());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaPropertiesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ class KafkaPropertiesTests {
3636
@Test
3737
void isolationLevelEnumConsistentWithKafkaVersion() {
3838
org.apache.kafka.common.IsolationLevel[] original = org.apache.kafka.common.IsolationLevel.values();
39-
assertThat(original).extracting("name").containsExactly(IsolationLevel.READ_UNCOMMITTED.name(),
39+
assertThat(original).extracting(Enum::name).containsExactly(IsolationLevel.READ_UNCOMMITTED.name(),
4040
IsolationLevel.READ_COMMITTED.name());
4141
assertThat(original).extracting("id").containsExactly(IsolationLevel.READ_UNCOMMITTED.id(),
4242
IsolationLevel.READ_COMMITTED.id());

0 commit comments

Comments
 (0)