Hi!
Just like many other people writing to this list i am new to unittest and jmock and i cant figure out why
that new jmock test i wrote runs good weather i test it against fail or true (weather its will(returnValue(true)) or will(returnValue(false))).
Well at least one should have failed but both run just fine.
The following is my jmock test i am working on:
------------------------------------------------------------------------------------------------
import org.jmock.Expectations;
import javax.mail.*;
import org.jmock.lib.legacy.*;
public class MailSenderBeanTest extends TestCase {
private Mockery context = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
public void testOneSubscriberReceivesAMessage() throws javax.mail.MessagingException {
final MailSenderBean msb = context.mock(saab.ecm.bo.MailSenderBean.class);
--------------------------------------------------------------------------------------------------
And i have a following method in my MailSenderBean that i am writing jmock test for
--------------------------------------------------------------------------------------------------
public boolean sendMail(String from, String to,
String subject, String text, String smtpHost){
boolean sent = true;
boolean debug = false; // true to get more information
// set the host
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
Session session = Session.getInstance(props, null);
session.setDebug(debug);
try
{
Message msg = new MimeMessage(session);
InternetAddress iafrom = new InternetAddress(from);
msg.setFrom(iafrom);
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(text);
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
InternetAddress replyTo[] = new InternetAddress[1];
replyTo[0] = iafrom;
msg.setReplyTo(replyTo);
this.getTransport(msg);
} catch(MessagingException e) {
LOG.error("sending status:Failed ", e);
sent = false;
}
return sent;
}
------------------------------------------------------------------------------
Please help,
Alexander