-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add the posibility to use @Before with bindMany #67
Comments
I think it's going to be hard to define semantics for this that won't surprise people. What would happen in these cases? @Before public void setup(@All Foo foo) { ... }
@Test public void test1(@All Foo foo) { ... }
@Test public void test2(@All Foo foo, @All Bar bar) { ... }
@Test public void test3(@All Bar bar) { ... }
@Test public void test4() { ... } I don't think this enhancement is worth the confusion it would cause. The workaround I posted |
I agree with you that add the @ALL annotation in the before method can Il giorno gio 23 lug 2015 alle ore 16:01 Tim Peierls <
|
Can you make a more specific proposal here? It's not enough to say "use @before with bindMany" -- you need to flesh out the semantics in detail. |
The proposal is to implement exact what you wrote in the Jukito forum:
Now it does't work in that way but I think it's the correct behavior. If isn't possible for same technical issue we can use your workaround. |
Those sentences (I didn't write them, I quoted them):
They aren't a specification to be implemented. They don't, for example, say what should happen in this case: @Before public void setup(Foo foo) {...}
@Test public void test1(@All Foo foo) {...}
@Test public void test2() {...} And what would happen with multiple @ALL arguments in a test but only a subset of those types in a @before? @Before public void setup(Foo foo) {...}
@Test public void test1(@All Foo foo, @All Bar bar) {...}
@Test public void test2(@All Foo foo) {...}
@Test public void test2(@All Bar bar) {...} It's easy to describe what the @ALL does for test methods, but it gets complicated when describing how the @before method arguments would be injected. I think it's better to be explicit. We're talking one line in each affected test method vs. a hard-to-specify new feature. |
I encountered and was annoyed by this absent feature a while back. If I remember the results of my investigation correctly, in Guice (and Jukito) each object to be injected is uniquely identified by the combination of the class and annotation(s) on its parameter declaration. The only reason Jukito doesn't already have this feature working is that The appropriate specification seems very simple and not at all confusing to me: for each invocation of a Examples (of how I think it should work):
Call setup with an automatically generated mock object because the annotations don't match, then call test with foo1. Call setup with a second automatically generated mock object, then call test with foo2. This is how Jukito currently behaves and I wouldn't change it for this case.
Call setup with an automatically generated mock object, then call test with foo1 for the first parameter and the mock generated for setup as the second parameter. Importantly, foo in setup and foo3 in test are the same instance. Repeat with foo2 and another generated mock. This is again how Jukito currently behaves and should not be changed. In fact, this case and preserving its proper functionality is a major reason why the first example should not be changed.
Call setup with foo1, then test with foo1, then setup with foo2, then test with foo2. Jukito currently handles this the same as the first example. I traced the code in the debugger a while back, the lookup performed for injection into setup has foo1/foo2 (I think only one of them at a time, but I'm not certain about my memory on that point) available in the map but skips them because the annotations recorded in the map don't match
Call:
Call setup with either foo1 or foo2, then call test with its empty parameter list. Declare in documentation that which of the many bound instances gets passed to setup in this case is unspecified.
Call setup with either foo1 or foo2 (unspecified), then test with bar1, then setup with foo1 or foo2 again, then test with bar2.
Call setup with either foo1 or foo2 (unspecified), then test with an automatically generated mock because it's not using |
Thanks for starting to spec this out. My feeling is still that the definitional complexity outweighs the marginal benefit, but if someone is willing to complete the spec and implement it, I don't see that it does any harm. (Yes, I'm damning with faint praise.) Does no one else see what I mean by definitional complexity? I would have trouble using this feature, because I wouldn't know when to add |
When to add Maybe you're getting confused by thoughts of how |
No, I did understand what you wrote. I'm not saying it's impossible to grok. I'm saying that someone coming to this fresh might be excused for being unsure of whether the Putting myself in the head of such a developer, I expect the price of this uncertainty would lead me just to write explicitly what I wanted rather than trusting my instincts or reaching for the docs. |
bindMany and All annotation doesn't permit to setup up the binded instance with a before annotated method.
The following code demonstrate the use case:
When running the test I expect as output:
Instead the output is:
It's possible to support the All annotation also in Before method or fix the behavior?
The text was updated successfully, but these errors were encountered: