1   /*
2    * Copyright 2005-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  
17  package org.springframework.ws.transport.mail.support;
18  
19  import java.net.URI;
20  import javax.mail.URLName;
21  import javax.mail.internet.InternetAddress;
22  
23  import org.junit.Assert;
24  import org.junit.Test;
25  
26  public class MailTransportUtilsTest {
27  
28      @Test
29      public void testToPasswordProtectedString() throws Exception {
30          URLName name = new URLName("imap://john:[email protected]/INBOX");
31          String result = MailTransportUtils.toPasswordProtectedString(name);
32          Assert.assertEquals("Password found in string", -1, result.indexOf("secret"));
33      }
34  
35      @Test
36      public void testGetTo() throws Exception {
37          URI uri = new URI("mailto:[email protected]?subject=current-issue");
38          InternetAddress to = MailTransportUtils.getTo(uri);
39          Assert.assertEquals("Invalid destination", new InternetAddress("[email protected]"), to);
40  
41          uri = new URI("mailto:[email protected]");
42          to = MailTransportUtils.getTo(uri);
43          Assert.assertEquals("Invalid destination", new InternetAddress("[email protected]"), to);
44      }
45  
46      @Test
47      public void testGetSubject() throws Exception {
48          URI uri = new URI("mailto:[email protected]?subject=current-issue");
49          String subject = MailTransportUtils.getSubject(uri);
50          Assert.assertEquals("Invalid destination", "current-issue", subject);
51  
52          uri = new URI("mailto:[email protected]");
53          subject = MailTransportUtils.getSubject(uri);
54          Assert.assertNull("Invalid destination", subject);
55      }
56  }