From 614877b5f99d95bfe992efc0ff68aae31fa05b3f Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 18 Dec 2017 15:40:53 +0100 Subject: [PATCH] Polishing #671 --- .../java/com/lambdaworks/redis/ReadFrom.java | 3 ++- .../redis/cluster/ReadFromTest.java | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/lambdaworks/redis/ReadFrom.java b/src/main/java/com/lambdaworks/redis/ReadFrom.java index 53e729495a..04cd94193a 100644 --- a/src/main/java/com/lambdaworks/redis/ReadFrom.java +++ b/src/main/java/com/lambdaworks/redis/ReadFrom.java @@ -23,6 +23,7 @@ * Defines from which Redis nodes data is read. * * @author Mark Paluch + * @author Ryosuke Hasebe * @since 4.0 */ public abstract class ReadFrom { @@ -70,6 +71,7 @@ public abstract class ReadFrom { * @throws IllegalArgumentException if {@code name} is empty, {@literal null} or the {@link ReadFrom} preset is unknown. */ public static ReadFrom valueOf(String name) { + if (LettuceStrings.isEmpty(name)) { throw new IllegalArgumentException("Name must not be empty"); } @@ -110,5 +112,4 @@ public interface Nodes extends Iterable { */ List getNodes(); } - } diff --git a/src/test/java/com/lambdaworks/redis/cluster/ReadFromTest.java b/src/test/java/com/lambdaworks/redis/cluster/ReadFromTest.java index 3637c7f28c..4dd2e236e4 100644 --- a/src/test/java/com/lambdaworks/redis/cluster/ReadFromTest.java +++ b/src/test/java/com/lambdaworks/redis/cluster/ReadFromTest.java @@ -31,6 +31,7 @@ /** * @author Mark Paluch + * @author Ryosuke Hasebe */ public class ReadFromTest { @@ -40,7 +41,7 @@ public class ReadFromTest { private RedisClusterNode slave = new RedisClusterNode(); @Before - public void before() throws Exception { + public void before() { master.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.MASTER)); nearest.setFlags(Collections.singleton(RedisClusterNode.NodeFlag.SLAVE)); @@ -52,67 +53,67 @@ public void before() throws Exception { } @Test - public void master() throws Exception { + public void master() { List result = ReadFrom.MASTER.select(getNodes()); assertThat(result).hasSize(1).containsOnly(master); } @Test - public void masterPreferred() throws Exception { + public void masterPreferred() { List result = ReadFrom.MASTER_PREFERRED.select(getNodes()); assertThat(result).hasSize(3).containsExactly(master, nearest, slave); } @Test - public void slave() throws Exception { + public void slave() { List result = ReadFrom.SLAVE.select(getNodes()); assertThat(result).hasSize(2).contains(nearest, slave); } @Test - public void slavePreferred() throws Exception { + public void slavePreferred() { List result = ReadFrom.SLAVE_PREFERRED.select(getNodes()); assertThat(result).hasSize(3).containsExactly(nearest, slave, master); } @Test - public void nearest() throws Exception { + public void nearest() { List result = ReadFrom.NEAREST.select(getNodes()); assertThat(result).hasSize(3).containsExactly(nearest, master, slave); } @Test(expected = IllegalArgumentException.class) - public void valueOfNull() throws Exception { + public void valueOfNull() { ReadFrom.valueOf(null); } @Test(expected = IllegalArgumentException.class) - public void valueOfUnknown() throws Exception { + public void valueOfUnknown() { ReadFrom.valueOf("unknown"); } @Test - public void valueOfNearest() throws Exception { + public void valueOfNearest() { assertThat(ReadFrom.valueOf("nearest")).isEqualTo(ReadFrom.NEAREST); } @Test - public void valueOfMaster() throws Exception { + public void valueOfMaster() { assertThat(ReadFrom.valueOf("master")).isEqualTo(ReadFrom.MASTER); } @Test - public void valueOfMasterPreferred() throws Exception { + public void valueOfMasterPreferred() { assertThat(ReadFrom.valueOf("masterPreferred")).isEqualTo(ReadFrom.MASTER_PREFERRED); } @Test - public void valueOfSlave() throws Exception { + public void valueOfSlave() { assertThat(ReadFrom.valueOf("slave")).isEqualTo(ReadFrom.SLAVE); } @Test - public void valueOfSlavePreferred() throws Exception { + public void valueOfSlavePreferred() { assertThat(ReadFrom.valueOf("slavePreferred")).isEqualTo(ReadFrom.SLAVE_PREFERRED); }