1 /* 2 * Copyright (C) 2008 The Android Open Source Project 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 com.android.email.mail.transport; 18 19 import com.android.email.mail.transport.MailTransport; 20 21 import android.test.AndroidTestCase; 22 import android.test.suitebuilder.annotation.SmallTest; 23 24 import java.net.URI; 25 import java.net.URISyntaxException; 26 27 /** 28 * Simple unit tests for MailSender. Tests here should not attempt any actual connections. 29 */ 30 @SmallTest 31 public class MailTransportUnitTests extends AndroidTestCase { 32 33 /** 34 * Tests of the Uri parsing logic 35 */ 36 public void testUriParsing() throws URISyntaxException { 37 38 // Parse with everything in the Uri 39 URI uri = new URI("smtp://user:password (at) server.com:999"); 40 MailTransport transport = new MailTransport("SMTP"); 41 transport.setUri(uri, 888); 42 assertEquals("server.com", transport.getHost()); 43 assertEquals(999, transport.getPort()); 44 String[] userInfoParts = transport.getUserInfoParts(); 45 assertNotNull(userInfoParts); 46 assertEquals("user", userInfoParts[0]); 47 assertEquals("password", userInfoParts[1]); 48 49 // Parse with no user/password (e.g. anonymous SMTP) 50 uri = new URI("smtp://server.com:999"); 51 transport = new MailTransport("SMTP"); 52 transport.setUri(uri, 888); 53 assertEquals("server.com", transport.getHost()); 54 assertEquals(999, transport.getPort()); 55 assertNull(transport.getUserInfoParts()); 56 } 57 } 58