⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emailtest.java

📁 也是apache的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        catch (EmailException e)        {            assertTrue(true);        }        // ====================================================================        // Exception (Empty Collection)        // ====================================================================        try        {            this.email.setCc(new ArrayList());            fail("Should have thrown an exception");        }        catch (EmailException e)        {            assertTrue(true);        }    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddBcc() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        List arrExpected = new ArrayList();        arrExpected.add(new InternetAddress("me@home.com", "me@home.com"));        arrExpected.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org"));        arrExpected.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            // add a valid bcc            this.email.addBcc(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getBccList().size());        assertEquals(            arrExpected.toString(),            this.email.getBccList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddBccWithEncoding() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        String testCharset = Email.ISO_8859_1;        List arrExpected = new ArrayList();        arrExpected.add(            new InternetAddress(                "me@home.com",                "me@home.com",                testCharset));        arrExpected.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org",                testCharset));        arrExpected.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au",                testCharset));        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            // set bccs            this.email.addBcc(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getBccList().size());        assertEquals(            arrExpected.toString(),            this.email.getBccList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddBcc2() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        String[] testEmailNames = {"Name1", "", null};        List arrExpected = new ArrayList();        arrExpected.add(new InternetAddress("me@home.com", "Name1"));        arrExpected.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org"));        arrExpected.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            // set from            this.email.addBcc(ARR_VALID_EMAILS[i], testEmailNames[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getBccList().size());        assertEquals(            arrExpected.toString(),            this.email.getBccList().toString());        // ====================================================================        // Test Exceptions        // ====================================================================        // reset the mail class        MockEmailConcrete anotherEmail = new MockEmailConcrete();        // bad encoding        try        {            // set a dodgy encoding scheme            anotherEmail.addBcc("me@home.com", "me@home.com", "bad.encoding\uc5ec\n");            fail("setting invalid charset should have failed!");        }        catch (IllegalCharsetNameException e)        {            // expected runtime exception.        }    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testSetBcc() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        List testInetEmailValid = new ArrayList();        testInetEmailValid.add(new InternetAddress("me@home.com", "Name1"));        testInetEmailValid.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org"));        testInetEmailValid.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        this.email.setBcc(testInetEmailValid);        assertEquals(testInetEmailValid, this.email.getBccList());        // ====================================================================        // Exception (Null Input)        // ====================================================================        try        {            this.email.setBcc(null);            fail("Should have thrown an exception");        }        catch (EmailException e)        {            assertTrue(true);        }        // ====================================================================        // Exception (Empty Collection)        // ====================================================================        try        {            this.email.setBcc(new ArrayList());            fail("Should have thrown an exception");        }        catch (EmailException e)        {            assertTrue(true);        }    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddReplyTo() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        List arrExpected = new ArrayList();        arrExpected.add(new InternetAddress("me@home.com", "me@home.com"));        arrExpected.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org"));        arrExpected.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            // set replyTo            this.email.addReplyTo(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getReplyList().size());        assertEquals(            arrExpected.toString(),            this.email.getReplyList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddReplyToWithEncoding() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        String testCharset = Email.ISO_8859_1;        List arrExpected = new ArrayList();        arrExpected.add(            new InternetAddress(                "me@home.com",                "me@home.com",                testCharset));        arrExpected.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org",                testCharset));        arrExpected.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au",                testCharset));        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            // set replyTo            this.email.addReplyTo(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getReplyList().size());        assertEquals(            arrExpected.toString(),            this.email.getReplyList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddReplyTo2() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        String[] testEmailNames = {"Name1", "", null};        List arrExpected = new ArrayList();        arrExpected.add(new InternetAddress("me@home.com", "Name1"));        arrExpected.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org"));        arrExpected.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            // set replyTo            this.email.addReplyTo(ARR_VALID_EMAILS[i], testEmailNames[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getReplyList().size());        assertEquals(            arrExpected.toString(),            this.email.getReplyList().toString());        // ====================================================================        // Test Exceptions        // ====================================================================        // reset the mail class        MockEmailConcrete anotherEmail = new MockEmailConcrete();        // bad encoding        try        {            // set a dodgy encoding scheme            anotherEmail.addReplyTo("me@home.com", "me@home.com", "bad.encoding\uc5ec\n");            fail("setting invalid charset should have failed!");        }        catch (IllegalCharsetNameException e)        {            // expected runtime exception.        }    }    /** */    public void testAddHeader()    {        // ====================================================================        // Test Success        // ====================================================================        Map ht = new Hashtable();        ht.put("X-Priority", "1");        ht.put("Disposition-Notification-To", "me@home.com");        ht.put("X-Mailer", "Sendmail");        for (Iterator items = ht.entrySet().iterator(); items.hasNext();)        {            Map.Entry entry = (Map.Entry) items.next();            String strName = (String) entry.getKey();            String strValue = (String) entry.getValue();            this.email.addHeader(strName, strValue);        }        assertEquals(ht.size(), this.email.getHeaders().size());        assertEquals(ht, this.email.getHeaders());    }    /** */    public void testAddHeaderEx()    {        // ====================================================================        // Test Exceptions        // ====================================================================        Map htBad = new Hashtable();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -