I have something like this:
fun doSomething(specifyInput: Base.() -> Unit) {
val spec = BaseImpl()
spec.apply {
specifyInput()
validate()
}
interface Base {
var a: String?
var b: String?
}
class BaseImpl(override var a: String?, override var b: String?) : Base {
constructor() : this(null, null)
fun validate() {
if (a == null) throw ExceptionForA()
if (b == null) throw ExceptionForB()
}
}
This is gradle task.
class A : DefaultTask(), Base by BaseImpl()
@TaskAction
fun doSomething() {
doSomething {
a = c
}
}
This is my test:
val buildFile = File(testProjectDir, "build.gradle.kts")
buildFile.createNewFile()
buildFile.writeText("""
tasks.register("task", A::class.java) {
c = "something"
}
""".trimIndent())
val result = testProjectDir.executeAndFailGradleRunner("task")
assertThat(result.output).contains("ExceptionForB")
Do you know what I need to do that the test passed?
Thank you in advance.
Update: In the meantime I have extend the code example.
Found the solution that I am looking for.