01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.test;
17:
18: import java.util.Iterator;
19:
20: import org.kuali.core.mail.InvalidAddressException;
21: import org.kuali.core.mail.MailMessage;
22: import org.kuali.core.service.MailService;
23: import org.kuali.core.service.impl.MailServiceImpl;
24:
25: /**
26: * A mail service that's used to log messages instead of sending it out (useful for unit testing)
27: */
28: public class NonSendingMailService extends MailServiceImpl implements
29: MailService {
30: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
31: .getLogger(NonSendingMailService.class);
32:
33: /**
34: * @see org.kuali.core.service.impl.MailServiceImpl#sendMessage(org.kuali.core.mail.MailMessage)
35: */
36: @Override
37: public void sendMessage(MailMessage message)
38: throws InvalidAddressException {
39: if (LOG.isInfoEnabled()) {
40: LOG.info("Email message");
41: if (message.getToAddresses().isEmpty()) {
42: LOG.info("No email to address specified");
43: }
44: for (Iterator i = message.getToAddresses().iterator(); i
45: .hasNext();) {
46: LOG.info("Email To: " + i.next());
47: }
48: LOG.info("Email To: " + message.getToAddresses());
49: LOG.info("Email From: " + message.getFromAddress());
50: LOG.info("Email subject: " + message.getSubject());
51: LOG.info("Email message:\n" + message.getMessage());
52: }
53: }
54:
55: }
|