Skip to content

Commit

Permalink
migrate to assertj
Browse files Browse the repository at this point in the history
  • Loading branch information
atakavci committed Apr 5, 2024
1 parent b26e244 commit 5616087
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> commandBuilder;

private final RedisCodec<String, String> codec = StringCodec.UTF8;

@BeforeEach
Expand All @@ -33,108 +34,109 @@ void publish() {
String message = "message payload";
Command<String, String, Long> command = this.commandBuilder.publish(channel, message);

assertEquals( PUBLISH, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "key<channel> value<message payload>", 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<channel> value<message payload>");
assertThat(command.getOutput()).isInstanceOf(IntegerOutput.class);
}

@Test
void pubsubChannels() {
String pattern = "channelPattern";
Command<String, String, List<String>> command = this.commandBuilder.pubsubChannels(pattern);

assertEquals( PUBSUB, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "CHANNELS key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(KeyListOutput.class);
}

@Test
void pubsubNumsub() {
String pattern = "channelPattern";
Command<String, String, Map<String, Long>> command = this.commandBuilder.pubsubNumsub(pattern);

assertEquals( PUBSUB, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "NUMSUB key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(MapOutput.class);
}

@Test
void pubsubShardChannels() {
String pattern = "channelPattern";
Command<String, String, List<String>> command = this.commandBuilder.pubsubShardChannels(pattern);

assertEquals( PUBSUB, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "SHARDCHANNELS key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(KeyListOutput.class);
}

@Test
void pubsubShardNumsub() {
String pattern = "channelPattern";
Command<String, String, Map<String, Long>> command = this.commandBuilder.pubsubShardNumsub(pattern);

assertEquals( PUBSUB, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "SHARDNUMSUB key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(MapOutput.class);
}

@Test
void psubscribe() {
String pattern = "channelPattern";
Command<String, String, String> command = this.commandBuilder.psubscribe(pattern);

assertEquals( PSUBSCRIBE, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class);
}

@Test
void punsubscribe() {
String pattern = "channelPattern";
Command<String, String, String> command = this.commandBuilder.punsubscribe(pattern);

assertEquals( PUNSUBSCRIBE, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class);
}

@Test
void subscribe() {
String pattern = "channelPattern";
Command<String, String, String> command = this.commandBuilder.subscribe(pattern);

assertEquals( SUBSCRIBE, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class);
}

@Test
void unsubscribe() {
String pattern = "channelPattern";
Command<String, String, String> command = this.commandBuilder.unsubscribe(pattern);

assertEquals( UNSUBSCRIBE, command.getType());
assertInstanceOf(PubSubCommandArgs.class, command.getArgs());
assertEquals( "key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class);
}

@Test
void ssubscribe() {
String channel = "channelPattern";
Command<String, String, String> command = this.commandBuilder.ssubscribe(channel);

assertEquals( SSUBSCRIBE, command.getType());
assertInstanceOf(CommandArgs.class, command.getArgs());
assertEquals( "key<channelPattern>", 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<channelPattern>");
assertThat(command.getOutput()).isInstanceOf(PubSubOutput.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
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;

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 {
Expand All @@ -42,9 +43,9 @@ void psubscribe() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -60,9 +61,9 @@ void punsubscribe() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -78,9 +79,9 @@ void subscribe() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -96,9 +97,9 @@ void unsubscribe() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -116,9 +117,9 @@ void publish() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<acmeChannel> value<acmeMessage>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key<acmeChannel> value<acmeMessage>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -135,9 +136,9 @@ void pubsubChannels() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("CHANNELS key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -154,9 +155,9 @@ void pubsubNumsub() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("NUMSUB key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -173,9 +174,9 @@ void pubsubShardChannels() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("SHARDCHANNELS key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -192,9 +193,9 @@ void pubsubShardNumsub() throws ExecutionException, InterruptedException {
ArgumentCaptor<AsyncCommand> 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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("SHARDNUMSUB key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand All @@ -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<channelPattern>", capturedCommand.getValue().getArgs().toCommandString());
assertThat(capturedCommand.getValue().getArgs().toCommandString()).isEqualTo("key<channelPattern>");

assertNotEquals(capturedCommand.getValue(), dispachedMock);
}
Expand Down

0 comments on commit 5616087

Please sign in to comment.