Skip to content

Commit 66c74bc

Browse files
committed
Polishing.
Refine assertions usage. Original pull request: #2985 Closes #2982
1 parent c16c840 commit 66c74bc

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

src/test/java/org/springframework/data/redis/connection/ReactiveStreamCommandsUnitTests.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.redis.connection;
217

318
import static org.assertj.core.api.Assertions.*;
@@ -24,7 +39,7 @@ void pendingRecordsCommandRangeShouldThrowExceptionWhenRangeIsNull() {
2439

2540
PendingRecordsCommand command = PendingRecordsCommand.pending(key, groupName);
2641

27-
assertThatThrownBy(() -> command.range(null, 10L)).isInstanceOf(IllegalArgumentException.class);
42+
assertThatIllegalArgumentException().isThrownBy(() -> command.range(null, 10L));
2843
}
2944

3045
@Test // GH-2982
@@ -36,6 +51,6 @@ void pendingRecordsCommandRangeShouldThrowExceptionWhenCountIsNegative() {
3651
PendingRecordsCommand command = PendingRecordsCommand.pending(key, groupName);
3752
Range<?> range = Range.closed("0", "10");
3853

39-
assertThatThrownBy(() -> command.range(range, -1L)).isInstanceOf(IllegalArgumentException.class);
54+
assertThatIllegalArgumentException().isThrownBy(() -> command.range(range, -1L));
4055
}
4156
}

src/test/java/org/springframework/data/redis/connection/RedisStreamCommandsUnitTests.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.redis.connection;
217

318
import static org.assertj.core.api.Assertions.*;
@@ -16,21 +31,19 @@ class RedisStreamCommandsUnitTests {
1631

1732
@Test // GH-2982
1833
void xPendingOptionsUnboundedShouldThrowExceptionWhenCountIsNegative() {
19-
20-
assertThatThrownBy(() -> XPendingOptions.unbounded(-1L)).isInstanceOf(IllegalArgumentException.class);
34+
assertThatIllegalArgumentException().isThrownBy(() -> XPendingOptions.unbounded(-1L));
2135
}
2236

2337
@Test // GH-2982
2438
void xPendingOptionsRangeShouldThrowExceptionWhenRangeIsNull() {
25-
26-
assertThatThrownBy(() -> XPendingOptions.range(null, 10L)).isInstanceOf(IllegalArgumentException.class);
39+
assertThatIllegalArgumentException().isThrownBy(() -> XPendingOptions.range(null, 10L));
2740
}
2841

2942
@Test // GH-2982
3043
void xPendingOptionsRangeShouldThrowExceptionWhenCountIsNegative() {
3144

3245
Range<?> range = Range.closed("0", "10");
3346

34-
assertThatThrownBy(() -> XPendingOptions.range(range, -1L)).isInstanceOf(IllegalArgumentException.class);
47+
assertThatIllegalArgumentException().isThrownBy(() -> XPendingOptions.range(range, -1L));
3548
}
3649
}

src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsIntegrationTests.java

-8
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ public class DefaultReactiveStreamOperationsIntegrationTests<K, HK, HV> {
8080
return ReactiveOperationsTestParams.testParams();
8181
}
8282

83-
/**
84-
* @param redisTemplate
85-
* @param keyFactory
86-
* @param valueFactory
87-
* @param label parameterized test label, no further use besides that.
88-
*/
8983
public DefaultReactiveStreamOperationsIntegrationTests(Fixture<K, HV> fixture) {
9084

9185
this.serializer = fixture.getSerializer();
@@ -359,7 +353,6 @@ void pendingShouldReadMessageDetails() {
359353
assertThat(pending.get(0).getConsumerName()).isEqualTo("my-consumer");
360354
assertThat(pending.get(0).getTotalDeliveryCount()).isOne();
361355
}).verifyComplete();
362-
363356
}
364357

365358
@ParameterizedRedisTest // GH-2465
@@ -384,6 +377,5 @@ void claimShouldReadMessageDetails() {
384377
assertThat(claimed.getValue()).isEqualTo(content);
385378
assertThat(claimed.getId()).isEqualTo(messageId);
386379
}).verifyComplete();
387-
388380
}
389381
}

src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsIntegrationTests.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@
3535
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
3636
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
3737
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
38-
import org.springframework.data.redis.connection.stream.*;
38+
import org.springframework.data.redis.connection.stream.Consumer;
39+
import org.springframework.data.redis.connection.stream.MapRecord;
40+
import org.springframework.data.redis.connection.stream.ObjectRecord;
41+
import org.springframework.data.redis.connection.stream.PendingMessages;
42+
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
43+
import org.springframework.data.redis.connection.stream.ReadOffset;
44+
import org.springframework.data.redis.connection.stream.RecordId;
45+
import org.springframework.data.redis.connection.stream.StreamOffset;
46+
import org.springframework.data.redis.connection.stream.StreamReadOptions;
47+
import org.springframework.data.redis.connection.stream.StreamRecords;
3948
import org.springframework.data.redis.test.condition.EnabledOnCommand;
4049
import org.springframework.data.redis.test.condition.EnabledOnRedisDriver;
4150
import org.springframework.data.redis.test.condition.EnabledOnRedisVersion;
@@ -65,7 +74,7 @@ public class DefaultStreamOperationsIntegrationTests<K, HK, HV> {
6574
private final StreamOperations<K, HK, HV> streamOps;
6675

6776
public DefaultStreamOperationsIntegrationTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
68-
ObjectFactory<?> objectFactory) {
77+
ObjectFactory<?> objectFactory) {
6978

7079
this.redisTemplate = redisTemplate;
7180
this.connectionFactory = redisTemplate.getRequiredConnectionFactory();
@@ -81,15 +90,15 @@ public static Collection<Object[]> testParams() {
8190
params.addAll(AbstractOperationsTestParams
8291
.testParams(JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class)));
8392

84-
if(RedisDetector.isClusterAvailable()) {
93+
if (RedisDetector.isClusterAvailable()) {
8594
params.addAll(AbstractOperationsTestParams
8695
.testParams(JedisConnectionFactoryExtension.getConnectionFactory(RedisCluster.class)));
8796
}
8897

8998
params.addAll(AbstractOperationsTestParams
9099
.testParams(LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class)));
91100

92-
if(RedisDetector.isClusterAvailable()) {
101+
if (RedisDetector.isClusterAvailable()) {
93102
params.addAll(AbstractOperationsTestParams
94103
.testParams(LettuceConnectionFactoryExtension.getConnectionFactory(RedisCluster.class)));
95104
}
@@ -305,7 +314,8 @@ void readShouldReadSimpleMessage() {
305314
RecordId messageId1 = streamOps.add(StreamRecords.objectBacked(value).withStreamKey(key));
306315
streamOps.add(StreamRecords.objectBacked(value).withStreamKey(key));
307316

308-
List<ObjectRecord<K, HV>> messages = streamOps.read((Class<HV>) value.getClass(), StreamOffset.create(key, ReadOffset.from("0-0")));
317+
List<ObjectRecord<K, HV>> messages = streamOps.read((Class<HV>) value.getClass(),
318+
StreamOffset.create(key, ReadOffset.from("0-0")));
309319

310320
assertThat(messages).hasSize(2);
311321

@@ -384,8 +394,7 @@ void pendingShouldReadMessageSummary() {
384394
RecordId messageId = streamOps.add(key, Collections.singletonMap(hashKey, value));
385395
streamOps.createGroup(key, ReadOffset.from("0-0"), "my-group");
386396

387-
streamOps.read(Consumer.from("my-group", "my-consumer"),
388-
StreamOffset.create(key, ReadOffset.lastConsumed()));
397+
streamOps.read(Consumer.from("my-group", "my-consumer"), StreamOffset.create(key, ReadOffset.lastConsumed()));
389398

390399
PendingMessagesSummary pending = streamOps.pending(key, "my-group");
391400

@@ -403,8 +412,7 @@ void pendingShouldReadMessageDetails() {
403412
RecordId messageId = streamOps.add(key, Collections.singletonMap(hashKey, value));
404413
streamOps.createGroup(key, ReadOffset.from("0-0"), "my-group");
405414

406-
streamOps.read(Consumer.from("my-group", "my-consumer"),
407-
StreamOffset.create(key, ReadOffset.lastConsumed()));
415+
streamOps.read(Consumer.from("my-group", "my-consumer"), StreamOffset.create(key, ReadOffset.lastConsumed()));
408416

409417
PendingMessages pending = streamOps.pending(key, "my-group", Range.unbounded(), 10L);
410418

0 commit comments

Comments
 (0)