FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

asShort in ImmutableLongValueImpl should check isInShortRange by mecp · Pull Request #287 · msgpack/msgpack-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) .scala  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public byte asByte()
@Override
public short asShort()
{
if (!isInByteRange()) {
if (!isInShortRange()) {
throw new MessageIntegerOverflowException(value);
}
return (short) value;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.msgpack.value

import java.math.BigInteger

import org.msgpack.core._

import scala.util.parsing.json.JSON
Expand Down Expand Up @@ -97,5 +96,35 @@ class ValueTest extends MessagePackSpec

}

"check appropriate range for integers" in {
import ValueFactory._
import java.lang.Byte
import java.lang.Short

newInteger(Byte.MAX_VALUE).asByte() shouldBe Byte.MAX_VALUE
newInteger(Byte.MIN_VALUE).asByte() shouldBe Byte.MIN_VALUE
newInteger(Short.MAX_VALUE).asShort() shouldBe Short.MAX_VALUE
newInteger(Short.MIN_VALUE).asShort() shouldBe Short.MIN_VALUE
newInteger(Integer.MAX_VALUE).asInt() shouldBe Integer.MAX_VALUE
newInteger(Integer.MIN_VALUE).asInt() shouldBe Integer.MIN_VALUE
intercept[MessageIntegerOverflowException] {
newInteger(Byte.MAX_VALUE+1).asByte()
}
intercept[MessageIntegerOverflowException] {
newInteger(Byte.MIN_VALUE-1).asByte()
}
intercept[MessageIntegerOverflowException] {
newInteger(Short.MAX_VALUE+1).asShort()
}
intercept[MessageIntegerOverflowException] {
newInteger(Short.MIN_VALUE-1).asShort()
}
intercept[MessageIntegerOverflowException] {
newInteger(Integer.MAX_VALUE+1.toLong).asInt()
}
intercept[MessageIntegerOverflowException] {
newInteger(Integer.MIN_VALUE-1.toLong).asInt()
}
}
}
}

Back | FazBrowse Home | New Git URL