1 package net.javacoding.jspider.core.util; 2 3 import junit.framework.TestCase; 4 5 import java.net.URL ; 6 7 10 public class EMailAddressUtilTest extends TestCase { 11 12 public EMailAddressUtilTest ( ) { 13 super ( "EMailAddressUtilTest" ); 14 } 15 16 public void testIsEmailAddressSimple ( ) throws Exception { 17 String url = "mailto:test@j-spider.sourceforge.net"; 18 boolean expected = true; 19 applyTestIsEMailAddress ( url, expected ); 20 } 21 22 public void testIsEmailAddressSimpleNoHost ( ) throws Exception { 23 String url = "mailto:test@"; 24 boolean expected = false; 25 applyTestIsEMailAddress ( url, expected ); 26 } 27 28 public void testIsEmailAddressSimpleBadHost ( ) throws Exception { 29 String url = "mailto:test@a.aa"; 30 boolean expected = false; 31 applyTestIsEMailAddress ( url, expected ); 32 } 33 34 public void testIsEmailAddressError ( ) throws Exception { 35 String url = "mailto:testj-spider.sourceforge.net"; 36 boolean expected = false; 37 applyTestIsEMailAddress ( url, expected ); 38 } 39 40 public void testIsEmailAddressErrorDoubleAt ( ) throws Exception { 41 String url = "mailto:test@j-spider@sourceforge.net"; 42 boolean expected = false; 43 applyTestIsEMailAddress ( url, expected ); 44 } 45 46 47 48 49 public void testGetEmailAddressSimple ( ) throws Exception { 50 String url = "mailto:test@j-spider.sourceforge.net"; 51 String expected = "test@j-spider.sourceforge.net"; 52 String actual = EMailAddressUtil.getEMailAddress(new URL (url)); 53 assertEquals("mail address extracted is not as expected", expected, actual); 54 } 55 56 57 58 59 public void testIsFixableEmailAddressSimple ( ) throws Exception { 60 String url = "mailto:test@j-spider.sourceforge.net"; 61 boolean expected = true; 62 applyTestIsFixableEMailAddress ( url, expected ); 63 } 64 65 public void testIsFixableEmailAddressSimpleNoHost ( ) throws Exception { 66 String url = "mailto:test@"; 67 boolean expected = false; 68 applyTestIsFixableEMailAddress ( url, expected ); 69 } 70 71 public void testIsFixableEmailAddressSimpleBadHost ( ) throws Exception { 72 String url = "mailto:test@a.aa"; 73 boolean expected = false; 74 applyTestIsFixableEMailAddress ( url, expected ); 75 } 76 77 public void testIsFixableEmailAddressError ( ) throws Exception { 78 String url = "mailto:testj-spider.sourceforge.net"; 79 boolean expected = false; 80 applyTestIsFixableEMailAddress ( url, expected ); 81 } 82 83 public void testIsFixableEmailAddressErrorDoubleAt ( ) throws Exception { 84 String url = "mailto:test@j-spider@sourceforge.net"; 85 boolean expected = false; 86 applyTestIsFixableEMailAddress ( url, expected ); 87 } 88 89 public void testIsFixableEmailAddressSimpleNoProto ( ) throws Exception { 90 String url = "test@j-spider.sourceforge.net"; 91 boolean expected = true; 92 applyTestIsFixableEMailAddress ( url, expected ); 93 } 94 95 public void testIsFixableEmailAddressSimpleNoHostNoProto ( ) throws Exception { 96 String url = "test@"; 97 boolean expected = false; 98 applyTestIsFixableEMailAddress ( url, expected ); 99 } 100 101 public void testIsFixableEmailAddressSimpleBadHostNoProto ( ) throws Exception { 102 String url = "test@a.aa"; 103 boolean expected = false; 104 applyTestIsFixableEMailAddress ( url, expected ); 105 } 106 107 public void testIsFixableEmailAddressErrorNoProto ( ) throws Exception { 108 String url = "testj-spider.sourceforge.net"; 109 boolean expected = false; 110 applyTestIsFixableEMailAddress ( url, expected ); 111 } 112 113 public void testIsFixableEmailAddressErrorDoubleAtNoProto ( ) throws Exception { 114 String url = "test@j-spider@sourceforge.net"; 115 boolean expected = false; 116 applyTestIsFixableEMailAddress ( url, expected ); 117 } 118 119 120 121 public void testFixEmailAddressSimple ( ) throws Exception { 122 String url = "mailto:test@j-spider.sourceforge.net"; 123 String expected = "mailto:test@j-spider.sourceforge.net"; 124 String actual = EMailAddressUtil.fixEMailAddress(url).toString(); 125 assertEquals("fixed email address not as expected", expected, actual); 126 } 127 128 public void testFixEmailAddressSimpleNoProto ( ) throws Exception { 129 String url = "test@j-spider.sourceforge.net"; 130 String expected = "mailto:test@j-spider.sourceforge.net"; 131 String actual = EMailAddressUtil.fixEMailAddress(url).toString(); 132 assertEquals("fixed email address not as expected", expected, actual); 133 } 134 135 136 137 138 public void applyTestIsEMailAddress ( String urlString, boolean expected ) throws Exception { 139 URL url = new URL (urlString); 140 boolean actual = EMailAddressUtil.isEMailAddress(url); 141 assertEquals("test for mail address result not as expected", expected, actual); 142 } 143 144 public void applyTestIsFixableEMailAddress ( String urlString, boolean expected ) throws Exception { 145 boolean actual = EMailAddressUtil.canBeEMailAddress(urlString); 146 assertEquals("test for fixable mail address result not as expected", expected, actual); 147 } 148 149 } 150 | Popular Tags |