Rfc822OutputTests.java revision 2d5691cac1874eb3491353ab608a84c2a75e2b62
1f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank/* 2f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Copyright (C) 2009 The Android Open Source Project 3f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * 4f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Licensed under the Apache License, Version 2.0 (the "License"); 5f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * you may not use this file except in compliance with the License. 6f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * You may obtain a copy of the License at 7f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * 8f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * http://www.apache.org/licenses/LICENSE-2.0 9f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * 10f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Unless required by applicable law or agreed to in writing, software 11f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * distributed under the License is distributed on an "AS IS" BASIS, 12f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * See the License for the specific language governing permissions and 14f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * limitations under the License. 15f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank */ 16f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 17f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blankpackage com.android.email.mail.transport; 18f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 19f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blankimport com.android.email.provider.EmailContent.Message; 20f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 21f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blankimport android.test.AndroidTestCase; 22f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 23f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank/** 24f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Tests of the Rfc822Output (used for sending mail) 25f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * 26f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * You can run this entire test case with: 27f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * runtest -c com.android.email.mail.transport.Rfc822OutputTests email 28f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank */ 29f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blankpublic class Rfc822OutputTests extends AndroidTestCase { 30f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String SENDER = "sender@android.com"; 31f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String REPLYTO = "replyto@android.com"; 32f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String RECIPIENT_TO = "recipient-to@android.com"; 33f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String RECIPIENT_CC = "recipient-cc@android.com"; 34f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String RECIPIENT_BCC = "recipient-bcc@android.com"; 35f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String SUBJECT = "This is the subject"; 36f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String BODY = "This is the body. This is also the body."; 371d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank private static final String TEXT = "Here is some new text."; 38f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String REPLY_BODY_SHORT = "\n\n" + SENDER + " wrote:\n\n"; 39f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank private static final String REPLY_BODY = REPLY_BODY_SHORT + ">" + BODY; 40f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 41f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank // TODO Create more tests here. Specifically, we should test to make sure that forward works 42f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank // properly instead of just reply 43f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 442d5691cac1874eb3491353ab608a84c2a75e2b62Marc Blank // TODO Write test that ensures that bcc is handled properly (i.e. sent/not send depending 452d5691cac1874eb3491353ab608a84c2a75e2b62Marc Blank // on the flag passed to writeTo 462d5691cac1874eb3491353ab608a84c2a75e2b62Marc Blank 471d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank // TODO Localize the following test, which will not work properly in other than English 481d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank // speaking locales! 492d5691cac1874eb3491353ab608a84c2a75e2b62Marc Blank 50f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank /** 51f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Test for buildBodyText(). 52f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Compare with expected values. 53f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank * Also test the situation where the message has no body. 541d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank * 551d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank * WARNING: This test is NOT localized, so it will fail if run on a device in a 561d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank * non-English speaking locale! 57f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank */ 581d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank public void testBuildBodyTextWithReply() { 59f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank // Create the least necessary; sender, flags, and the body of the reply 60f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank Message msg = new Message(); 61f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.mText = ""; 62f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.mFrom = SENDER; 63f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.mFlags = Message.FLAG_TYPE_REPLY; 64f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.mTextReply = BODY; 65f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.save(getContext()); 66f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 671d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank String body = Rfc822Output.buildBodyText(getContext(), msg, true); 68f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank assertEquals(REPLY_BODY, body); 69f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank 70f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank // Save a different message with no reply body (so we reset the id) 71f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.mId = -1; 72f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.mTextReply = null; 73f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank msg.save(getContext()); 741d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank body = Rfc822Output.buildBodyText(getContext(), msg, true); 75f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank assertEquals(REPLY_BODY_SHORT, body); 76f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank } 771d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank 781d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank /** 791d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank * Test for buildBodyText(). 801d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank * Compare with expected values. 811d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank * Also test the situation where the message has no body. 821d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank */ 831d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank public void testBuildBodyTextWithoutReply() { 841d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank // Create the least necessary; sender, flags, and the body of the reply 851d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank Message msg = new Message(); 861d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.mText = TEXT; 871d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.mFrom = SENDER; 881d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.mFlags = Message.FLAG_TYPE_REPLY; 891d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.mTextReply = BODY; 901d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.save(getContext()); 911d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank 921d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank String body = Rfc822Output.buildBodyText(getContext(), msg, false); 931d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank assertEquals(TEXT, body); 941d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank 951d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank // Save a different message with no reply body (so we reset the id) 961d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.mId = -1; 971d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.mTextReply = null; 981d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank msg.save(getContext()); 991d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank body = Rfc822Output.buildBodyText(getContext(), msg, false); 1001d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank assertEquals(TEXT, body); 1011d98989222f2d023ddb08a70d5abb850029f95dcMarc Blank } 102f2dded3a2fba83dd3f0d14cce6abe467a4ab66ebMarc Blank } 103