diff --git a/src/test/java/io/lettuce/core/pubsub/PubSubCommandBuilderUnitTests.java b/src/test/java/io/lettuce/core/pubsub/PubSubCommandBuilderUnitTests.java index 8e8d37b4c3..4d4e798187 100644 --- a/src/test/java/io/lettuce/core/pubsub/PubSubCommandBuilderUnitTests.java +++ b/src/test/java/io/lettuce/core/pubsub/PubSubCommandBuilderUnitTests.java @@ -15,11 +15,12 @@ import java.util.Map; import static io.lettuce.core.protocol.CommandType.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; class PubSubCommandBuilderUnitTests { private PubSubCommandBuilder commandBuilder; + private final RedisCodec codec = StringCodec.UTF8; @BeforeEach @@ -33,10 +34,10 @@ void publish() { String message = "message payload"; Command command = this.commandBuilder.publish(channel, message); - assertEquals( PUBLISH, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "key value", command.getArgs().toCommandString()); - assertInstanceOf(IntegerOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PUBLISH); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("key value"); + assertThat(command.getOutput()).isInstanceOf(IntegerOutput.class); } @Test @@ -44,10 +45,10 @@ void pubsubChannels() { String pattern = "channelPattern"; Command> command = this.commandBuilder.pubsubChannels(pattern); - assertEquals( PUBSUB, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "CHANNELS key", command.getArgs().toCommandString()); - assertInstanceOf(KeyListOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PUBSUB); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("CHANNELS key"); + assertThat(command.getOutput()).isInstanceOf(KeyListOutput.class); } @Test @@ -55,10 +56,10 @@ void pubsubNumsub() { String pattern = "channelPattern"; Command> command = this.commandBuilder.pubsubNumsub(pattern); - assertEquals( PUBSUB, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "NUMSUB key", command.getArgs().toCommandString()); - assertInstanceOf(MapOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PUBSUB); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("NUMSUB key"); + assertThat(command.getOutput()).isInstanceOf(MapOutput.class); } @Test @@ -66,10 +67,10 @@ void pubsubShardChannels() { String pattern = "channelPattern"; Command> command = this.commandBuilder.pubsubShardChannels(pattern); - assertEquals( PUBSUB, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "SHARDCHANNELS key", command.getArgs().toCommandString()); - assertInstanceOf(KeyListOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PUBSUB); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("SHARDCHANNELS key"); + assertThat(command.getOutput()).isInstanceOf(KeyListOutput.class); } @Test @@ -77,10 +78,10 @@ void pubsubShardNumsub() { String pattern = "channelPattern"; Command> command = this.commandBuilder.pubsubShardNumsub(pattern); - assertEquals( PUBSUB, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "SHARDNUMSUB key", command.getArgs().toCommandString()); - assertInstanceOf(MapOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PUBSUB); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("SHARDNUMSUB key"); + assertThat(command.getOutput()).isInstanceOf(MapOutput.class); } @Test @@ -88,10 +89,10 @@ void psubscribe() { String pattern = "channelPattern"; Command command = this.commandBuilder.psubscribe(pattern); - assertEquals( PSUBSCRIBE, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "key", command.getArgs().toCommandString()); - assertInstanceOf(PubSubOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PSUBSCRIBE); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("key"); + assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class); } @Test @@ -99,10 +100,10 @@ void punsubscribe() { String pattern = "channelPattern"; Command command = this.commandBuilder.punsubscribe(pattern); - assertEquals( PUNSUBSCRIBE, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "key", command.getArgs().toCommandString()); - assertInstanceOf(PubSubOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(PUNSUBSCRIBE); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("key"); + assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class); } @Test @@ -110,10 +111,10 @@ void subscribe() { String pattern = "channelPattern"; Command command = this.commandBuilder.subscribe(pattern); - assertEquals( SUBSCRIBE, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "key", command.getArgs().toCommandString()); - assertInstanceOf(PubSubOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(SUBSCRIBE); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("key"); + assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class); } @Test @@ -121,10 +122,10 @@ void unsubscribe() { String pattern = "channelPattern"; Command command = this.commandBuilder.unsubscribe(pattern); - assertEquals( UNSUBSCRIBE, command.getType()); - assertInstanceOf(PubSubCommandArgs.class, command.getArgs()); - assertEquals( "key", command.getArgs().toCommandString()); - assertInstanceOf(PubSubOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(UNSUBSCRIBE); + assertThat(command.getArgs()).isInstanceOf(PubSubCommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("key"); + assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class); } @Test @@ -132,9 +133,10 @@ void ssubscribe() { String channel = "channelPattern"; Command command = this.commandBuilder.ssubscribe(channel); - assertEquals( SSUBSCRIBE, command.getType()); - assertInstanceOf(CommandArgs.class, command.getArgs()); - assertEquals( "key", command.getArgs().toCommandString()); - assertInstanceOf(PubSubOutput.class, command.getOutput()); + assertThat(command.getType()).isEqualTo(SSUBSCRIBE); + assertThat(command.getArgs()).isInstanceOf(CommandArgs.class); + assertThat(command.getArgs().toCommandString()).isEqualTo("key"); + assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class); } + } diff --git a/src/test/java/io/lettuce/core/pubsub/RedisPubSubAsyncCommandsImplUnitTests.java b/src/test/java/io/lettuce/core/pubsub/RedisPubSubAsyncCommandsImplUnitTests.java index 17f159276e..8eebf685fa 100644 --- a/src/test/java/io/lettuce/core/pubsub/RedisPubSubAsyncCommandsImplUnitTests.java +++ b/src/test/java/io/lettuce/core/pubsub/RedisPubSubAsyncCommandsImplUnitTests.java @@ -7,7 +7,6 @@ import io.lettuce.core.output.MapOutput; import io.lettuce.core.protocol.AsyncCommand; import io.lettuce.core.protocol.RedisCommand; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -15,8 +14,10 @@ import java.util.concurrent.ExecutionException; import static io.lettuce.core.protocol.CommandType.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; class RedisPubSubAsyncCommandsImplUnitTests { @@ -42,9 +43,9 @@ void psubscribe() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PSUBSCRIBE, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PSUBSCRIBE); assertInstanceOf(PubSubOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -60,9 +61,9 @@ void punsubscribe() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PUNSUBSCRIBE, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PUNSUBSCRIBE); assertInstanceOf(PubSubOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -78,9 +79,9 @@ void subscribe() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( SUBSCRIBE, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(SUBSCRIBE); assertInstanceOf(PubSubOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -96,9 +97,9 @@ void unsubscribe() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( UNSUBSCRIBE, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(UNSUBSCRIBE); assertInstanceOf(PubSubOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -116,9 +117,9 @@ void publish() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PUBLISH, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PUBLISH); assertInstanceOf(IntegerOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "key value", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key value"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -135,9 +136,9 @@ void pubsubChannels() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PUBSUB, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PUBSUB); assertInstanceOf(KeyListOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "CHANNELS key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("CHANNELS key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -154,9 +155,9 @@ void pubsubNumsub() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PUBSUB, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PUBSUB); assertInstanceOf(MapOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "NUMSUB key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("NUMSUB key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -173,9 +174,9 @@ void pubsubShardChannels() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PUBSUB, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PUBSUB); assertInstanceOf(KeyListOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "SHARDCHANNELS key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("SHARDCHANNELS key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -192,9 +193,9 @@ void pubsubShardNumsub() throws ExecutionException, InterruptedException { ArgumentCaptor capturedCommand = ArgumentCaptor.forClass(AsyncCommand.class);; verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals( PUBSUB, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(PUBSUB); assertInstanceOf(MapOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals( "SHARDNUMSUB key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("SHARDNUMSUB key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); } @@ -211,9 +212,9 @@ void ssubscribe() throws ExecutionException, InterruptedException { verify(mockedConnection).dispatch(capturedCommand.capture()); - Assertions.assertEquals(SSUBSCRIBE, capturedCommand.getValue().getType()); + assertThat(capturedCommand.getValue().getType()).isEqualTo(SSUBSCRIBE); assertInstanceOf(PubSubOutput.class, capturedCommand.getValue().getOutput()); - Assertions.assertEquals("key", capturedCommand.getValue().getArgs().toCommandString()); + assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key"); assertNotEquals(capturedCommand.getValue(), dispachedMock); }