17. Entity
@Entity(immutable = true)
data class Person(
@Id
@GeneratedValue(strategy = GenerationType.
IDENTITY)
val id: Int? = null,
val name: Name,
val age: Int?,
val address: Address,
@Version
val version: Int = -1)
44. @Select(strategy = SelectType.STREAM)
fun selectById(
@ParameterName("id") id:Int,
func :
java.util.function.Function<java.util.stream.
Stream<Person>, Name>): Name
Dao
45. @Test fun test2() {
tm.required {
val personName = dao.selectById(1, Function {
it.map {it.name}.findFirst().orElseThrow {
Exception("あってほしい!")
}
})
Assert.assertEquals(Name("SMITH"), personName)
}
}
Test Code
46. @Test fun test2() {
tm.required {
val personName = dao.selectById(1, Function {
it.map {it.name}.findFirst().orElseThrow {
Exception("あってほしい!")
}
})
Assert.assertEquals(Name("SMITH"), personName)
}
}
Test Code
SAM(Single Abstract
Method)
47. @Test fun test2() {
tm.required {
val personName = dao.selectById(1, Function {
it.map {it.name}.findFirst().orElseThrow {
Exception("あってほしい!")
}
})
Assert.assertEquals(Name("SMITH"), personName)
}
}
Test Code
Function#applyを
Function{}とかける
48. @Test fun test2() {
tm.required {
val personName = dao.selectById(1, Function {
it.map {it.name}.findFirst().orElseThrow {
Exception("あってほしい!")
}
})
Assert.assertEquals(Name("SMITH"), personName)
}
}
Test Code
it = Stream<Person>
stream -> stream
と思ってくれれば。
49. @Test fun test2() {
tm.required {
val personName = dao.selectById(1, Function {
it.map {it.name}.findFirst().orElseThrow {
Exception("あってほしい!")
}
})
Assert.assertEquals(Name("SMITH"), personName)
}
}
Test Code Javaで書くなら
stream -> stream
.map(person -> person.getName())
.findFirst().orElseThrow(()-> throw
new Exception(“あってほしい!”)