X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FNumberParsersTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FNumberParsersTest.java;h=00c226375014b0558de53e0b502d1ef59ad5af7b;hb=224be7a31fee673fa438cb02c4bb2105d01a52cc;hp=0000000000000000000000000000000000000000;hpb=43740d6a1dfc686ab54d0aebd4a5b1bce75b9ed6;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/utils/NumberParsersTest.java b/src/test/java/net/pterodactylus/sone/utils/NumberParsersTest.java new file mode 100644 index 0000000..00c2263 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/utils/NumberParsersTest.java @@ -0,0 +1,84 @@ +package net.pterodactylus.sone.utils; + +import static net.pterodactylus.sone.utils.NumberParsers.parseInt; +import static net.pterodactylus.sone.utils.NumberParsers.parseLong; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.Test; + +/** + * Unit test for {@link NumberParsers}. + * + * @author David ‘Bombe’ Roden + */ +public class NumberParsersTest { + + @Test + // yes, this test is for coverage only. + public void constructorCanBeCalled() { + new NumberParsers(); + } + + @Test + public void nullIsParsedToDefaultInt() { + assertThat(parseInt(null, 17), is(17)); + } + + @Test + public void notANumberIsParsedToDefaultInt() { + assertThat(parseInt("not a number", 18), is(18)); + } + + @Test + public void intIsCorrectlyParsed() { + assertThat(parseInt("19", 0), is(19)); + } + + @Test + public void valueTooLargeForIntIsParsedToDefault() { + assertThat(parseInt("2147483648", 20), is(20)); + } + + @Test + public void valueTooSmallForIntIsParsedToDefault() { + assertThat(parseInt("-2147483649", 20), is(20)); + } + + @Test + public void nullCanBeDefaultIntValue() { + assertThat(parseInt("not a number", null), nullValue()); + } + + @Test + public void nullIsParsedToDefaultLong() { + assertThat(parseLong(null, 17L), is(17L)); + } + + @Test + public void notANumberIsParsedToDefaultLong() { + assertThat(parseLong("not a number", 18L), is(18L)); + } + + @Test + public void LongIsCorrectlyParsed() { + assertThat(parseLong("19", 0L), is(19L)); + } + + @Test + public void valueTooLargeForLongIsParsedToDefault() { + assertThat(parseLong("9223372036854775808", 20L), is(20L)); + } + + @Test + public void valueTooSmallForLongIsParsedToDefault() { + assertThat(parseLong("-9223372036854775809", 20L), is(20L)); + } + + @Test + public void nullCanBeDefaultLongValue() { + assertThat(parseLong("not a number", null), nullValue()); + } + +}