1 /* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mail.ui; 19 20 import android.test.AndroidTestCase; 21 import android.text.SpannableStringBuilder; 22 import android.test.suitebuilder.annotation.SmallTest; 23 24 @SmallTest 25 public class HierarchicalFolderTruncationTests extends AndroidTestCase { 26 27 private HierarchicalFolderSelectorAdapter mAdapter; 28 29 @Override 30 protected void setUp() throws Exception { 31 super.setUp(); 32 mAdapter = new HierarchicalFolderSelectorAdapter(mContext, null, null, 1); 33 } 34 35 public void testEmpty() { 36 assertNull(truncate(null)); 37 } 38 39 public void testNoParents() { 40 assertEquals("name", truncate("name")); 41 } 42 43 public void testSingleParent() { 44 assertEquals("parent\u2215folder", truncate("parent/folder")); 45 } 46 47 public void testDoubleParent() { 48 assertEquals("grandparent\u2215parent\u2215folder", truncate("grandparent/parent/folder")); 49 } 50 51 public void testEllipsizedDoubleParent() { 52 assertEquals("grandparent\u2215\u2026\u2215parent\u2215folder", 53 truncate("grandparent/stuff/stuff/stuff/stuff/parent/folder")); 54 } 55 56 private String truncate(String hierarchy) { 57 final SpannableStringBuilder result = mAdapter.truncateHierarchy(hierarchy); 58 return result == null ? null : result.toString(); 59 } 60 } 61