1 /* 2 * Copyright (C) 2007 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 android.text; 18 19 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertNotNull; 22 23 import android.text.style.BulletSpan; 24 import android.text.style.QuoteSpan; 25 import android.text.style.SubscriptSpan; 26 import android.text.style.UnderlineSpan; 27 28 import org.junit.Test; 29 30 public class SpannableStringBuilderTest extends SpannableTest { 31 32 protected Spannable newSpannableWithText(String text) { 33 return new SpannableStringBuilder(text); 34 } 35 36 @Test 37 public void testGetSpans_sortsByPriorityEvenWhenSortParamIsFalse() { 38 String text = "p_in_s"; 39 SpannableStringBuilder builder = new SpannableStringBuilder(text); 40 Object first = new SubscriptSpan(); 41 Object second = new UnderlineSpan(); 42 Object third = new BulletSpan(); 43 Object fourth = new QuoteSpan(); 44 45 builder.setSpan(first, 2, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 46 builder.setSpan(second, 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 47 builder.setSpan(third, 2, text.length(), 1 << Spanned.SPAN_PRIORITY_SHIFT); 48 builder.setSpan(fourth, 0, text.length(), 2 << Spanned.SPAN_PRIORITY_SHIFT); 49 50 Object[] spans = builder.getSpans(0, text.length(), Object.class, false); 51 52 assertNotNull(spans); 53 assertEquals(4, spans.length); 54 // priority spans are first 55 assertEquals(fourth, spans[0]); 56 assertEquals(third, spans[1]); 57 // other spans should be there 58 assertEquals(second, spans[2]); 59 assertEquals(first, spans[3]); 60 } 61 } 62