1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail

File MailState.java

 
parseWhenUnknownStateString: Invalid mail state [unknown]
 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

10
14
2
1
98
32
10
0.71
7
2
5

Classes

Class Line # Actions
MailState 29 14 0% 10 2
0.923076992.3%
 

Contributing tests

This file is covered by 28 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package org.xwiki.mail;
22   
23    /**
24    * Represents the state of a mail (ready to be sent, sent successfully or failed to be sent).
25    *
26    * @version $Id: b6f0bfa7353ae68b08b1a6263ce83be3375ec18f $
27    * @since 6.4M3
28    */
 
29    public enum MailState
30    {
31    /**
32    * Mail prepared successfully and ready to be sent.
33    * @since 7.1RC1
34    */
35    PREPARE_SUCCESS,
36   
37    /**
38    * Error was encountered during mail preparation, no message available for sending.
39    * @since 7.1RC1
40    */
41    PREPARE_ERROR,
42   
43    /**
44    * Mail sent with success.
45    * @since 7.1RC1
46    */
47    SEND_SUCCESS,
48   
49    /**
50    * Error was encountered during sending mail.
51    * @since 7.1RC1
52    */
53    SEND_ERROR,
54   
55    /**
56    * Error was encountered while retrieving mail for sending.
57    * @since 7.1RC1
58    */
59    SEND_FATAL_ERROR;
60   
61    /**
62    * @return the lower case String version of the enum, to use lowercase String on database
63    */
 
64  177 toggle @Override
65    public String toString()
66    {
67  177 return super.toString().toLowerCase();
68    }
69   
70    /**
71    * Create a MailState object from a String.
72    *
73    * @param state the state represented as a string
74    * @return the MailState object
75    * @throws java.lang.IllegalArgumentException if the passed stated is invalid
76    */
 
77  31 toggle public static MailState parse(String state)
78    {
79    // We support the old enum values READY, SENT, and FAILED from the old API, so that existing script code
80    // using filtering continue to work properly.
81   
82  31 MailState result;
83  31 if (state.equalsIgnoreCase(PREPARE_SUCCESS.toString()) || state.equalsIgnoreCase("READY")) {
84  5 result = PREPARE_SUCCESS;
85  26 } else if (state.equalsIgnoreCase(PREPARE_ERROR.toString())) {
86  4 result = PREPARE_ERROR;
87  22 } else if (state.equalsIgnoreCase(SEND_SUCCESS.toString()) || state.equalsIgnoreCase("SENT")) {
88  13 result = SEND_SUCCESS;
89  9 } else if (state.equalsIgnoreCase(SEND_ERROR.toString()) || state.equalsIgnoreCase("FAILED")) {
90  5 result = SEND_ERROR;
91  3 } else if (state.equalsIgnoreCase(SEND_FATAL_ERROR.toString())) {
92  3 result = SEND_FATAL_ERROR;
93    } else {
94  0 Test failure here throw new IllegalArgumentException(String.format("Invalid mail state [%s]", state));
95    }
96  30 return result;
97    }
98    }