-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider Kotlin extension-method "overloads" to StandardSubjectBuilder.that #660
Comments
Hi, When I try to create a new Subject (in Kotlin), I feel it's not straightforward. There are some questions prompted in my head like:
I suggest a new way: abstract class SubjectFactory<S : Subject, T>(
subjectConstructor: (metadata: FailureMetadata, actual: T?) -> S
) {
private val subjectFactory: Factory<S, T> = Factory<S, T>(subjectConstructor)
fun assertThat(actual: T?): S = assertAbout(subjectFactory).that(actual)
} Then for a new subject, we just need: class XyzSubject(
metadata: FailureMetadata,
private val actual: Xyz?
) : Subject(metadata, actual) {
// Snippet
companion object : SubjectFactory<XyzSubject, Xyz>(::XyzSubject)
}
|
Thanks, @tuanchauict. I finally had a detailed look at your suggestion. I think it would be the best approach for someone who wants to use All that said, we know people who are looking more at pure Kotlin projects, so we may eventually want to provide exactly what you're suggesting for them. |
I hope Jetbrains will allow us to make |
Thanks, I might have given up before trying The other thing I note about that implementation is that users would need to define a Backing up to my original proposal:
Wait, no, we can't. Or we could, but it wouldn't do any good: Kotlin always prefers any member function that exists over any extension function. So, because |
Everywhere we expose a
Subject.Factory
(orCustomSubjectBuilder.Factory
), we could expose athat
method. Such methods would save users ofassertWithMessage
,check
,expect
, etc. (maybe includingExpectFailure
in theSubject
's own tests :)) from having to callabout(foos())
.The text was updated successfully, but these errors were encountered: