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

📄 emailtest.java

📁 也是apache的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        for (int i = 0; i < testEmails.length; i++)        {            // set from            this.email.setFrom(testEmails[i], testEmailNames[i]);            // retrieve and verify            assertEquals(arrExpected.get(i), this.email.getFromAddress());        }        // ====================================================================        // Test Exceptions        // ====================================================================        // reset the mail class        MockEmailConcrete anotherEmail = new MockEmailConcrete();        // bad encoding        try        {            // set a dodgy encoding scheme            anotherEmail.setFrom("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 testAddTo() throws EmailException, UnsupportedEncodingException    {        // ====================================================================        // 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 from            this.email.addTo(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getToList().size());        assertEquals(arrExpected.toString(), this.email.getToList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddToWithEncoding() 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 from            this.email.addTo(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getToList().size());        assertEquals(arrExpected.toString(), this.email.getToList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddTo2() 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.addTo(ARR_VALID_EMAILS[i], testEmailNames[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getToList().size());        assertEquals(arrExpected.toString(), this.email.getToList().toString());        // ====================================================================        // Test Exceptions        // ====================================================================        // reset the mail class        MockEmailConcrete anotherEmail = new MockEmailConcrete();        // bad encoding        try        {            // set a dodgy encoding scheme            anotherEmail.addTo("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 testSetTo() throws UnsupportedEncodingException, EmailException    {        // ====================================================================        // Test Success        // ====================================================================        List testEmailValid2 = new ArrayList();        testEmailValid2.add(new InternetAddress("me@home.com", "Name1"));        testEmailValid2.add(            new InternetAddress(                "joe.doe@apache.org",                "joe.doe@apache.org"));        testEmailValid2.add(            new InternetAddress(                "someone_here@work-address.com.au",                "someone_here@work-address.com.au"));        this.email.setTo(testEmailValid2);        // retrieve and verify        assertEquals(testEmailValid2.size(), this.email.getToList().size());        assertEquals(            testEmailValid2.toString(),            this.email.getToList().toString());        // ====================================================================        // Exception (Null Input)        // ====================================================================        try        {            this.email.setTo(null);            fail("Should have thrown an exception");        }        catch (EmailException e)        {            assertTrue(true);        }        // ====================================================================        // Exception (Empty Collection)        // ====================================================================        try        {            this.email.setTo(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 testAddCc() 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 from            this.email.addCc(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getCcList().size());        assertEquals(arrExpected.toString(), this.email.getCcList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddCcWithEncoding() 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));        // add valid ccs        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)        {            this.email.addCc(ARR_VALID_EMAILS[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getCcList().size());        assertEquals(arrExpected.toString(), this.email.getCcList().toString());    }    /**     * @throws EmailException when there are problems adding an address     * @throws UnsupportedEncodingException on bad email addresses     */    public void testAddCc2() 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.addCc(ARR_VALID_EMAILS[i], testEmailNames[i]);        }        // retrieve and verify        assertEquals(arrExpected.size(), this.email.getCcList().size());        assertEquals(arrExpected.toString(), this.email.getCcList().toString());        // ====================================================================        // Test Exceptions        // ====================================================================        // reset the mail class        MockEmailConcrete anotherEmail = new MockEmailConcrete();        // bad encoding        try        {            // set a dodgy encoding scheme            anotherEmail.addCc("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     */    public void testSetCc() throws EmailException    {        // ====================================================================        // Test Success        // ====================================================================        List testEmailValid2 = new ArrayList();        testEmailValid2.add("Name1 <me@home.com>");        testEmailValid2.add("\"joe.doe@apache.org\" <joe.doe@apache.org>");        testEmailValid2.add(            "\"someone_here@work.com.au\" <someone_here@work.com.au>");        this.email.setCc(testEmailValid2);        assertEquals(testEmailValid2, this.email.getCcList());        // ====================================================================        // Exception (Null Input)        // ====================================================================        try        {            this.email.setCc(null);            fail("Should have thrown an exception");        }

⌨️ 快捷键说明

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