-
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 auto-generating assertThat and subject factory for custom subjects #612
Comments
I'd be down with a generator if it generated |
Thanks. This is something that we've given a little thought to in the past. I'll try to summarize here. The boilerplate is definitely unfortunate. While you can cut the 2 methods down to this... public static EmployeeSubject assertThat(Employee employee) {
return assertAbout(employees()).that(employee);
}
public static Factory<EmployeeSubject, Employee> employees() {
return EmployeeSubject::new;
} ...so that there's no need for On top of that, there's the possibility that we could generate the assertion methods themselves in straightforward cases (like the For those reasons, I do think we will look into this eventually. I say only "eventually," though, for a few reasons:
A little more on annotation processors that generate public API, cribbed from some internal documentation on the topic:
|
Oh man - hey dude! :) I’m keen to look into this too… perhaps we can host some truth extensions somewhere to get something prototyped.. |
As per the PR, this is now available here: https://github.com/astubbs/truth-generator as a pre-release SNAPSHOT that can be installed locally. Will work on getting it into repo1 soon. |
The plugin is now available in a couple of Maven repositories (but not repo1 yet), and the README has been updated with feature list and examples. See the README for details. |
FYI 0.1 of the library / plugin is now publicly available. |
Currently a minimal Truth Subject requires four operations: a constructor, an assertion method, and two static methods for accessing the subject:
assertThat
and a subject factory (see extension page).Would it be possible to auto-generate these methods and, possibly, accumulate all custom
assertThat
overloads in a single place, to cut down the number or operations the developer has to add to a custom subject, and encourage creating customSubject
s even if a single assertion method is needed?For instance,
Will generate these two methods:
As a new user of Truth, I can't say if such implementations are common enough so that it makes sense to generate them. There are also other considerations:
#251, which suggested generating the factory, is likely related.
The text was updated successfully, but these errors were encountered: