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 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
16 public class NumberParsersTest {
19 // yes, this test is for coverage only.
20 public void constructorCanBeCalled() {
25 public void nullIsParsedToDefaultInt() {
26 assertThat(parseInt(null, 17), is(17));
30 public void notANumberIsParsedToDefaultInt() {
31 assertThat(parseInt("not a number", 18), is(18));
35 public void intIsCorrectlyParsed() {
36 assertThat(parseInt("19", 0), is(19));
40 public void valueTooLargeForIntIsParsedToDefault() {
41 assertThat(parseInt("2147483648", 20), is(20));
45 public void valueTooSmallForIntIsParsedToDefault() {
46 assertThat(parseInt("-2147483649", 20), is(20));
50 public void nullCanBeDefaultIntValue() {
51 assertThat(parseInt("not a number", null), nullValue());
55 public void nullIsParsedToDefaultLong() {
56 assertThat(parseLong(null, 17L), is(17L));
60 public void notANumberIsParsedToDefaultLong() {
61 assertThat(parseLong("not a number", 18L), is(18L));
65 public void LongIsCorrectlyParsed() {
66 assertThat(parseLong("19", 0L), is(19L));
70 public void valueTooLargeForLongIsParsedToDefault() {
71 assertThat(parseLong("9223372036854775808", 20L), is(20L));
75 public void valueTooSmallForLongIsParsedToDefault() {
76 assertThat(parseLong("-9223372036854775809", 20L), is(20L));
80 public void nullCanBeDefaultLongValue() {
81 assertThat(parseLong("not a number", null), nullValue());