-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move to ktor 2.0.0 and update dependencies, packages and testing.
- Loading branch information
1 parent
1d531a1
commit 8715958
Showing
5 changed files
with
49 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 22 additions & 13 deletions
35
src/test/kotlin/com/github/aymanizz/ktori18n/I18nTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,50 @@ | ||
package com.github.aymanizz.ktori18n | ||
|
||
import io.ktor.application.install | ||
import io.ktor.server.testing.withTestApplication | ||
import io.ktor.server.testing.testApplication | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import java.util.Locale | ||
import kotlin.test.assertEquals | ||
|
||
internal class I18nTests { | ||
@Test | ||
fun `throws when supported locales is not initialized`(): Unit = withTestApplication { | ||
assertThrows<UninitializedPropertyAccessException> { application.install(I18n) } | ||
fun `throws when supported locales is not initialized`() { | ||
assertThrows<UninitializedPropertyAccessException> { | ||
testApplication { | ||
install(I18n) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `throws when supported locales is empty`(): Unit = withTestApplication { | ||
fun `throws when supported locales is empty`() { | ||
assertThrows<IllegalArgumentException> { | ||
application.install(I18n) { supportedLocales = listOf() } | ||
testApplication { | ||
install(I18n) { supportedLocales = listOf() } | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `throws when default locale not in supported locales`(): Unit = withTestApplication { | ||
fun `throws when default locale not in supported locales`() { | ||
assertThrows<IllegalArgumentException> { | ||
application.install(I18n) { | ||
supportedLocales = listOf("en", "de").map { Locale.forLanguageTag(it) } | ||
defaultLocale = Locale.forLanguageTag("ar") | ||
testApplication { | ||
install(I18n) { | ||
supportedLocales = listOf("en", "de").map { Locale.forLanguageTag(it) } | ||
defaultLocale = Locale.forLanguageTag("ar") | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `default locale defaults to the first supported locale`(): Unit = withTestApplication { | ||
fun `default locale defaults to the first supported locale`(): Unit = testApplication { | ||
val locales = listOf("en", "ar").map { Locale.forLanguageTag(it) } | ||
application.install(I18n) { | ||
install(I18n) { | ||
supportedLocales = locales | ||
} | ||
assertEquals(locales[0], application.i18n.defaultLocale) | ||
this.application { | ||
assertEquals(locales[0], i18n.defaultLocale) | ||
} | ||
} | ||
} |