🔀 Merge branch 'release/v82'
[Sone.git] / pterodactylus / sone / data / ProfileTest.kt
1 package net.pterodactylus.sone.data
2
3 import net.pterodactylus.sone.test.*
4 import org.hamcrest.MatcherAssert.*
5 import org.hamcrest.Matchers.*
6 import org.junit.*
7
8 /**
9  * Unit test for [Profile].
10  */
11 class ProfileTest {
12
13         private val sone = mock<Sone>()
14         private val profile = Profile(sone)
15
16         @Test
17         fun `first name is initialized with null`() {
18                 assertThat(profile.firstName, nullValue())
19         }
20
21         @Test
22         fun `setting first name to value will set it to value`() {
23             profile.firstName = "first name"
24                 assertThat(profile.firstName, equalTo("first name"))
25         }
26
27         @Test
28         fun `setting first name to null will set it to null`() {
29             profile.firstName = null
30                 assertThat(profile.firstName, nullValue())
31         }
32
33         @Test
34         fun `setting first name to empty string will set it to null`() {
35             profile.firstName = ""
36                 assertThat(profile.firstName, nullValue())
37         }
38
39         @Test
40         fun `middle name is initialized with null`() {
41                 assertThat(profile.middleName, nullValue())
42         }
43
44         @Test
45         fun `setting middle name to value will set it to value`() {
46                 profile.middleName = "middle name"
47                 assertThat(profile.middleName, equalTo("middle name"))
48         }
49
50         @Test
51         fun `setting middle name to null will set it to null`() {
52                 profile.middleName = null
53                 assertThat(profile.middleName, nullValue())
54         }
55
56         @Test
57         fun `setting middle name to empty string will set it to null`() {
58                 profile.middleName = ""
59                 assertThat(profile.middleName, nullValue())
60         }
61
62         @Test
63         fun `last name is initialized with null`() {
64                 assertThat(profile.lastName, nullValue())
65         }
66
67         @Test
68         fun `setting last name to value will set it to value`() {
69                 profile.lastName = "last name"
70                 assertThat(profile.lastName, equalTo("last name"))
71         }
72
73         @Test
74         fun `setting last name to null will set it to null`() {
75                 profile.lastName = null
76                 assertThat(profile.lastName, nullValue())
77         }
78
79         @Test
80         fun `setting last name to empty string will set it to null`() {
81                 profile.lastName = ""
82                 assertThat(profile.lastName, nullValue())
83         }
84
85         @Test
86         fun `new fields are initialized with an empty string`() {
87                 val newField = profile.addField("testField")
88                 assertThat(newField.value, equalTo(""))
89         }
90
91 }