1 /*
2 * Copyright 2006-2010 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.springframework.batch.sample.domain.mail.internal;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21
22 import org.springframework.batch.item.mail.MailErrorHandler;
23 import org.springframework.mail.MailMessage;
24
25 /**
26 * This handler prints out failed messages with their exceptions. It also
27 * maintains a list of all failed messages it receives for lookup later by an
28 * assertion.
29 *
30 * @author Dan Garrette
31 * @author Dave Syer
32 *
33 * @since 2.1
34 */
35 public class TestMailErrorHandler implements MailErrorHandler {
36
37 private List<MailMessage> failedMessages = new ArrayList<MailMessage>();
38
39 public void handle(MailMessage failedMessage, Exception ex) {
40 this.failedMessages.add(failedMessage);
41 System.out.println("Mail message failed: " + failedMessage);
42 System.out.println(ex);
43 }
44
45 public List<MailMessage> getFailedMessages() {
46 return failedMessages;
47 }
48
49 public void clear() {
50 this.failedMessages.clear();
51 }
52 }