diff --git a/app/build.gradle b/app/build.gradle index e8902fdd..c9425d58 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -186,7 +186,7 @@ ext { } dependencies { - implementation "io.github.wulkanowy:sdk:1.7.4" + implementation "io.github.wulkanowy:sdk:dcd8bd8b19" coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.8' diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/MailboxRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/MailboxRepository.kt index ad4f669e..c571937a 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/MailboxRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/MailboxRepository.kt @@ -60,16 +60,18 @@ class MailboxRepository @Inject constructor( } private fun String.normalizeStudentName(): String { - return trim().split(" ").joinToString(" ") { part -> - part.lowercase().replaceFirstChar { it.uppercase() } - } + return trim().split(" ") + .filter { it.isNotBlank() } + .joinToString(" ") { part -> + part.lowercase().replaceFirstChar { it.uppercase() } + } } private fun String.getFirstAndLastPart(): String { val parts = normalizeStudentName().split(" ") val endParts = parts.filterIndexed { i, _ -> - i == 0 || parts.size == i - 1 + i == 0 || parts.size - 1 == i } return endParts.joinToString(" ") } diff --git a/app/src/test/java/io/github/wulkanowy/data/repositories/MailboxRepositoryTest.kt b/app/src/test/java/io/github/wulkanowy/data/repositories/MailboxRepositoryTest.kt index 300662f0..9198560f 100644 --- a/app/src/test/java/io/github/wulkanowy/data/repositories/MailboxRepositoryTest.kt +++ b/app/src/test/java/io/github/wulkanowy/data/repositories/MailboxRepositoryTest.kt @@ -91,6 +91,20 @@ class MailboxRepositoryTest { assertEquals(expectedMailbox, systemUnderTest.getMailbox(student)) } + @Test + fun `get mailbox for unique non-authorized student but with spaces`() = runTest { + val student = getStudentEntity( + userName = "Stanisław Kowalski", + studentName = "J** K*******", + ) + val expectedMailbox = getMailboxEntity("Jan Kowalski") + coEvery { mailboxDao.loadAll(any()) } returns listOf( + expectedMailbox, + ) + + assertEquals(expectedMailbox, systemUnderTest.getMailbox(student)) + } + @Test(expected = IllegalArgumentException::class) fun `get mailbox for not-unique non-authorized student`() = runTest { val student = getStudentEntity(