-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add optional values and sections support. Add unit tests for optional values and sections. * (cleanup) Use no deprecated method. Use only CdnDeserializer#createInstance() method to create instance.
- Loading branch information
Showing
4 changed files
with
228 additions
and
40 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
cdn-tests/src/test/kotlin/net/dzikoysk/cdn/feature/OptionalSectionTest.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,97 @@ | ||
package net.dzikoysk.cdn.feature | ||
|
||
import net.dzikoysk.cdn.CdnSpec | ||
import net.dzikoysk.cdn.entity.Contextual | ||
import net.dzikoysk.cdn.entity.Description | ||
import net.dzikoysk.cdn.loadAs | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
import panda.std.ResultAssertions.assertOk | ||
|
||
class OptionalSectionTest : CdnSpec() { | ||
|
||
class ConfigurationWithOptionalValues { | ||
|
||
@Description("// Normal value") | ||
var normal = "value" | ||
|
||
@Description("// Optional section") | ||
var optionalSection: Section? = null | ||
|
||
@Contextual | ||
class Section { | ||
@Description("// Other value in section") | ||
var other = "value" | ||
@Description("// Optional value") | ||
var optional: String? = null; | ||
} | ||
|
||
} | ||
|
||
@Test | ||
fun `should render without optional section`() { | ||
val renderResult = standard.render(ConfigurationWithOptionalValues()) | ||
val render = assertOk(renderResult) | ||
|
||
assertEquals(""" | ||
// Normal value | ||
normal: value | ||
""".trimIndent(), render) | ||
} | ||
|
||
@Test | ||
fun `should render section after without optional value`() { | ||
val modified = ConfigurationWithOptionalValues() | ||
|
||
modified.optionalSection = ConfigurationWithOptionalValues.Section() | ||
|
||
val renderResult = standard.render(modified) | ||
val render = assertOk(renderResult) | ||
|
||
assertEquals(""" | ||
// Normal value | ||
normal: value | ||
// Optional section | ||
optionalSection { | ||
// Other value in section | ||
other: value | ||
} | ||
""".trimIndent(), render) | ||
} | ||
|
||
@Test | ||
fun `should load without optional value`() { | ||
val loadResult = standard.loadAs<ConfigurationWithOptionalValues> { """ | ||
// Normal value | ||
normal: value | ||
""".trimIndent() } | ||
|
||
val load = assertOk(loadResult) | ||
|
||
assertEquals("value", load.normal) | ||
assertNull(load.optionalSection) | ||
} | ||
|
||
@Test | ||
fun `should load all values`() { | ||
val loadResult = standard.loadAs<ConfigurationWithOptionalValues> { """ | ||
// Normal value | ||
normal: value | ||
// Optional section | ||
optionalSection { | ||
// Other value in section | ||
other: otherValue | ||
// Optional value | ||
optional: optionalValue | ||
} | ||
""".trimIndent() } | ||
|
||
val load = assertOk(loadResult) | ||
|
||
assertEquals("value", load.normal) | ||
assertNotNull(load.optionalSection) | ||
assertEquals("otherValue", load.optionalSection?.other) | ||
assertEquals("optionalValue", load.optionalSection?.optional) | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
cdn-tests/src/test/kotlin/net/dzikoysk/cdn/feature/OptionalValueTest.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,79 @@ | ||
package net.dzikoysk.cdn.feature | ||
|
||
import net.dzikoysk.cdn.CdnSpec | ||
import net.dzikoysk.cdn.entity.Description | ||
import net.dzikoysk.cdn.loadAs | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.Test | ||
import panda.std.ResultAssertions.assertOk | ||
|
||
class OptionalValueTest : CdnSpec() { | ||
|
||
class ConfigurationWithOptionalValues { | ||
|
||
@Description("// Normal value") | ||
var normal = "value" | ||
|
||
@Description("// Optional value") | ||
var optional: String? = null | ||
|
||
} | ||
|
||
@Test | ||
fun `should render without optional value`() { | ||
val renderResult = standard.render(ConfigurationWithOptionalValues()) | ||
val render = assertOk(renderResult) | ||
|
||
assertEquals(""" | ||
// Normal value | ||
normal: value | ||
""".trimIndent(), render) | ||
} | ||
|
||
@Test | ||
fun `should render with all values after modification`() { | ||
val modified = ConfigurationWithOptionalValues() | ||
|
||
modified.optional = "newValue" | ||
|
||
val renderResult = standard.render(modified) | ||
val render = assertOk(renderResult) | ||
|
||
assertEquals(""" | ||
// Normal value | ||
normal: value | ||
// Optional value | ||
optional: newValue | ||
""".trimIndent(), render) | ||
} | ||
|
||
@Test | ||
fun `should load without optional value`() { | ||
val loadResult = standard.loadAs<ConfigurationWithOptionalValues> { """ | ||
// Normal value | ||
normal: value | ||
""".trimIndent() } | ||
|
||
val load = assertOk(loadResult) | ||
|
||
assertEquals("value", load.normal) | ||
assertNull(load.optional) | ||
} | ||
|
||
@Test | ||
fun `should load all values`() { | ||
val loadResult = standard.loadAs<ConfigurationWithOptionalValues> { """ | ||
// Normal value | ||
normal: value | ||
// Optional value | ||
optional: newValue | ||
""".trimIndent() } | ||
|
||
val load = assertOk(loadResult) | ||
|
||
assertEquals("value", load.normal) | ||
assertEquals("newValue", load.optional) | ||
} | ||
|
||
} |
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