On Wed, Dec 26, 2012 at 9:15 PM, Dirk Nimerem <nene1...@sinnlos-mail.de>wrote:
> Hi, > > Let's say i have a class which represents an user, called "User" and an > interface implemented by this class called "IUser". The IUser interface > declares one method called "sendMail(String text)" for the user. Also i > created an interceptor/ aspect via the Guice bindInterceptor method for my > IUser. The aspect simply logs every call for the sendMail() method, that > works fine. > > 1.) But how do i test, that my aspect works properly? I don't have an idea > how to write an unit test for that. My idea was to create an IUser mock and > trigger the public sendMail() method from outside. But how do I create an > aspect on top of a mock? > First, I think you should unit test the interceptor itself, making sure that the log event is called. It's a little tricky, but you can achieve that with Mockito and log4j. If you really want to test the interceptor is binded correctly, you should write some kinda functional / integration test case. Here, you'll start your the Injector and check that the log is written or something alike. > > 2.) In my aspect/ interceptor i simply check the methodname like this: "if > methodname == 'sendMail'". But if i rename/ refactor the sendMail Method my > aspect won't work anymore. Is there a better way to to that? > You should use custom annotation for that and apply it only on the methods you want logging. Then configure your interceptor like: bindInterceptor( any(), // classes annotatedWith(YourAnnon.class), // methods new YourLoggingInterceptor()); I think the examples about AOP in the wiki [1] are pretty clear, but let me know if I can help you further! Cheers! jordi [1] http://code.google.com/p/google-guice/wiki/AOP > > Thanks, > Dirk > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-guice/-/6flNLUy1tfwJ. > To post to this group, send email to google-guice@googlegroups.com. > To unsubscribe from this group, send email to > google-guice+unsubscr...@googlegroups.com. > 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 google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.