1 package net.pterodactylus.sone.utils;
3 import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
4 import static net.pterodactylus.sone.utils.NumberParsers.parseLong;
5 import static org.hamcrest.MatcherAssert.assertThat;
6 import static org.hamcrest.Matchers.is;
7 import static org.hamcrest.Matchers.nullValue;
12 * Unit test for {@link NumberParsers}.
14 public class NumberParsersTest {
17 // yes, this test is for coverage only.
18 public void constructorCanBeCalled() {
23 public void nullIsParsedToDefaultInt() {
24 assertThat(parseInt(null, 17), is(17));
28 public void notANumberIsParsedToDefaultInt() {
29 assertThat(parseInt("not a number", 18), is(18));
33 public void intIsCorrectlyParsed() {
34 assertThat(parseInt("19", 0), is(19));
38 public void valueTooLargeForIntIsParsedToDefault() {
39 assertThat(parseInt("2147483648", 20), is(20));
43 public void valueTooSmallForIntIsParsedToDefault() {
44 assertThat(parseInt("-2147483649", 20), is(20));
48 public void nullCanBeDefaultIntValue() {
49 assertThat(parseInt("not a number", null), nullValue());
53 public void nullIsParsedToDefaultLong() {
54 assertThat(parseLong(null, 17L), is(17L));
58 public void notANumberIsParsedToDefaultLong() {
59 assertThat(parseLong("not a number", 18L), is(18L));
63 public void LongIsCorrectlyParsed() {
64 assertThat(parseLong("19", 0L), is(19L));
68 public void valueTooLargeForLongIsParsedToDefault() {
69 assertThat(parseLong("9223372036854775808", 20L), is(20L));
73 public void valueTooSmallForLongIsParsedToDefault() {
74 assertThat(parseLong("-9223372036854775809", 20L), is(20L));
78 public void nullCanBeDefaultLongValue() {
79 assertThat(parseLong("not a number", null), nullValue());