EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.item.mail]

COVERAGE SUMMARY FOR SOURCE FILE [DefaultMailErrorHandler.java]

nameclass, %method, %block, %line, %
DefaultMailErrorHandler.java100% (1/1)100% (3/3)100% (33/33)100% (7/7)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultMailErrorHandler100% (1/1)100% (3/3)100% (33/33)100% (7/7)
DefaultMailErrorHandler (): void 100% (1/1)100% (6/6)100% (2/2)
handle (MailMessage, Exception): void 100% (1/1)100% (23/23)100% (3/3)
setMaxMessageLength (int): void 100% (1/1)100% (4/4)100% (2/2)

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 */
16package org.springframework.batch.item.mail;
17 
18import org.springframework.mail.MailException;
19import org.springframework.mail.MailMessage;
20import org.springframework.mail.MailSendException;
21 
22/**
23 * This {@link MailErrorHandler} implementation simply rethrows the exception it
24 * receives.
25 * 
26 * @author Dan Garrette
27 * @author Dave Syer
28 * 
29 * @since 2.1
30 */
31public class DefaultMailErrorHandler implements MailErrorHandler {
32 
33        private static final int DEFAULT_MAX_MESSAGE_LENGTH = 1024;
34 
35        private int maxMessageLength = DEFAULT_MAX_MESSAGE_LENGTH;
36 
37        /**
38         * The limit for the size of message that will be copied to the exception
39         * message. Output will be truncated beyond that. Default value is 1024.
40         * 
41         * @param maxMessageLength the maximum message length
42         */
43        public void setMaxMessageLength(int maxMessageLength) {
44                this.maxMessageLength = maxMessageLength;
45        }
46 
47        /**
48         * Wraps the input exception with a runtime {@link MailException}. The
49         * exception message will contain the failed message (using toString).
50         * 
51         * @param message a failed message
52         * @param exception a MessagingException
53         * @throws MailException a translation of the Exception
54         * @see MailErrorHandler#handle(MailMessage, Exception)
55         */
56    @Override
57        public void handle(MailMessage message, Exception exception) throws MailException {
58                String msg = message.toString();
59                throw new MailSendException("Mail server send failed: "
60                                + msg.substring(0, Math.min(maxMessageLength, msg.length())), exception);
61        }
62}

[all classes][org.springframework.batch.item.mail]
EMMA 2.0.5312 (C) Vladimir Roubtsov