I agree that this is a rather simplistic example but for testing purposes, I would have to prepare PizzaFactory in addition to preparing a mock Pizza object.
I have found that designing a system for DI makes it easier for me to test various use cases without having to . In my example, I can simply mock Pizza interface and stub out canned outputs and put it in a map for access. The stubbed objects will behave the way I have programmed them to. On Sat, Feb 13, 2010 at 3:45 PM, Kwik <[email protected]> wrote: > Hi. > > Interesting post. I thought I'd just mention that it is quite easy to > test the example you gave. Simply mock out the PizzaFactory with > jmockit. > > Would look something like this: > > new Expectation() > { > PizzaFactory pizzaFactory; > { > PizzaFactory.createPizza(any); > result = aPizza; // could be another mock if I want > } > } > > I still like the guice way better but it is possible to test static > factories as well assuming you're able to use jmockit in your project. > > /Kaj > > > On Feb 14, 12:09 am, Kartik Kumar <[email protected]> wrote: > > Hi All, > > > > I have been working on slowly integrating Guice in our project that > > leverages JPF to buid web application. So far, the results have been more > > than encouraging. Our code is now more testable and faster. More bugs are > > being caught during development cycle. To replace a static factory > > implementation used repeatedly in our code, I leveraged multibindings > which > > made id easier to look up strategy implementations based on key-value > pairs. > > I just finished writing a blog post about ithttp:// > kartik-krishnanand.blogspot.com/2010/02/factory-implementation... > > > > Any feedback any one may have is appreciated. > > > > Thanks, > > > > Kartik > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
