Cleaned up null-safety checks.

This commit is contained in:
Erik C. Thauvin 2021-04-27 11:38:08 -07:00
parent ae6220d421
commit 2f4e6bdb2d
4 changed files with 8 additions and 8 deletions

View file

@ -86,9 +86,7 @@ object Utils {
* Capitalize a string.
*/
@JvmStatic
fun capitalize(s: String?): String {
return s!!.replaceFirstChar { it.uppercase() }
}
fun capitalize(s: String?): String? = s?.replaceFirstChar { it.uppercase() }
/**
* Colorize a string.

View file

@ -152,8 +152,8 @@ class EntryLink : Serializable {
* Sets a comment.
*/
fun setComment(index: Int, comment: String?, nick: String?) {
if (index < comments.size) {
comments[index] = EntryComment(comment!!, nick!!)
if (index < comments.size && (comment != null) && !nick.isNullOrBlank()) {
comments[index] = EntryComment(comment, nick)
}
}

View file

@ -82,6 +82,8 @@ class UtilsTest {
fun testCapitalize() {
Assertions.assertThat(capitalize("test")).`as`("capitalize(test)").isEqualTo("Test")
Assertions.assertThat(capitalize("Test")).`as`("capitalize(Test)").isEqualTo("Test")
Assertions.assertThat(capitalize(null)).`as`("captitalize(null)").isNull()
Assertions.assertThat(capitalize("")).`as`("capitalize()").isEqualTo("")
}
@Test

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
#Mon Apr 26 22:11:16 PDT 2021
version.buildmeta=475
#Tue Apr 27 17:59:17 PDT 2021
version.buildmeta=487
version.major=0
version.minor=8
version.patch=0
version.prerelease=beta
version.project=mobibot
version.semver=0.8.0-beta+475
version.semver=0.8.0-beta+487