From: James H. <jw...@al...> - 2003-04-29 18:41:49
|
I'm writing a small utility class which will be used to send e-mail. I would like to write the code test-first as much as possible. However, I notice that that Java Mail API makes heavy use of static methods to accomplish many of its tasks. I see that there are Mock implementations of things like Transport and Message in the Mock Objects library, but I'm not sure how to make use of them. Are there any simple examples of using the MockObjects library to test things that use things like javax.mail.Transport (and related classes?) Thanks. -- James Howe |
From: Steve F. <st...@m3...> - 2003-04-29 19:40:32
|
One option I considered, but never got around to, was to implement and register a mock mail provider. S. James Howe wrote: > I'm writing a small utility class which will be used to send e-mail. I > would like to write the code test-first as much as possible. However, I > notice that that Java Mail API makes heavy use of static methods to > accomplish many of its tasks. I see that there are Mock implementations > of things like Transport and Message in the Mock Objects library, but > I'm not sure how to make use of them. Are there any simple examples of > using the MockObjects library to test things that use things like > javax.mail.Transport (and related classes?) > > Thanks. > |
From: Griffin C. <gri...@ya...> - 2003-04-29 19:50:47
|
Steve, Can you expand on what a "mock mail provider" entails? -Griffin --- Steve Freeman <st...@m3...> wrote: > One option I considered, but never got around to, > was to implement and > register a mock mail provider. > > S. > > James Howe wrote: > > I'm writing a small utility class which will be > used to send e-mail. I > > would like to write the code test-first as much as > possible. However, I > > notice that that Java Mail API makes heavy use of > static methods to > > accomplish many of its tasks. I see that there > are Mock implementations > > of things like Transport and Message in the Mock > Objects library, but > > I'm not sure how to make use of them. Are there > any simple examples of > > using the MockObjects library to test things that > use things like > > javax.mail.Transport (and related classes?) > > > > Thanks. > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-users mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users ===== Griffin Caprio "Your child against mine. The winner will be hailed, the loser will be booed until my throat hurts!" - Homer Simpson to Marge __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com |
From: Steve F. <st...@m3...> - 2003-04-30 13:22:57
|
From what I remember, you can register an implementation to provide mail for a given transport, it's in the API somewhere. When I was looking, I didn't have time to figure out how to plug in to that. S. Griffin Caprio wrote: > Steve, > > Can you expand on what a "mock mail provider" entails? > > -Griffin > --- Steve Freeman <st...@m3...> wrote: > >>One option I considered, but never got around to, >>was to implement and >>register a mock mail provider. >> >>S. >> >>James Howe wrote: >> >>>I'm writing a small utility class which will be >> >>used to send e-mail. I >> >>>would like to write the code test-first as much as >> >>possible. However, I >> >>>notice that that Java Mail API makes heavy use of >> >>static methods to >> >>>accomplish many of its tasks. I see that there >> >>are Mock implementations >> >>>of things like Transport and Message in the Mock >> >>Objects library, but >> >>>I'm not sure how to make use of them. Are there >> >>any simple examples of >> >>>using the MockObjects library to test things that >> >>use things like >> >>>javax.mail.Transport (and related classes?) >>> >>>Thanks. >>> >> >> >> >> > ------------------------------------------------------- > >>This sf.net email is sponsored by:ThinkGeek >>Welcome to geek heaven. >>http://thinkgeek.com/sf >>_______________________________________________ >>Mockobjects-java-users mailing list >>Moc...@li... >> > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users > > > ===== > Griffin Caprio > "Your child against mine. The winner > will be hailed, the loser will be booed > until my throat hurts!" - Homer Simpson to Marge > > __________________________________ > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo. > http://search.yahoo.com |
From: Jeff M. <je...@mk...> - 2003-04-30 11:52:42
|
The mocks for Transport/Message etc are mocks of the alt.javax interfaces. Which have both mock and real implementations. The real implementations being wrappers around the javax.mail.* classes. http://www.mockobjects.com/javadoc/1.3/alt/javax/mail/package-summary.html On Tue, 2003-04-29 at 19:40, James Howe wrote: > I'm writing a small utility class which will be used to send e-mail. I > would like to write the code test-first as much as possible. However, I > notice that that Java Mail API makes heavy use of static methods to > accomplish many of its tasks. I see that there are Mock implementations of > things like Transport and Message in the Mock Objects library, but I'm not > sure how to make use of them. Are there any simple examples of using the > MockObjects library to test things that use things like > javax.mail.Transport (and related classes?) > > Thanks. -- Jeff Martin <je...@mk...> |
From: James H. <jw...@al...> - 2003-04-30 14:24:53
|
Ok, I found those definitions but I guess I'm a little fuzzy on how to best make use of them in writing my code and tests. Are there any examples of how to make use of these classes? I'm assuming this approach also falls into a pattern for mocking up code which needs to use functionality normally provided by static methods. I'd be interested in seeing some examples of this pattern in action as well. Thanks. On 30 Apr 2003 12:54:31 +0100, Jeff Martin <je...@mk...> wrote: > The mocks for Transport/Message etc are mocks of the alt.javax > interfaces. Which have both mock and real implementations. The real > implementations being wrappers around the javax.mail.* classes. > > http://www.mockobjects.com/javadoc/1.3/alt/javax/mail/package- > summary.html > > On Tue, 2003-04-29 at 19:40, James Howe wrote: >> I'm writing a small utility class which will be used to send e-mail. I >> would like to write the code test-first as much as possible. However, I >> notice that that Java Mail API makes heavy use of static methods to >> accomplish many of its tasks. I see that there are Mock implementations >> of things like Transport and Message in the Mock Objects library, but >> I'm not sure how to make use of them. Are there any simple examples of >> using the MockObjects library to test things that use things like >> javax.mail.Transport (and related classes?) >> >> Thanks. -- James Howe |
From: Steve F. <st...@m3...> - 2003-04-30 14:51:46
|
I never had the time to do it. The public API selects a provider implementation based on some kind of lookup and calls through to it. In theory, we could intercept that lookup and make it call through to a mock implementation that we provide. S. James Howe wrote: > Ok, I found those definitions but I guess I'm a little fuzzy on how to > best make use of them in writing my code and tests. Are there any > examples of how to make use of these classes? I'm assuming this > approach also falls into a pattern for mocking up code which needs to > use functionality normally provided by static methods. I'd be > interested in seeing some examples of this pattern in action as well. |
From: Jeff M. <je...@mk...> - 2003-04-30 15:16:05
|
Probably need to write a class a little like this. class MyMailer{ MimeMessageFactory messageFactory; Session session; MyMailer(MimeMessageFactory messageFactory, Session session, Transport transport){ this.messageFactory = messageFactory; this.session = session; this.transport = transport; } send(MyStuff stuff){ MimeMessage message = messageFactory.createMimeMessage(session); // set things on message from stuff. transport.send(message); } } You can then test it by passing mock version of session, transport and messagefactory in. On Wed, 2003-04-30 at 15:23, James Howe wrote: > Ok, I found those definitions but I guess I'm a little fuzzy on how to best > make use of them in writing my code and tests. Are there any examples of > how to make use of these classes? I'm assuming this approach also falls > into a pattern for mocking up code which needs to use functionality > normally provided by static methods. I'd be interested in seeing some > examples of this pattern in action as well. > > Thanks. > > On 30 Apr 2003 12:54:31 +0100, Jeff Martin <je...@mk...> wrote: > > > The mocks for Transport/Message etc are mocks of the alt.javax > > interfaces. Which have both mock and real implementations. The real > > implementations being wrappers around the javax.mail.* classes. > > > > http://www.mockobjects.com/javadoc/1.3/alt/javax/mail/package- > > summary.html > > > > On Tue, 2003-04-29 at 19:40, James Howe wrote: > >> I'm writing a small utility class which will be used to send e-mail. I > >> would like to write the code test-first as much as possible. However, I > >> notice that that Java Mail API makes heavy use of static methods to > >> accomplish many of its tasks. I see that there are Mock implementations > >> of things like Transport and Message in the Mock Objects library, but > >> I'm not sure how to make use of them. Are there any simple examples of > >> using the MockObjects library to test things that use things like > >> javax.mail.Transport (and related classes?) > >> > >> Thanks. -- Jeff Martin <je...@mk...> |