Coverage report

| %line | %branch
--- | --- | ---
com.ozacc.mail.mock.EqualityCheck |
59% |
89% |

1 |  |
     package com.ozacc.mail.mock;
2 |  |
3 |  |
     import javax.mail.internet.InternetAddress;
4 |  |
5 |  |
     import com.ozacc.mail.Mail;
6 |  |
7 |  |
     /**
8 |  |
      * ¥á¡¼¥?¤¬Æ±ÃÍ¤Ç¤¢¤?¤³¤È¤òÄ´¤Ù¤?¥á¥½¥Ã¥É¤òÄó¶¡¡£
9 |  |
      * <p>
10 |  |
      * <strong>Ã?:</strong> ÅºÉÕ¥Õ¥¡¥¤¥?¤ÏÈæ³ÓÂÐ¾Ý¤Ë¤Ê¤ê¤Þ¤»¤ó¡£
11 |  |
      *
12 |  |
      * @since 1.1
13 |  |
      *
14 |  |
      * @author Tomohiro Otsuka
15 |  |
      * @version $Id: EqualityCheck.java,v 1.3.2.1 2004/11/25 08:01:18 otsuka Exp $
16 |  |
      */
17 |  |
     public class EqualityCheck {
18 |  |
19 | 0 |
     	private EqualityCheck() {}
20 |  |
21 |  |
     	/**
22 |  |
     	 * expected¤Èsent¤Î¥á¡¼¥?ÆâÍÆ¤¬Æ±°?¤Ç¤¢¤?¤«¤É¤¦¤«¤òÈ½Äê¤·¤Þ¤¹¡£<br>
23 |  |
     	 * MultipartMail¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤â»ØÄê¤Ç¤¤Þ¤¹¡£Ã¢¤·¡¢ÅºÉÕ¥Õ¥¡¥¤¥?¤Ï¥Á¥§¥Ã¥¯¤µ¤?¤Þ¤»¤ó¡£
24 |  |
     	 *
25 |  |
     	 * @param expected
26 |  |
     	 * @param sent
27 |  |
     	 * @return expected¤Èsent¤Î¥á¡¼¥?ÆâÍÆ¤¬Æ±°?¤Ç¤¢¤?¾?¹? true
28 |  |
     	 */
29 |  |
     	public static boolean equals(Mail expected, Mail sent) {
30 | 5 |
     		boolean mockMode = (expected instanceof MockMail);
31 |  |
32 |  |
     		// ¥Þ¥?¥Á¥Ñ¡¼¥È¥á¡¼¥?¤Î¾?¹?
33 | 5 |
     		if (expected.isMultipartMail()) {
34 |  |
35 |  |
     			// HTML
36 | 0 |
     			if (!mockMode) {
37 | 0 |
     				if ((expected.getHtmlText() == null && sent.getHtmlText() != class="keyword">null)
38 | 0 |
     						|| (expected.getHtmlText() != null && sent.getHtmlText() == class="keyword">null)
39 | 0 |
     						|| (!expected.getHtmlText().equals(sent.getHtmlText()))) {
40 | 0 |
     					return false;
41 |  |
     				}
42 | 0 |
     			} else if (mockMode && expected.getHtmlText() != null) {
43 | 0 |
     				if (!expected.getHtmlText().equals(sent.getHtmlText())) {
44 | 0 |
     					return false;
45 |  |
     				}
46 |  |
     			}
47 |  |
     		}
48 |  |
49 |  |
     		// Return-Path
50 | 5 |
     		if (!mockMode || (mockMode && expected.getReturnPath() != null)) {
51 | 5 |
     			if (expected.getReturnPath() != null && sent.getReturnPath() != class="keyword">null) {
52 | 5 |
     				if (!expected.getReturnPath().equals(sent.getReturnPath())) {
53 | 0 |
     					return false;
54 |  |
     				}
55 | 0 |
     			} else if ((expected.getReturnPath() != null && sent.getReturnPath() == class="keyword">null)
56 | 0 |
     					|| (expected.getReturnPath() == null && sent.getReturnPath() != class="keyword">null)) {
57 | 0 |
     				return false;
58 |  |
     			}
59 |  |
     		}
60 |  |
61 |  |
     		//	From
62 | 5 |
     		if (!mockMode || (mockMode && expected.getFrom() != null)) {
63 | 5 |
     			if (expected.getFrom() != null && sent.getFrom() != class="keyword">null) {
64 | 5 |
     				if (!equals(expected.getFrom(), sent.getFrom())) {
65 | 0 |
     					return false;
66 |  |
     				}
67 | 0 |
     			} else if ((expected.getFrom() != null && sent.getFrom() == class="keyword">null)
68 | 0 |
     					|| (expected.getFrom() == null && sent.getFrom() != class="keyword">null)) {
69 | 0 |
     				return false;
70 |  |
     			}
71 |  |
     		}
72 |  |
73 |  |
     		// to
74 | 5 |
     		InternetAddress[] expectedAddresses = expected.getTo();
75 | 5 |
     		InternetAddress[] sentAddresses = sent.getTo();
76 | 5 |
     		if (!mockMode || (mockMode && expectedAddresses.length > 0)) {
77 | 5 |
     			if (expectedAddresses.length != sentAddresses.length) {
78 | 0 |
     				return false;
79 |  |
     			}
80 | 15 |
     			for (int i = 0; i < expectedAddresses.length; i++) {
81 | 10 |
     				if (!equals(expectedAddresses[i], sentAddresses[i])) {
82 | 0 |
     					return false;
83 |  |
     				}
84 |  |
     			}
85 |  |
     		}
86 |  |
87 |  |
     		// cc
88 | 5 |
     		expectedAddresses = expected.getCc();
89 | 5 |
     		sentAddresses = sent.getCc();
90 | 5 |
     		if (!mockMode || (mockMode && expectedAddresses.length > 0)) {
91 | 5 |
     			if (expectedAddresses.length != sentAddresses.length) {
92 | 0 |
     				return false;
93 |  |
     			}
94 | 15 |
     			for (int i = 0; i < expectedAddresses.length; i++) {
95 | 10 |
     				if (!equals(expectedAddresses[i], sentAddresses[i])) {
96 | 0 |
     					return false;
97 |  |
     				}
98 |  |
     			}
99 |  |
     		}
100 |  |
101 |  |
     		// bcc
102 | 5 |
     		expectedAddresses = expected.getBcc();
103 | 5 |
     		sentAddresses = sent.getBcc();
104 | 5 |
     		if (!mockMode || (mockMode && expectedAddresses.length > 0)) {
105 | 5 |
     			if (expectedAddresses.length != sentAddresses.length) {
106 | 1 |
     				return false;
107 |  |
     			}
108 | 8 |
     			for (int i = 0; i < expectedAddresses.length; i++) {
109 | 4 |
     				if (!equals(expectedAddresses[i], sentAddresses[i])) {
110 | 0 |
     					return false;
111 |  |
     				}
112 |  |
     			}
113 |  |
     		}
114 |  |
115 |  |
     		// Reply-To
116 | 4 |
     		if (!mockMode || (mockMode && expected.getReplyTo() != null)) {
117 | 4 |
     			if (expected.getReplyTo() != null && sent.getReplyTo() != class="keyword">null) {
118 | 4 |
     				if (!equals(expected.getReplyTo(), sent.getReplyTo())) {
119 | 0 |
     					return false;
120 |  |
     				}
121 | 0 |
     			} else if ((expected.getReplyTo() != null && sent.getReplyTo() == class="keyword">null)
122 | 0 |
     					|| (expected.getReplyTo() == null && sent.getReplyTo() != class="keyword">null)) {
123 | 0 |
     				return false;
124 |  |
     			}
125 |  |
     		}
126 |  |
127 |  |
     		// ·?Ì¾
128 | 4 |
     		if (!mockMode || (mockMode && expected.getSubject().length() > 0)) {
129 | 4 |
     			if (!expected.getSubject().equals(sent.getSubject())) {
130 | 0 |
     				return false;
131 |  |
     			}
132 |  |
     		}
133 |  |
134 |  |
     		// ËÜÊ¸
135 | 4 |
     		if (!mockMode || (mockMode && expected.getText().length() > 0)) {
136 | 4 |
     			if (!expected.getText().equals(sent.getText())) {
137 | 0 |
     				return false;
138 |  |
     			}
139 |  |
     		}
140 |  |
141 | 4 |
     		return true;
142 |  |
     	}
143 |  |
144 |  |
     	/**
145 |  |
     	 * »ØÄê¤µ¤?¤¿Æó¤Ä¤ÎInternetAddress¥¤¥ó¥¹¥¿¥ó¥¹¤¬Åù¤·¤¤¤«¤É¤¦¤«È½Äê¤·¤Þ¤¹¡£
146 |  |
     	 * <p>
147 |  |
     	 * InternetAddress#equals()¥á¥½¥Ã¥É¤Ç¤Ï¡¢¥á¡¼¥?¥¢¥É¥?¥¹¤·¤«¸¡ºº¤·¤Ê¤¤¤¿¤á¡¢
148 |  |
     	 * ¤³¤Î¥á¥½¥Ã¥É¤Ç¤ÏInternetAddress¤ËÌ¾Á°¤¬´Þ¤Þ¤?¤Æ¤¤¤?¾?¹ç¡¢¤½¤ÎÌ¾Á°¤?
149 |  |
     	 * Åù¤·¤¤¤«¤É¤¦¤«¸¡ºº¤·¤Þ¤¹¡£
150 |  |
     	 *
151 |  |
     	 * @since 1.1.3
152 |  |
     	 * @param a Èæ³Ó¤¹¤?InternetAddress¥¤¥ó¥¹¥¿¥ó¥¹
153 |  |
     	 * @param b Èæ³Ó¤¹¤?InternetAddress¥¤¥ó¥¹¥¿¥ó¥¹
154 |  |
     	 * @return Æó¤Ä¤ÎInternetAddress¥¤¥ó¥¹¥¿¥ó¥¹¤¬Åù¤·¤¤¾?¹? true
155 |  |
     	 */
156 |  |
     	public static boolean equals(InternetAddress a, InternetAddress b) {
157 | 48 |
     		if (a.equals(b)) {
158 | 46 |
     			if (a.getPersonal() != null || b.getPersonal() != class="keyword">null) {
159 | 19 |
     				return a.getPersonal().equals(b.getPersonal());
160 |  |
     			} else {
161 | 27 |
     				return true;
162 |  |
     			}
163 |  |
     		}
164 | 2 |
     		return false;
165 |  |
     	}
166 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.