Closed richkeenan closed 7 years ago
Hi, Absolutely loved the library, is this feature implemented yet, If not can I offer any help ?
Hi @waliahimanshu , thanks for the kind words!
I've not worked on this in ages to be honest - I'm a C# dev at work and so this library hasn't been my focus lately, although I should be looking at more often TBH.
Last time I was looking at this issue I was trying to think about the best way it would work under-the-hood, but couldn't come with anything I was happy with, but here's what I was thinking 2 years ago (that I can remember!):
With("Id", "ABC-123")
, but using strings to specify the getter is prone to a number of problems. Maybe it's ok as a first iteration though?AutoFixture
library uses this mechanismnameof
operator which looks like With(nameof(order.Id)..
which would work tooI've also been thinking of spinning out V3 and only supporting Java 8 (with V2 for Java 6/7). So if Java 8 offers a type-safe way of getting the name of a getter/setter I'd be super happy to include that in V3.
Do you know if Java has a similar mechanism nowadays for doing this? Thanks
I recently started with Android(Java), was doing .net before and using AutoFixtures a lot for TDD. I will explore the options java 8 has to offer.
Keen to look at the first point. Will let you know if I have some questions or when I know more around this.
+1 for this
Java 8 has method references, but their name cannot be queried just by using the platform. Even if it worked you couldn't do the same with fields (there're no field references in the language). See http://stackoverflow.com/q/19845213/253468 for more. One of the answers uses Mockito, that might be the same as your point about the proxy library.
Love the idea of the name "stringly typed API", never heard that before :)
@TWiStErRob thanks for the info, that reinforces my understanding. I think the best thing here is to implement a stringed API so people can start using it immediately, then figure out a strongly typed API that will just call down to the string version. Probably using the concept of a proxy (you're right that this is how Mockito does it). Java has a built in mechanism for this that I'll explore too.
Awesome! Thanks for the effort.
(note: comment on commit)
AutoFixture allows you to customise particular properties of objects using this syntax
This works because C# is able to evaluate the lambda expression to pull out the string
"Id"
.As a first step I'd like JFixture to be able to do this using a stringly typed API, so something along the lines of