james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [14/15] james-project git commit: JAMES-2255 Remove Number::fromInt
Date Fri, 05 Jan 2018 09:17:40 GMT
JAMES-2255 Remove Number::fromInt

Last JMAP specification do not specify it anymore. It leads to some code simplification.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/aebb2d2c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/aebb2d2c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/aebb2d2c

Branch: refs/heads/master
Commit: aebb2d2cdd6f8a5b94992d06170ae6f5888e3fee
Parents: 5708237
Author: benwa <btellier@linagora.com>
Authored: Mon Dec 18 18:33:48 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 16:11:46 2018 +0700

----------------------------------------------------------------------
 .../james/jmap/model/FilterCondition.java       |  8 +--
 .../org/apache/james/jmap/model/Number.java     | 14 ------
 .../org/apache/james/jmap/model/NumberTest.java | 52 ++++----------------
 3 files changed, 13 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/aebb2d2c/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
index 6b6cd43..02f7657 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
@@ -117,13 +117,13 @@ public class FilterCondition implements Filter {
             return this;
         }
 
-        public Builder minSize(int minSize) {
-            this.minSize = Number.fromInt(minSize);
+        public Builder minSize(long minSize) {
+            this.minSize = Number.fromLong(minSize);
             return this;
         }
 
-        public Builder maxSize(int maxSize) {
-            this.maxSize = Number.fromInt(maxSize);
+        public Builder maxSize(long maxSize) {
+            this.maxSize = Number.fromLong(maxSize);
             return this;
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebb2d2c/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
index d4fc286..98a73ce 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
@@ -47,14 +47,6 @@ public class Number {
         return new Number(value);
     }
 
-    public static Number fromOutboundInt(int value) {
-        if (value < ZERO_VALUE) {
-            LOGGER.warn("Received a negative Number");
-            return new Number(ZERO_VALUE);
-        }
-        return new Number(value);
-    }
-
     public static Number fromOutboundLong(long value) {
         if (value < ZERO_VALUE) {
             LOGGER.warn("Received a negative Number");
@@ -77,12 +69,6 @@ public class Number {
         this.value = value;
     }
 
-    public Number ensureLessThan(long maxValue) {
-        Preconditions.checkState(value >= ZERO_VALUE && value <= maxValue,
-            "value should be positive and less than " + maxValue + " or empty");
-        return new Number(value);
-    }
-
     @JsonValue
     public long asLong() {
         return value;

http://git-wip-us.apache.org/repos/asf/james-project/blob/aebb2d2c/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
index 06119ff..59ab9a7 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
@@ -26,28 +26,15 @@ import org.junit.Test;
 
 public class NumberTest {
     @Test
-    public void fromIntShouldReturnMinValueWhenNegativeValueWithLenient() throws Exception
{
-        assertThat(Number.fromOutboundLong(-1))
-            .isEqualTo(Number.ZERO);
-    }
-
-    @Test
     public void fromLongShouldReturnMinValueWhenNegativeValueWithLenient() throws Exception
{
         assertThat(Number.fromOutboundLong(-1))
             .isEqualTo(Number.ZERO);
     }
 
     @Test
-    public void fromIntShouldThrowWhenNegativeValueWithStrict() throws Exception {
-        assertThatThrownBy(() ->
-            Number.fromInt(-1))
-            .isInstanceOf(IllegalStateException.class);
-    }
-
-    @Test
-    public void fromIntShouldReturnIntegerValue() throws Exception {
-        assertThat(Number.fromInt(1).asLong())
-            .isEqualTo(1);
+    public void fromOutboundLongShouldSanitizeTooBigNumbers() throws Exception {
+        assertThat(Number.fromOutboundLong(Number.MAX_VALUE  + 1))
+            .isEqualTo(Number.MAX_VALUE);
     }
 
     @Test
@@ -65,36 +52,15 @@ public class NumberTest {
     }
 
     @Test
-    public void fromLongShouldReturnLongValue() throws Exception {
-        assertThat(Number.fromLong(1).asLong())
-            .isEqualTo(1);
-    }
-
-    @Test
-    public void ensureLessThanShouldThrowWhenOverSpecifiedValue() throws Exception {
-        assertThatThrownBy(() ->
-            Number.fromInt(11).ensureLessThan(10))
-            .isInstanceOf(IllegalStateException.class);
-    }
-
-    @Test
-    public void ensureLessThanShouldReturnNumberWhenEqualValue() throws Exception {
-        Number number = Number.fromInt(10);
-        assertThat(number.ensureLessThan(10))
-            .isEqualTo(number);
+    public void fromLongShouldReturnValueWhenZero() throws Exception {
+        assertThat(Number.fromLong(0).asLong())
+            .isEqualTo(0);
     }
 
     @Test
-    public void ensureLessThanShouldReturnNumberWhenLessThanMaxValue() throws Exception {
-        Number number = Number.fromInt(10);
-        assertThat(number.ensureLessThan(11))
-            .isEqualTo(number);
+    public void fromLongShouldReturnValueWhenMaxValue() throws Exception {
+        assertThat(Number.fromLong(Number.MAX_VALUE).asLong())
+            .isEqualTo(Number.MAX_VALUE);
     }
 
-    @Test
-    public void fromIntShouldThrowWhenOver2Pow31Value() throws Exception {
-        assertThatThrownBy(() ->
-            Number.fromInt(Integer.MAX_VALUE + 1))
-            .isInstanceOf(IllegalStateException.class);
-    }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message