jhutchison commented on a change in pull request #6119:
URL: https://github.com/apache/geode/pull/6119#discussion_r593269453



##########
File path: 
geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractDecrByIntegrationTest.java
##########
@@ -50,48 +52,99 @@ public void tearDown() {
   }
 
   @Test
-  public void decrBy_errors_givenWrongNumberOfArguments() {
-    assertExactNumberOfArgs(jedis, Protocol.Command.DECRBY, 2);
+  public void shouldDecrementByGivenAmount_givenValidInputsAndKey() {
+    String key1 = "key1";
+    jedis.set(key1, "100");
+    jedis.decrBy(key1, 10);
+    String result = jedis.get(key1);
+    assertThat(Integer.parseInt(result)).isEqualTo(90);
+
+    jedis.set(key1, "100");
+    jedis.decrBy(key1, -10);
+    result = jedis.get(key1);
+    assertThat(Integer.parseInt(result)).isEqualTo(110);
+
+    String key2 = "key2";
+    jedis.set(key2, "-100");
+    jedis.decrBy(key2, 10);
+    result = jedis.get(key2);
+    assertThat(Integer.parseInt(result)).isEqualTo(-110);
+
+    jedis.set(key2, "-100");
+    jedis.decrBy(key2, -10);
+    result = jedis.get(key2);
+    assertThat(Integer.parseInt(result)).isEqualTo(-90);
   }
 
   @Test
-  public void testDecrBy() {
-    String key1 = randString();
-    String key2 = randString();
-    String key3 = randString();
-    int decr1 = rand.nextInt(100);
-    int decr2 = rand.nextInt(100);
-    Long decr3 = Long.MAX_VALUE / 2;
-    int num1 = 100;
-    int num2 = -100;
-    jedis.set(key1, "" + num1);
-    jedis.set(key2, "" + num2);
-    jedis.set(key3, "" + Long.MIN_VALUE);
-
-    jedis.decrBy(key1, decr1);
-    jedis.decrBy(key2, decr2);
-
-    assertThat(jedis.get(key1)).isEqualTo("" + (num1 - decr1 * 1));
-    assertThat(jedis.get(key2)).isEqualTo("" + (num2 - decr2 * 1));
-
-    Exception ex = null;
-    try {
-      jedis.decrBy(key3, decr3);
-    } catch (Exception e) {
-      ex = e;
-    }
-    assertThat(ex).isNotNull();
+  public void should_returnNewValue_givenSuccessfulDecrby() {
+    jedis.set("key", "100");
+    Long decrByresult = jedis.decrBy("key", 50);
+
+    String getResult = jedis.get("key");
+
+    assertThat(decrByresult).isEqualTo(Long.valueOf(getResult)).isEqualTo(50l);
+  }
+
+
+  @Test
+  public void should_setKeyToZeroAndThenDecrement_givenKeyThatDoesNotExist() {
+
+    Long returnValue = jedis.decrBy("noneSuch", 10);
+    assertThat(returnValue).isEqualTo(-10);
+
+  }
+
+  @Test
+  public void shouldThrowError_givenWrongNumberOfArguments() {
+    assertExactNumberOfArgs(jedis, Protocol.Command.DECRBY, 2);
   }
 
   @Test
   public void decrbyMoreThanMaxLongThrowsArithmeticException() {
     jedis.set("somekey", "1");
+
+    BigInteger maxLongValue = new BigInteger(String.valueOf(Long.MAX_VALUE));
+    BigInteger biggerThanMinLongValue = maxLongValue.add(new BigInteger("1"));

Review comment:
       yes it should.  thanks.  changed.




----------------------------------------------------------------
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:
[email protected]


Reply via email to