-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring
- Loading branch information
Showing
12 changed files
with
106 additions
and
19 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
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
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
50 changes: 50 additions & 0 deletions
50
kvalidation-core/src/test/kotlin/hwolf/kvalidation/ValidationResultTests.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,50 @@ | ||
@file:Suppress("unused") | ||
|
||
package hwolf.kvalidation | ||
|
||
import dev.minutest.given | ||
import dev.minutest.rootContext | ||
import dev.minutest.test | ||
import org.junit.platform.commons.annotation.Testable | ||
import strikt.api.expectThat | ||
import strikt.assertions.contains | ||
import strikt.assertions.containsExactly | ||
import strikt.assertions.doesNotContain | ||
import strikt.assertions.isEmpty | ||
import strikt.assertions.map | ||
|
||
@Testable | ||
fun testsValidationResult() = rootContext<ValidationResult> { | ||
|
||
fun violation(property: String, constraint: Constraint) = ConstraintViolation( | ||
propertyName = property, | ||
propertyType = "Any", | ||
propertyValue = null, | ||
constraint = constraint) | ||
|
||
given { | ||
ValidationResult(listOf( | ||
violation("prop1", Required), | ||
violation("prop1", NotBlank), | ||
violation("otherProp", Empty))) | ||
} | ||
test("Operator [] should return all violations for a property") { | ||
expectThat(this["prop1"]) { | ||
containsExactly( | ||
violation("prop1", Required), | ||
violation("prop1", NotBlank)) | ||
} | ||
} | ||
test("Operator [] should return only violations for a property") { | ||
expectThat(this["prop1"]) { | ||
map(ConstraintViolation::propertyName) | ||
.contains("prop1") | ||
.doesNotContain("otherProp") | ||
} | ||
} | ||
test("Operator [] should return empty list for unknown property") { | ||
expectThat(this["unknownProp"]) { | ||
isEmpty() | ||
} | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
kvalidation-samples/src/main/kotlin/hwolf/kvalidation/samples/constraints/MinLength.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,12 @@ | ||
package hwolf.kvalidation.samples.constraints | ||
|
||
import hwolf.kvalidation.Constraint | ||
import hwolf.kvalidation.ValidationBuilder | ||
import hwolf.kvalidation.validate | ||
|
||
data class MinLength<T>(val min: T) : Constraint | ||
|
||
fun <T> ValidationBuilder<T, String>.hasMinLength(min: Int) = | ||
validate(MinLength(min)) { v, _ -> | ||
v.length >= min | ||
} |
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 |
---|---|---|
|
@@ -20,4 +20,4 @@ class UserProfileTests { | |
|
||
expectThat(result.isValid).isFalse() | ||
} | ||
} | ||
} |