-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If invalid value is set for a property in settings.properties, defaul…
…t value should be applied #1437 Add tests
- Loading branch information
1 parent
a47bc27
commit 509ae72
Showing
2 changed files
with
68 additions
and
12 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
51 changes: 51 additions & 0 deletions
51
utbot-core/src/test/kotlin/org/utbot/common/AbstractSettingsTest.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.utbot.common | ||
|
||
import java.io.InputStream | ||
import mu.KLogger | ||
import mu.KotlinLogging | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
internal class AbstractSettingsTest { | ||
@Test | ||
fun testParsing() { | ||
var settings = createSettings("testBoolean=false\ntestInt=3\ntestIntRange=2\ntestLong=333\ntestLongRange=222") | ||
Assertions.assertFalse(settings.testBoolean) | ||
Assertions.assertEquals(3, settings.testInt) | ||
Assertions.assertEquals(2, settings.testIntRange) | ||
Assertions.assertEquals(333, settings.testLong) | ||
Assertions.assertEquals(222, settings.testLongRange) | ||
|
||
settings = createSettings("testBoolean=invalid\ntestInt=-1\ntestIntRange=-1\ntestLong=-111\ntestLongRange=-111") | ||
Assertions.assertTrue(settings.testBoolean) | ||
Assertions.assertEquals(-1, settings.testInt) | ||
Assertions.assertEquals(1, settings.testIntRange) | ||
Assertions.assertEquals(-111, settings.testLong) | ||
Assertions.assertEquals(111, settings.testLongRange) | ||
|
||
settings = createSettings("") | ||
Assertions.assertTrue(settings.testBoolean) | ||
Assertions.assertEquals(3, settings.testInt) | ||
Assertions.assertEquals(333, settings.testLongRange) | ||
} | ||
|
||
private fun createSettings(propertiesText: String): TestSettings { | ||
AbstractSettings.setupFactory(object : SettingsContainerFactory { | ||
override fun createSettingsContainer( | ||
logger: KLogger, defaultKeyForSettingsPath: String, defaultSettingsPath: String? | ||
) = object : PropertiesSettingsContainer(logger, defaultKeyForSettingsPath, defaultSettingsPath) { | ||
override fun getInputStream(): InputStream = propertiesText.byteInputStream() | ||
} | ||
}) | ||
return TestSettings() | ||
} | ||
|
||
internal class TestSettings : AbstractSettings(KotlinLogging.logger {}, "") { | ||
val testBoolean: Boolean by getBooleanProperty(true) | ||
val testInt: Int by getIntProperty(3) | ||
val testIntRange: Int by getIntProperty(3, 1, 5) | ||
val testLong: Long by getLongProperty(333) | ||
val testLongRange: Long by getLongProperty(333, 111, 555) | ||
} | ||
} |