Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2012 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.vcard.tests;
     18 
     19 import android.content.ContentValues;
     20 import android.provider.ContactsContract;
     21 
     22 import com.android.vcard.VCardBuilder;
     23 import com.android.vcard.VCardConfig;
     24 import com.google.android.collect.Lists;
     25 
     26 import junit.framework.TestCase;
     27 
     28 import java.util.ArrayList;
     29 
     30 /**
     31  * Unit test for VCardBuilder.
     32  */
     33 public class VCardBuilderTest extends TestCase {
     34 
     35     public void testVCardNameFieldFromDisplayName() {
     36         final ArrayList<ContentValues> contentList = Lists.newArrayList();
     37 
     38         final ContentValues values = new ContentValues();
     39         values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "");
     40         contentList.add(values);
     41 
     42         final VCardBuilder builder = new VCardBuilder(VCardConfig.VCARD_TYPE_DEFAULT);
     43         builder.appendNameProperties(contentList);
     44         final String actual = builder.toString();
     45 
     46         final String expectedCommon = ";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:" +
     47                 "=E0=A4=A8=E0=A5=87";
     48 
     49         final String expectedName = "N" + expectedCommon + ";;;;";
     50         final String expectedFullName = "FN" + expectedCommon;
     51 
     52         assertTrue("Actual value:\n" + actual + " expected to contain\n" + expectedName +
     53                 "\nbut does not.", actual.contains(expectedName));
     54         assertTrue("Actual value:\n" + actual + " expected to contain\n" + expectedFullName +
     55                 "\nbut does not.", actual.contains(expectedFullName));
     56     }
     57 }
     58 
     59