You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/06/17 14:19:24 UTC

[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #5262: GEODE-8269: Improve test coverage

jdeppe-pivotal commented on a change in pull request #5262:
URL: https://github.com/apache/geode/pull/5262#discussion_r441579410



##########
File path: geode-redis/src/test/java/org/apache/geode/redis/internal/executor/key/ExpireAtExecutorJUnitTest.java
##########
@@ -34,30 +37,30 @@
 
   @Test
   public void calledWithTooFewCommandArguments_returnsError() {
-    List<byte[]> commandsAsBytesWithTooFewArguments = new ArrayList<>();
-    commandsAsBytesWithTooFewArguments.add("EXPIREAT".getBytes());
-    commandsAsBytesWithTooFewArguments.add("key".getBytes());
-    Command command = new Command(commandsAsBytesWithTooFewArguments);
+    List<byte[]> commandAsBytes = new ArrayList<>();
+    commandAsBytes.add("EXPIREAT".getBytes());
+    commandAsBytes.add("key".getBytes());
+    Command command = new Command(commandAsBytes);
 
-    RedisResponse response =
-        new ExpireAtExecutor().executeCommand(command, mockContext());
+    Throwable thrown = catchThrowable(() -> command.execute(mockContext()));
 
-    assertThat(response.toString()).startsWith("-ERR The wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).hasMessageContaining("wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).isInstanceOf(RedisParametersMismatchException.class);
   }
 
   @Test
   public void calledWithTooManyCommandArguments_returnsError() {
-    List<byte[]> commandsAsBytesWithTooFewArguments = new ArrayList<>();
-    commandsAsBytesWithTooFewArguments.add("EXPIREAT".getBytes());
-    commandsAsBytesWithTooFewArguments.add("key".getBytes());
-    commandsAsBytesWithTooFewArguments.add("1".getBytes());
-    commandsAsBytesWithTooFewArguments.add("extra-argument".getBytes());
-    Command command = new Command(commandsAsBytesWithTooFewArguments);
+    List<byte[]> commandsAsBytes = new ArrayList<>();
+    commandsAsBytes.add("EXPIREAT".getBytes());
+    commandsAsBytes.add("key".getBytes());
+    commandsAsBytes.add("1".getBytes());
+    commandsAsBytes.add("extra-argument".getBytes());
+    Command command = new Command(commandsAsBytes);
 
-    RedisResponse response =
-        new ExpireAtExecutor().executeCommand(command, mockContext());
+    Throwable thrown = catchThrowable(() -> command.execute(mockContext()));
 
-    assertThat(response.toString()).startsWith("-ERR The wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).hasMessageContaining("wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).isInstanceOf(RedisParametersMismatchException.class);

Review comment:
       Maybe the same thing, but at least for consistency, `assertThat` should come from the `org.assertj.core.api.Assertions` package.

##########
File path: geode-redis/src/test/java/org/apache/geode/redis/internal/executor/key/KeysExecutorJUnitTest.java
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.geode.redis.internal.executor.key;
+
+import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import io.netty.buffer.UnpooledByteBufAllocator;
+import org.assertj.core.api.AssertionsForClassTypes;
+import org.junit.Test;
+
+import org.apache.geode.redis.internal.ParameterRequirements.RedisParametersMismatchException;
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+
+public class KeysExecutorJUnitTest {
+
+  @Test
+  public void calledWithTooFewOptions_returnsError() {
+    List<byte[]> commandsAsBytes = new ArrayList<>();
+    commandsAsBytes.add("KEYS".getBytes());
+    Command command = new Command(commandsAsBytes);
+
+    Throwable thrown = catchThrowable(() -> command.execute(mockContext()));
+
+    AssertionsForClassTypes.assertThat(thrown).hasMessageContaining("wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).isInstanceOf(RedisParametersMismatchException.class);
+  }
+
+  @Test
+  public void calledWithTooManyOptions_returnsError() {
+    List<byte[]> commandsAsBytes = new ArrayList<>();
+    commandsAsBytes.add("KEYS".getBytes());
+    commandsAsBytes.add("*".getBytes());
+    commandsAsBytes.add("**".getBytes());
+    Command command = new Command(commandsAsBytes);
+
+    Throwable thrown = catchThrowable(() -> command.execute(mockContext()));
+
+    AssertionsForClassTypes.assertThat(thrown).hasMessageContaining("wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).isInstanceOf(RedisParametersMismatchException.class);

Review comment:
       Ditto previous comment

##########
File path: geode-redis/src/test/java/org/apache/geode/redis/internal/executor/key/ExpireAtExecutorJUnitTest.java
##########
@@ -34,30 +37,30 @@
 
   @Test
   public void calledWithTooFewCommandArguments_returnsError() {
-    List<byte[]> commandsAsBytesWithTooFewArguments = new ArrayList<>();
-    commandsAsBytesWithTooFewArguments.add("EXPIREAT".getBytes());
-    commandsAsBytesWithTooFewArguments.add("key".getBytes());
-    Command command = new Command(commandsAsBytesWithTooFewArguments);
+    List<byte[]> commandAsBytes = new ArrayList<>();
+    commandAsBytes.add("EXPIREAT".getBytes());
+    commandAsBytes.add("key".getBytes());
+    Command command = new Command(commandAsBytes);
 
-    RedisResponse response =
-        new ExpireAtExecutor().executeCommand(command, mockContext());
+    Throwable thrown = catchThrowable(() -> command.execute(mockContext()));

Review comment:
       Can this be a `assertThatThrownBy` assertion?

##########
File path: geode-redis/src/test/java/org/apache/geode/redis/internal/executor/key/ExpireExecutorJUnitTest.java
##########
@@ -35,42 +37,41 @@
 
   @Test
   public void calledWithTooFewCommandArguments_returnsError() {
-    Executor executor = new ExpireExecutor();
-    List<byte[]> commandsAsBytesWithTooFewArguments = new ArrayList<>();
-    commandsAsBytesWithTooFewArguments.add("EXPIRE".getBytes());
-    commandsAsBytesWithTooFewArguments.add("key".getBytes());
+    List<byte[]> commandsAsBytes = new ArrayList<>();
+    commandsAsBytes.add("EXPIRE".getBytes());
+    commandsAsBytes.add("key".getBytes());
+    Command command = new Command(commandsAsBytes);
 
-    Command command = new Command(commandsAsBytesWithTooFewArguments);
-    RedisResponse response = executor.executeCommand(command, mockContext());
+    Throwable thrown = catchThrowable(() -> command.execute(mockContext()));
 
-    assertThat(response.toString()).startsWith("-ERR The wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).hasMessageContaining("wrong number of arguments");
+    AssertionsForClassTypes.assertThat(thrown).isInstanceOf(RedisParametersMismatchException.class);

Review comment:
       Ditto previous comment.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org