Skip to content

Commit

Permalink
Fix Kotlin setPostCondition extension (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo authored Oct 30, 2023
1 parent c5cc9ee commit dbffdf1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ fun <T> ArbitraryBuilder<T>.setInner(innerSpecConfigurer: ((InnerSpec) -> Unit))
return this.setInner(InnerSpec().apply(innerSpecConfigurer))
}

inline fun <reified T> ArbitraryBuilder<T>.setPostCondition(expression: String, noinline predicate: (T) -> Boolean) =
this.setPostCondition(expression, T::class.java, predicate)
inline fun <T, reified U> ArbitraryBuilder<T>.setPostCondition(expression: String, noinline predicate: (U) -> Boolean) =
this.setPostCondition(expression, U::class.java, predicate)

inline fun <reified T> ArbitraryBuilder<T>.setPostCondition(
inline fun <T, reified U> ArbitraryBuilder<T>.setPostCondition(
expressionGenerator: ExpressionGenerator,
noinline predicate: (T) -> Boolean
) = this.setPostCondition(expressionGenerator, T::class.java, predicate)
noinline predicate: (U) -> Boolean
) = this.setPostCondition(expressionGenerator, U::class.java, predicate)

inline fun <reified T> ArbitraryBuilder<T>.setPostCondition(
inline fun <T, reified U> ArbitraryBuilder<T>.setPostCondition(
expression: String,
noinline predicate: (T) -> Boolean,
noinline predicate: (U) -> Boolean,
limit: Int
) = this.setPostCondition(expression, T::class.java, predicate, limit)
) = this.setPostCondition(expression, U::class.java, predicate, limit)

inline fun <reified T> ArbitraryBuilder<T>.setPostCondition(
inline fun <T, reified U> ArbitraryBuilder<T>.setPostCondition(
expressionGenerator: ExpressionGenerator,
noinline predicate: (T) -> Boolean,
noinline predicate: (U) -> Boolean,
limit: Int
) = this.setPostCondition(expressionGenerator, T::class.java, predicate, limit)
) = this.setPostCondition(expressionGenerator, U::class.java, predicate, limit)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.javax.validation.plugin.JavaxValidationPlugin
import com.navercorp.fixturemonkey.kotest.KotestPlugin
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin
import com.navercorp.fixturemonkey.kotlin.giveMeBuilder
import com.navercorp.fixturemonkey.kotlin.giveMeOne
import com.navercorp.fixturemonkey.kotlin.setPostCondition
import com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT
import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.RepeatedTest
Expand Down Expand Up @@ -713,6 +715,20 @@ class KotestInJunitTest {
}
}

@RepeatedTest(TEST_COUNT)
fun setPostConditionExtension() {
class StringObject(val string: String)

val actual = SUT.giveMeBuilder<StringObject>()
.setPostCondition<StringObject, String>("string") {
it.length < 5
}
.sample()
.string

then(actual).hasSizeLessThan(5)
}

companion object {
private val SUT: FixtureMonkey = FixtureMonkey.builder()
.plugin(JavaxValidationPlugin())
Expand Down

0 comments on commit dbffdf1

Please sign in to comment.