00c226375014b0558de53e0b502d1ef59ad5af7b
[Sone.git] / src / test / java / net / pterodactylus / sone / utils / NumberParsersTest.java
1 package net.pterodactylus.sone.utils;
2
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;
8
9 import org.junit.Test;
10
11 /**
12  * Unit test for {@link NumberParsers}.
13  *
14  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
15  */
16 public class NumberParsersTest {
17
18         @Test
19         // yes, this test is for coverage only.
20         public void constructorCanBeCalled() {
21                 new NumberParsers();
22         }
23
24         @Test
25         public void nullIsParsedToDefaultInt() {
26                 assertThat(parseInt(null, 17), is(17));
27         }
28
29         @Test
30         public void notANumberIsParsedToDefaultInt() {
31                 assertThat(parseInt("not a number", 18), is(18));
32         }
33
34         @Test
35         public void intIsCorrectlyParsed() {
36                 assertThat(parseInt("19", 0), is(19));
37         }
38
39         @Test
40         public void valueTooLargeForIntIsParsedToDefault() {
41                 assertThat(parseInt("2147483648", 20), is(20));
42         }
43
44         @Test
45         public void valueTooSmallForIntIsParsedToDefault() {
46                 assertThat(parseInt("-2147483649", 20), is(20));
47         }
48
49         @Test
50         public void nullCanBeDefaultIntValue() {
51                 assertThat(parseInt("not a number", null), nullValue());
52         }
53
54         @Test
55         public void nullIsParsedToDefaultLong() {
56                 assertThat(parseLong(null, 17L), is(17L));
57         }
58
59         @Test
60         public void notANumberIsParsedToDefaultLong() {
61                 assertThat(parseLong("not a number", 18L), is(18L));
62         }
63
64         @Test
65         public void LongIsCorrectlyParsed() {
66                 assertThat(parseLong("19", 0L), is(19L));
67         }
68
69         @Test
70         public void valueTooLargeForLongIsParsedToDefault() {
71                 assertThat(parseLong("9223372036854775808", 20L), is(20L));
72         }
73
74         @Test
75         public void valueTooSmallForLongIsParsedToDefault() {
76                 assertThat(parseLong("-9223372036854775809", 20L), is(20L));
77         }
78
79         @Test
80         public void nullCanBeDefaultLongValue() {
81                 assertThat(parseLong("not a number", null), nullValue());
82         }
83
84 }