Skip to content

Commit 66b121a

Browse files
committed
Update jspecify nullability in test classes
Signed-off-by: Soby Chacko <[email protected]>
1 parent 01b82e2 commit 66b121a

8 files changed

+30
-42
lines changed

Diff for: spring-kafka/src/test/java/org/springframework/kafka/annotation/EnableKafkaIntegrationTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -63,6 +63,8 @@
6363
import org.apache.kafka.common.errors.TopicExistsException;
6464
import org.apache.kafka.common.serialization.ByteArrayDeserializer;
6565
import org.apache.kafka.common.serialization.ByteArraySerializer;
66+
import org.jspecify.annotations.NonNull;
67+
import org.jspecify.annotations.Nullable;
6668
import org.junit.jupiter.api.Test;
6769

6870
import org.springframework.aop.framework.ProxyFactory;
@@ -134,8 +136,6 @@
134136
import org.springframework.kafka.test.EmbeddedKafkaKraftBroker;
135137
import org.springframework.kafka.test.context.EmbeddedKafka;
136138
import org.springframework.kafka.test.utils.KafkaTestUtils;
137-
import org.springframework.lang.NonNull;
138-
import org.springframework.lang.Nullable;
139139
import org.springframework.messaging.Message;
140140
import org.springframework.messaging.MessageHeaders;
141141
import org.springframework.messaging.converter.AbstractMessageConverter;
@@ -1877,8 +1877,7 @@ protected Object convertFromInternal(Message<?> message, Class<?> targetClass,
18771877
}
18781878

18791879
@Override
1880-
@Nullable
1881-
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
1880+
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
18821881
@Nullable Object conversionHint) {
18831882

18841883
return payload instanceof Foo ? ((Foo) payload).getBar() : null;

Diff for: spring-kafka/src/test/java/org/springframework/kafka/listener/ConcurrentMessageListenerContainerMockTests.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 the original author or authors.
2+
* Copyright 2019-2025 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.
@@ -43,6 +43,7 @@
4343
import org.apache.kafka.clients.producer.Producer;
4444
import org.apache.kafka.common.TopicPartition;
4545
import org.apache.kafka.common.errors.GroupAuthorizationException;
46+
import org.jspecify.annotations.Nullable;
4647
import org.junit.jupiter.api.DisplayName;
4748
import org.junit.jupiter.api.Test;
4849

@@ -58,7 +59,6 @@
5859
import org.springframework.kafka.support.Acknowledgment;
5960
import org.springframework.kafka.test.utils.KafkaTestUtils;
6061
import org.springframework.kafka.transaction.KafkaAwareTransactionManager;
61-
import org.springframework.lang.Nullable;
6262
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6363
import org.springframework.transaction.support.TransactionSynchronizationManager;
6464

@@ -686,8 +686,7 @@ void testIntercept(boolean beforeTx, @Nullable AssignmentCommitOption option, bo
686686
container.setRecordInterceptor(new RecordInterceptor() {
687687

688688
@Override
689-
@Nullable
690-
public ConsumerRecord intercept(ConsumerRecord rec, Consumer consumer) {
689+
public @Nullable ConsumerRecord intercept(ConsumerRecord rec, Consumer consumer) {
691690
order.add("interceptor");
692691
latch.countDown();
693692
return rec;
@@ -709,8 +708,7 @@ public void failure(ConsumerRecord record, Exception exception, Consumer consume
709708
container.setBatchInterceptor(new BatchInterceptor() {
710709

711710
@Override
712-
@Nullable
713-
public ConsumerRecords intercept(ConsumerRecords recs, Consumer consumer) {
711+
public @Nullable ConsumerRecords intercept(ConsumerRecords recs, Consumer consumer) {
714712
order.add("interceptor");
715713
latch.countDown();
716714
return new ConsumerRecords(Collections.singletonMap(tp0, Collections.singletonList(record1)));

Diff for: spring-kafka/src/test/java/org/springframework/kafka/listener/ConcurrentMessageListenerContainerTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -42,6 +42,7 @@
4242
import org.apache.kafka.clients.consumer.ConsumerRecord;
4343
import org.apache.kafka.clients.consumer.ConsumerRecords;
4444
import org.apache.kafka.common.TopicPartition;
45+
import org.jspecify.annotations.Nullable;
4546
import org.junit.jupiter.api.BeforeAll;
4647
import org.junit.jupiter.api.Test;
4748
import org.mockito.invocation.InvocationOnMock;
@@ -63,7 +64,6 @@
6364
import org.springframework.kafka.test.context.EmbeddedKafka;
6465
import org.springframework.kafka.test.utils.ContainerTestUtils;
6566
import org.springframework.kafka.test.utils.KafkaTestUtils;
66-
import org.springframework.lang.Nullable;
6767

6868
import static org.assertj.core.api.Assertions.assertThat;
6969
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

Diff for: spring-kafka/src/test/java/org/springframework/kafka/listener/KafkaMessageListenerContainerTests.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -64,6 +64,8 @@
6464
import org.apache.kafka.common.errors.WakeupException;
6565
import org.apache.kafka.common.serialization.IntegerDeserializer;
6666
import org.assertj.core.api.InstanceOfAssertFactories;
67+
import org.jspecify.annotations.NonNull;
68+
import org.jspecify.annotations.Nullable;
6769
import org.junit.jupiter.api.BeforeAll;
6870
import org.junit.jupiter.api.Test;
6971
import org.junit.jupiter.params.ParameterizedTest;
@@ -109,8 +111,6 @@
109111
import org.springframework.kafka.test.utils.ContainerTestUtils;
110112
import org.springframework.kafka.test.utils.KafkaTestUtils;
111113
import org.springframework.kafka.transaction.KafkaAwareTransactionManager;
112-
import org.springframework.lang.NonNull;
113-
import org.springframework.lang.Nullable;
114114
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
115115
import org.springframework.util.backoff.FixedBackOff;
116116

@@ -3845,8 +3845,7 @@ public void onMessage(ConsumerRecord<Integer, String> data) {
38453845
RecordInterceptor<Integer, String> recordInterceptor = spy(new RecordInterceptor<Integer, String>() {
38463846

38473847
@Override
3848-
@NonNull
3849-
public ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String> record,
3848+
public @NonNull ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String> record,
38503849
Consumer<Integer, String> consumer) {
38513850

38523851
return record;
@@ -3934,8 +3933,7 @@ public void testInvokeRecordInterceptorAllSkipped(AckMode ackMode, boolean early
39343933
RecordInterceptor<Integer, String> recordInterceptor = spy(new RecordInterceptor<Integer, String>() {
39353934

39363935
@Override
3937-
@Nullable
3938-
public ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String> record,
3936+
public @Nullable ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String> record,
39393937
Consumer<Integer, String> consumer) {
39403938

39413939
return null;
@@ -4024,8 +4022,7 @@ public void testInvokeBatchInterceptorAllSkipped(boolean early) throws Exception
40244022
BatchInterceptor<Integer, String> interceptor = spy(new BatchInterceptor<Integer, String>() {
40254023

40264024
@Override
4027-
@Nullable
4028-
public ConsumerRecords<Integer, String> intercept(ConsumerRecords<Integer, String> records,
4025+
public @Nullable ConsumerRecords<Integer, String> intercept(ConsumerRecords<Integer, String> records,
40294026
Consumer<Integer, String> consumer) {
40304027

40314028
return null;
@@ -4090,8 +4087,7 @@ public void onMessage(ConsumerRecord<Integer, String> data) {
40904087
RecordInterceptor<Integer, String> recordInterceptor = spy(new RecordInterceptor<Integer, String>() {
40914088

40924089
@Override
4093-
@NonNull
4094-
public ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String> record,
4090+
public @NonNull ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String> record,
40954091
Consumer<Integer, String> consumer) {
40964092

40974093
return record;

Diff for: spring-kafka/src/test/java/org/springframework/kafka/listener/ManualNackRecordTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 the original author or authors.
2+
* Copyright 2017-2025 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.
@@ -39,6 +39,7 @@
3939
import org.apache.kafka.common.TopicPartition;
4040
import org.apache.kafka.common.header.internals.RecordHeaders;
4141
import org.apache.kafka.common.record.TimestampType;
42+
import org.jspecify.annotations.Nullable;
4243
import org.junit.jupiter.api.Test;
4344
import org.mockito.InOrder;
4445

@@ -53,7 +54,6 @@
5354
import org.springframework.kafka.listener.ContainerProperties.AckMode;
5455
import org.springframework.kafka.support.Acknowledgment;
5556
import org.springframework.kafka.test.utils.KafkaTestUtils;
56-
import org.springframework.lang.Nullable;
5757
import org.springframework.test.annotation.DirtiesContext;
5858
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5959

@@ -248,9 +248,8 @@ public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() {
248248
factory.setRecordInterceptor(new RecordInterceptor() {
249249

250250
@Override
251-
@Nullable
252251
@SuppressWarnings("rawtypes")
253-
public ConsumerRecord intercept(ConsumerRecord record, Consumer consumer) {
252+
public @Nullable ConsumerRecord intercept(ConsumerRecord record, Consumer consumer) {
254253
return new ConsumerRecord(record.topic(), record.partition(), record.offset(), 0L,
255254
TimestampType.NO_TIMESTAMP_TYPE, 0, 0, record.key(), record.value(), record.headers(),
256255
Optional.empty());

Diff for: spring-kafka/src/test/java/org/springframework/kafka/listener/SeekToCurrentRecovererTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2024 the original author or authors.
2+
* Copyright 2018-2025 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,6 +36,7 @@
3636
import org.apache.kafka.common.TopicPartition;
3737
import org.apache.kafka.common.serialization.ByteArraySerializer;
3838
import org.apache.kafka.common.serialization.Serializer;
39+
import org.jspecify.annotations.Nullable;
3940
import org.junit.jupiter.api.BeforeAll;
4041
import org.junit.jupiter.api.Test;
4142

@@ -51,7 +52,6 @@
5152
import org.springframework.kafka.test.condition.EmbeddedKafkaCondition;
5253
import org.springframework.kafka.test.context.EmbeddedKafka;
5354
import org.springframework.kafka.test.utils.KafkaTestUtils;
54-
import org.springframework.lang.Nullable;
5555
import org.springframework.util.backoff.FixedBackOff;
5656

5757
import static org.assertj.core.api.Assertions.assertThat;

Diff for: spring-kafka/src/test/java/org/springframework/kafka/support/converter/MessagingMessageConverterTests.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 the original author or authors.
2+
* Copyright 2019-2025 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.
@@ -26,10 +26,10 @@
2626
import org.apache.kafka.common.header.Headers;
2727
import org.apache.kafka.common.header.internals.RecordHeader;
2828
import org.apache.kafka.common.header.internals.RecordHeaders;
29+
import org.jspecify.annotations.Nullable;
2930
import org.junit.jupiter.api.Test;
3031

3132
import org.springframework.kafka.support.KafkaHeaders;
32-
import org.springframework.lang.Nullable;
3333
import org.springframework.messaging.Message;
3434
import org.springframework.messaging.MessageHeaders;
3535
import org.springframework.messaging.converter.AbstractMessageConverter;
@@ -183,16 +183,14 @@ protected boolean supports(Class<?> clazz) {
183183
}
184184

185185
@Override
186-
@Nullable
187-
protected Object convertFromInternal(Message<?> message, Class<?> targetClass,
186+
protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass,
188187
@Nullable Object conversionHint) {
189188

190189
return new Foo("bar");
191190
}
192191

193192
@Override
194-
@Nullable
195-
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
193+
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
196194
@Nullable Object conversionHint) {
197195

198196
return "foo".getBytes();
@@ -207,16 +205,14 @@ static class BarConverter extends FooConverter {
207205
}
208206

209207
@Override
210-
@Nullable
211-
protected Object convertFromInternal(Message<?> message, Class<?> targetClass,
208+
protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass,
212209
@Nullable Object conversionHint) {
213210

214211
return new Bar("bar");
215212
}
216213

217214
@Override
218-
@Nullable
219-
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
215+
protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
220216
@Nullable Object conversionHint) {
221217

222218
return "bar".getBytes();

Diff for: spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 the original author or authors.
2+
* Copyright 2022-2025 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.
@@ -56,6 +56,7 @@
5656
import org.apache.kafka.common.errors.InvalidTopicException;
5757
import org.apache.kafka.common.header.Header;
5858
import org.apache.kafka.common.header.Headers;
59+
import org.jspecify.annotations.Nullable;
5960
import org.junit.jupiter.api.Test;
6061
import reactor.core.publisher.Mono;
6162

@@ -82,7 +83,6 @@
8283
import org.springframework.kafka.test.EmbeddedKafkaBroker;
8384
import org.springframework.kafka.test.context.EmbeddedKafka;
8485
import org.springframework.kafka.test.utils.KafkaTestUtils;
85-
import org.springframework.lang.Nullable;
8686
import org.springframework.test.annotation.DirtiesContext;
8787
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
8888
import org.springframework.util.StringUtils;

0 commit comments

Comments
 (0)