Skip to content

Commit 485ee1d

Browse files
committed
DATAREDIS-549 - Polishing.
Replace some AtTest(expected = …) and ExpectedException with the corresponding AssertJ assertThatExceptionOfType(…) and assertThatIllegalArgumentException().isThrownBy(…).
1 parent 0205c9c commit 485ee1d

File tree

47 files changed

+628
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+628
-555
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,11 +2289,11 @@ public void pfCountWithMultipleKeysShouldReturnCorrectly() {
22892289
assertThat(results.get(2)).isEqualTo(6L);
22902290
}
22912291

2292-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-308
2292+
@Test // DATAREDIS-308
22932293
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
22942294
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
22952295
public void pfCountWithNullKeysShouldThrowIllegalArgumentException() {
2296-
actual.add(connection.pfCount((String[]) null));
2296+
assertThatIllegalArgumentException().isThrownBy(() -> actual.add(connection.pfCount((String[]) null)));
22972297
}
22982298

22992299
@SuppressWarnings("unchecked")

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,55 +56,53 @@ public void testPubSubWithNamedChannels() throws Exception {}
5656
@Ignore("Pub/Sub not supported while pipelining")
5757
public void testPubSubWithPatterns() throws Exception {}
5858

59-
@Test(expected = RedisPipelineException.class)
59+
@Test
6060
public void testExecWithoutMulti() {
61-
super.testExecWithoutMulti();
61+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testExecWithoutMulti);
6262
}
6363

64-
@Test(expected = RedisPipelineException.class)
64+
@Test
6565
public void testErrorInTx() {
66-
super.testErrorInTx();
66+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testErrorInTx);
6767
}
6868

69-
@Test(expected = RedisPipelineException.class)
70-
public void exceptionExecuteNative() throws Exception {
71-
super.exceptionExecuteNative();
69+
@Test
70+
public void exceptionExecuteNative() {
71+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::exceptionExecuteNative);
7272
}
7373

74-
@Test(expected = RedisPipelineException.class)
74+
@Test
7575
@IfProfileValue(name = "redisVersion", value = "2.6+")
7676
public void testEvalShaNotFound() {
77-
super.testEvalShaNotFound();
77+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testEvalShaNotFound);
7878
}
7979

80-
@Test(expected = RedisPipelineException.class)
80+
@Test
8181
@IfProfileValue(name = "redisVersion", value = "2.6+")
8282
public void testEvalReturnSingleError() {
83-
super.testEvalReturnSingleError();
83+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testEvalReturnSingleError);
8484
}
8585

86-
@Test(expected = RedisPipelineException.class)
86+
@Test
8787
@IfProfileValue(name = "redisVersion", value = "2.6+")
8888
public void testRestoreBadData() {
89-
super.testRestoreBadData();
89+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testRestoreBadData);
9090
}
9191

92-
@Test(expected = RedisPipelineException.class)
92+
@Test
9393
@IfProfileValue(name = "redisVersion", value = "2.6+")
9494
public void testRestoreExistingKey() {
95-
super.testRestoreExistingKey();
95+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testRestoreExistingKey);
9696
}
9797

98-
@Test(expected = RedisPipelineException.class)
99-
@IfProfileValue(name = "redisVersion", value = "2.6+")
100-
public void testEvalArrayScriptError() {
101-
super.testEvalArrayScriptError();
102-
}
98+
@Test
99+
@Ignore
100+
public void testEvalArrayScriptError() {}
103101

104-
@Test(expected = RedisPipelineException.class)
102+
@Test
105103
@IfProfileValue(name = "redisVersion", value = "2.6+")
106104
public void testEvalShaArrayError() {
107-
super.testEvalShaArrayError();
105+
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testEvalShaArrayError);
108106
}
109107

110108
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public void testHashNullKey() throws Exception {}
9494
@Ignore
9595
public void testHashNullValue() throws Exception {}
9696

97-
@Test(expected = UnsupportedOperationException.class)
97+
@Test
9898
public void testWatchWhileInTx() {
99-
connection.watch("foo".getBytes());
99+
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> connection.watch("foo".getBytes()));
100100
}
101101

102102
@Test(expected = UnsupportedOperationException.class)

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,20 @@ public void executeCommandOnSingleNodeByNodeIdShouldBeExecutedCorrectly() {
134134
verify(con2, times(1)).theWheelWeavesAsTheWheelWills();
135135
}
136136

137-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
137+
@Test // DATAREDIS-315
138138
public void executeCommandOnSingleNodeShouldThrowExceptionWhenNodeIsNull() {
139-
executor.executeCommandOnSingleNode(COMMAND_CALLBACK, null);
139+
assertThatIllegalArgumentException().isThrownBy(() -> executor.executeCommandOnSingleNode(COMMAND_CALLBACK, null));
140140
}
141141

142-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
142+
@Test // DATAREDIS-315
143143
public void executeCommandOnSingleNodeShouldThrowExceptionWhenCommandCallbackIsNull() {
144-
executor.executeCommandOnSingleNode(null, CLUSTER_NODE_1);
144+
assertThatIllegalArgumentException().isThrownBy(() -> executor.executeCommandOnSingleNode(null, CLUSTER_NODE_1));
145145
}
146146

147-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
147+
@Test // DATAREDIS-315
148148
public void executeCommandOnSingleNodeShouldThrowExceptionWhenNodeIsUnknown() {
149-
executor.executeCommandOnSingleNode(COMMAND_CALLBACK, UNKNOWN_CLUSTER_NODE);
149+
assertThatIllegalArgumentException()
150+
.isThrownBy(() -> executor.executeCommandOnSingleNode(COMMAND_CALLBACK, UNKNOWN_CLUSTER_NODE));
150151
}
151152

152153
@Test // DATAREDIS-315

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ public void shouldCreateRedisClusterConfigurationCorrectlyGivenMultipleHostAndPo
6060
new RedisNode("localhost", 789));
6161
}
6262

63-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
63+
@Test // DATAREDIS-315
6464
public void shouldThrowExecptionOnInvalidHostAndPortString() {
65-
new RedisClusterConfiguration(Collections.singleton(HOST_AND_NO_PORT));
65+
assertThatIllegalArgumentException()
66+
.isThrownBy(() -> new RedisClusterConfiguration(Collections.singleton(HOST_AND_NO_PORT)));
6667
}
6768

68-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
69+
@Test // DATAREDIS-315
6970
public void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
70-
new RedisClusterConfiguration(Collections.<String> singleton(null));
71+
assertThatIllegalArgumentException()
72+
.isThrownBy(() -> new RedisClusterConfiguration(Collections.<String> singleton(null)));
7173
}
7274

7375
@Test // DATAREDIS-315
@@ -78,9 +80,9 @@ public void shouldNotFailWhenListOfHostAndPortIsEmpty() {
7880
assertThat(config.getClusterNodes().size()).isEqualTo(0);
7981
}
8082

81-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
83+
@Test // DATAREDIS-315
8284
public void shouldThrowExceptionGivenNullPropertySource() {
83-
new RedisClusterConfiguration((PropertySource<?>) null);
85+
assertThatIllegalArgumentException().isThrownBy(() -> new RedisClusterConfiguration((PropertySource<?>) null));
8486
}
8587

8688
@Test // DATAREDIS-315

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ public void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndMultipl
5959
new RedisNode("localhost", 789));
6060
}
6161

62-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-372
62+
@Test // DATAREDIS-372
6363
public void shouldThrowExecptionOnInvalidHostAndPortString() {
64-
new RedisSentinelConfiguration("mymaster", Collections.singleton(HOST_AND_NO_PORT));
64+
assertThatIllegalArgumentException()
65+
.isThrownBy(() -> new RedisSentinelConfiguration("mymaster", Collections.singleton(HOST_AND_NO_PORT)));
6566
}
6667

67-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-372
68+
@Test // DATAREDIS-372
6869
public void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
69-
new RedisSentinelConfiguration("mymaster", Collections.<String> singleton(null));
70+
assertThatIllegalArgumentException()
71+
.isThrownBy(() -> new RedisSentinelConfiguration("mymaster", Collections.<String> singleton(null)));
7072
}
7173

7274
@Test // DATAREDIS-372
@@ -77,9 +79,9 @@ public void shouldNotFailWhenListOfHostAndPortIsEmpty() {
7779
assertThat(config.getSentinels().size()).isEqualTo(0);
7880
}
7981

80-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-372
82+
@Test // DATAREDIS-372
8183
public void shouldThrowExceptionGivenNullPropertySource() {
82-
new RedisSentinelConfiguration((PropertySource<?>) null);
84+
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSentinelConfiguration((PropertySource<?>) null));
8385
}
8486

8587
@Test // DATAREDIS-372

src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ public void bitCountWithRangeShouldWorkCorrectly() {
184184
assertThat(clusterConnection.bitCount(KEY_1_BYTES, 0, 3)).isEqualTo(3L);
185185
}
186186

187-
@Test(expected = DataAccessException.class) // DATAREDIS-315
187+
@Test // DATAREDIS-315
188188
public void bitOpShouldThrowExceptionWhenKeysDoNotMapToSameSlot() {
189-
clusterConnection.bitOp(BitOperation.AND, KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES);
189+
assertThatExceptionOfType(DataAccessException.class)
190+
.isThrownBy(() -> clusterConnection.bitOp(BitOperation.AND, KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES));
190191
}
191192

192193
@Test // DATAREDIS-315
@@ -344,9 +345,9 @@ public void delShouldRemoveSingleKeyCorrectly() {
344345
assertThat(nativeConnection.get(KEY_1)).isNull();
345346
}
346347

347-
@Test(expected = DataAccessException.class) // DATAREDIS-315
348+
@Test // DATAREDIS-315
348349
public void discardShouldThrowException() {
349-
clusterConnection.discard();
350+
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.discard());
350351
}
351352

352353
@Test // DATAREDIS-315
@@ -379,9 +380,9 @@ public void echoShouldReturnInputCorrectly() {
379380
assertThat(clusterConnection.echo(VALUE_1_BYTES)).isEqualTo(VALUE_1_BYTES);
380381
}
381382

382-
@Test(expected = DataAccessException.class) // DATAREDIS-315
383+
@Test // DATAREDIS-315
383384
public void execShouldThrowException() {
384-
clusterConnection.exec();
385+
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.exec());
385386
}
386387

387388
@Test // DATAREDIS-689
@@ -401,9 +402,10 @@ public void executeWithKeyAndArgs() {
401402
assertThat(nativeConnection.get(KEY_1)).isEqualTo(VALUE_1);
402403
}
403404

404-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-689
405+
@Test // DATAREDIS-689
405406
public void executeWithNoKeyAndArgsThrowsException() {
406-
clusterConnection.execute("KEYS", (byte[]) null, Collections.singletonList("*".getBytes()));
407+
assertThatIllegalArgumentException()
408+
.isThrownBy(() -> clusterConnection.execute("KEYS", (byte[]) null, Collections.singletonList("*".getBytes())));
407409
}
408410

409411
@Test // DATAREDIS-529
@@ -1209,14 +1211,15 @@ public void mSetShouldWorkWhenKeysMapToSameSlot() {
12091211
assertThat(nativeConnection.get(SAME_SLOT_KEY_2)).isEqualTo(VALUE_2);
12101212
}
12111213

1212-
@Test(expected = UnsupportedOperationException.class) // DATAREDIS-315
1214+
@Test // DATAREDIS-315
12131215
public void moveShouldNotBeSupported() {
1214-
clusterConnection.move(KEY_1_BYTES, 3);
1216+
assertThatExceptionOfType(UnsupportedOperationException.class)
1217+
.isThrownBy(() -> clusterConnection.move(KEY_1_BYTES, 3));
12151218
}
12161219

1217-
@Test(expected = DataAccessException.class) // DATAREDIS-315
1220+
@Test // DATAREDIS-315
12181221
public void multiShouldThrowException() {
1219-
clusterConnection.multi();
1222+
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.multi());
12201223
}
12211224

12221225
@Test // DATAREDIS-315
@@ -1318,9 +1321,10 @@ public void pfCountShouldThrowErrorCountingOnDifferentSlotKeys() {
13181321
clusterConnection.pfCount(KEY_1_BYTES, KEY_2_BYTES);
13191322
}
13201323

1321-
@Test(expected = DataAccessException.class) // DATAREDIS-315
1324+
@Test // DATAREDIS-315
13221325
public void pfMergeShouldThrowErrorOnDifferentSlotKeys() {
1323-
clusterConnection.pfMerge(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES);
1326+
assertThatExceptionOfType(DataAccessException.class)
1327+
.isThrownBy(() -> clusterConnection.pfMerge(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES));
13241328
}
13251329

13261330
@Test // DATAREDIS-315
@@ -1344,9 +1348,10 @@ public void pingShouldRetrunPongForExistingNode() {
13441348
assertThat(clusterConnection.ping(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()))).isEqualTo("PONG");
13451349
}
13461350

1347-
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
1351+
@Test // DATAREDIS-315
13481352
public void pingShouldThrowExceptionWhenNodeNotKnownToCluster() {
1349-
clusterConnection.ping(new RedisClusterNode("127.0.0.1", 1234, null));
1353+
assertThatIllegalArgumentException()
1354+
.isThrownBy(() -> clusterConnection.ping(new RedisClusterNode("127.0.0.1", 1234, null)));
13501355
}
13511356

13521357
@Test // DATAREDIS-315
@@ -1697,9 +1702,9 @@ public void selectShouldAllowSelectionOfDBIndexZero() {
16971702
clusterConnection.select(0);
16981703
}
16991704

1700-
@Test(expected = DataAccessException.class) // DATAREDIS-315
1705+
@Test // DATAREDIS-315
17011706
public void selectShouldThrowExceptionWhenSelectingNonZeroDbIndex() {
1702-
clusterConnection.select(1);
1707+
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.select(1));
17031708
}
17041709

17051710
@Test // DATAREDIS-315
@@ -1926,14 +1931,14 @@ public void typeShouldReadKeyTypeCorrectly() {
19261931
assertThat(clusterConnection.type(KEY_3_BYTES)).isEqualTo(DataType.HASH);
19271932
}
19281933

1929-
@Test(expected = DataAccessException.class) // DATAREDIS-315
1934+
@Test // DATAREDIS-315
19301935
public void unwatchShouldThrowException() {
1931-
clusterConnection.unwatch();
1936+
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.unwatch());
19321937
}
19331938

1934-
@Test(expected = DataAccessException.class) // DATAREDIS-315
1939+
@Test // DATAREDIS-315
19351940
public void watchShouldThrowException() {
1936-
clusterConnection.watch();
1941+
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> clusterConnection.watch());
19371942
}
19381943

19391944
@Test // DATAREDIS-674
@@ -1988,9 +1993,10 @@ public void zIncrByShouldIncScoreForValueCorrectly() {
19881993
assertThat(nativeConnection.zrank(KEY_1_BYTES, VALUE_1_BYTES)).isEqualTo(1L);
19891994
}
19901995

1991-
@Test(expected = DataAccessException.class) // DATAREDIS-315
1996+
@Test // DATAREDIS-315
19921997
public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
1993-
clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES);
1998+
assertThatExceptionOfType(DataAccessException.class)
1999+
.isThrownBy(() -> clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES));
19942000
}
19952001

19962002
@Test // DATAREDIS-315
@@ -2251,9 +2257,10 @@ public void zScoreShouldRetrieveScoreForValue() {
22512257
assertThat(clusterConnection.zScore(KEY_1_BYTES, VALUE_2_BYTES)).isEqualTo(20D);
22522258
}
22532259

2254-
@Test(expected = DataAccessException.class) // DATAREDIS-315
2260+
@Test // DATAREDIS-315
22552261
public void zUnionStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
2256-
clusterConnection.zUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES);
2262+
assertThatExceptionOfType(DataAccessException.class)
2263+
.isThrownBy(() -> clusterConnection.zUnionStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES));
22572264
}
22582265

22592266
@Test // DATAREDIS-315
@@ -2395,9 +2402,10 @@ public void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
23952402
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
23962403
create().incr(unsigned(2)).valueAt(BitFieldSubCommands.Offset.offset(102L)).overflow(FAIL).by(1L)))
23972404
.containsExactly(3L);
2398-
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
2399-
create().incr(unsigned(2)).valueAt(BitFieldSubCommands.Offset.offset(102L)).overflow(FAIL).by(1L)).get(0))
2400-
.isNull();
2405+
assertThat(clusterConnection.stringCommands()
2406+
.bitField(JedisConverters.toBytes(KEY_1),
2407+
create().incr(unsigned(2)).valueAt(BitFieldSubCommands.Offset.offset(102L)).overflow(FAIL).by(1L))
2408+
.get(0)).isNull();
24012409
}
24022410

24032411
@Test // DATAREDIS-562
@@ -2413,9 +2421,11 @@ public void bitfieldShouldAllowMultipleSubcommands() {
24132421
@IfProfileValue(name = "redisVersion", value = "3.2+")
24142422
public void bitfieldShouldWorkUsingNonZeroBasedOffset() {
24152423

2416-
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
2417-
create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L).multipliedByTypeLength()).to(100L).set(INT_8)
2418-
.valueAt(BitFieldSubCommands.Offset.offset(1L).multipliedByTypeLength()).to(200L))).containsExactly(0L, 0L);
2424+
assertThat(
2425+
clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
2426+
create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L).multipliedByTypeLength()).to(100L)
2427+
.set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(1L).multipliedByTypeLength()).to(200L)))
2428+
.containsExactly(0L, 0L);
24192429
assertThat(
24202430
clusterConnection.stringCommands()
24212431
.bitField(JedisConverters.toBytes(KEY_1),

0 commit comments

Comments
 (0)