9e96bfe647994cb28e981f12422db90ed358e831
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / utils / ObjectsTest.kt
1 package net.pterodactylus.sone.utils
2
3 import org.hamcrest.MatcherAssert.assertThat
4 import org.hamcrest.Matchers.*
5 import org.junit.Test
6
7 /**
8  * Unit test for Object utils.
9  */
10 class ObjectsTest {
11
12         @Test
13         fun `non-null value is turned into a list with one element`() {
14                 assertThat(5.asList(), contains(5))
15         }
16
17         @Test
18         fun `null value is turned into empty list`() {
19                 assertThat(null.asList(), empty())
20         }
21
22         @Test(expected = IllegalArgumentException::class)
23         fun `exception is thrown for null and true condition`() {
24                 null.throwOnNullIf(true) { IllegalArgumentException() }
25         }
26
27         @Test
28         fun `exception is not thrown for null and false condition`() {
29                 assertThat(null.throwOnNullIf(false) { IllegalArgumentException() }, nullValue())
30         }
31
32         @Test
33         fun `exception is not thrown for any and true condition`() {
34                 val any = Any()
35                 assertThat(any.throwOnNullIf(true) { IllegalArgumentException() }, equalTo(any))
36         }
37
38         @Test
39         fun `exception is not thrown for any and false condition`() {
40                 val any = Any()
41                 assertThat(any.throwOnNullIf(false) { IllegalArgumentException() }, equalTo(any))
42         }
43
44 }