Skip to content

Commit

Permalink
Some lint cleanup in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
russhwolf committed Aug 4, 2018
1 parent ebc54e2 commit be5cf51
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:Suppress("KDocMissingDocumentation", "unused")

package com.russhwolf.settings

import kotlin.reflect.KClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

// TODO We shouldn't need this, but common module test sources aren't making it to the IDE test scope at the moment
@file:Suppress("KDocMissingDocumentation")

package com.russhwolf.settings

import kotlin.test.BeforeTest
Expand Down Expand Up @@ -116,9 +119,9 @@ class SettingsTest {
var a by settings.nullableInt("Nullable Int")
assertEquals(null, a)
a = 2
assertEquals(2, a)
assertEquals(2.asNullableType(), a)
a = 0
assertEquals(0, a)
assertEquals(0.asNullableType(), a)
a = null
assertEquals(null, a)
}
Expand All @@ -128,9 +131,9 @@ class SettingsTest {
var a by settings.nullableLong("Nullable Long")
assertEquals(null, a)
a = 2
assertEquals(2, a)
assertEquals(2L.asNullableType(), a)
a = 0
assertEquals(0, a)
assertEquals(0L.asNullableType(), a)
a = null
assertEquals(null, a)
}
Expand All @@ -140,7 +143,7 @@ class SettingsTest {
var a by settings.nullableString("Nullable String")
assertEquals(null, a)
a = "value"
assertEquals("value", a)
assertEquals("value".asNullableType(), a)
a = null
assertEquals(null, a)
}
Expand All @@ -150,9 +153,9 @@ class SettingsTest {
var a by settings.nullableFloat("Nullable Float")
assertEquals(null, a)
a = 2f
assertEquals(2f, a)
assertEquals(2f.asNullableType(), a)
a = 0f
assertEquals(0f, a)
assertEquals(0f.asNullableType(), a)
a = null
assertEquals(null, a)
}
Expand All @@ -162,9 +165,9 @@ class SettingsTest {
var a by settings.nullableDouble("Nullable Double")
assertEquals(null, a)
a = 2.0
assertEquals(2.0, a)
assertEquals(2.0.asNullableType(), a)
a = 0.0
assertEquals(0.0, a)
assertEquals(0.0.asNullableType(), a)
a = null
assertEquals(null, a)
}
Expand All @@ -174,8 +177,15 @@ class SettingsTest {
var a by settings.nullableBoolean("Nullable Boolean")
assertEquals(null, a)
a = true
assertEquals(true, a)
assertEquals(true.asNullableType(), a)
a = null
assertEquals(null, a)
}
}

/**
* Cast a value of type `T` to `T?`
*
* Helper function to avoid deprecated smart-casts when asserting non-null values of nullable delegates
*/
private fun <T : Any> T.asNullableType() = this as T?

0 comments on commit be5cf51

Please sign in to comment.