Skip to content

Commit

Permalink
Fix transaction failure tests using mock (#3683)
Browse files Browse the repository at this point in the history
Now we have to mock Protocol#read(RedisInputStream, ClientSideCache) instead of Protocol#read(RedisInputStream).
  • Loading branch information
sazzad16 authored Jan 11, 2024
1 parent 6d4930f commit fca975f
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.Assert.*;

import static org.mockito.ArgumentMatchers.any;
import static redis.clients.jedis.Protocol.Command.INCR;
import static redis.clients.jedis.Protocol.Command.GET;
import static redis.clients.jedis.Protocol.Command.SET;
Expand All @@ -15,6 +14,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

Expand Down Expand Up @@ -159,7 +159,9 @@ public void discardFail() {
trans.set("b", "b");

try (MockedStatic<Protocol> protocol = Mockito.mockStatic(Protocol.class)) {
protocol.when(() -> Protocol.read(any())).thenThrow(JedisConnectionException.class);
//protocol.when(() -> Protocol.read(any())).thenThrow(JedisConnectionException.class);
protocol.when(() -> Protocol.read(ArgumentMatchers.any(), ArgumentMatchers.isNull()))
.thenThrow(JedisConnectionException.class);

trans.discard();
fail("Should get mocked JedisConnectionException.");
Expand All @@ -179,7 +181,9 @@ public void execFail() {
trans.set("b", "b");

try (MockedStatic<Protocol> protocol = Mockito.mockStatic(Protocol.class)) {
protocol.when(() -> Protocol.read(any())).thenThrow(JedisConnectionException.class);
//protocol.when(() -> Protocol.read(any())).thenThrow(JedisConnectionException.class);
protocol.when(() -> Protocol.read(ArgumentMatchers.any(), ArgumentMatchers.isNull()))
.thenThrow(JedisConnectionException.class);

trans.exec();
fail("Should get mocked JedisConnectionException.");
Expand Down

0 comments on commit fca975f

Please sign in to comment.