|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.*; |
4 | 4 |
|
| 5 | +import java.util.Collection; |
| 6 | +import java.util.Collections; |
| 7 | + |
5 | 8 | import org.junit.Test; |
6 | 9 |
|
7 | 10 | public class ParagraphTest { |
@@ -37,4 +40,26 @@ public void restylingEmptyParagraphViaStyleSpansWorks() { |
37 | 40 | assertTrue(restyledP.getStyleSpans().styleStream().allMatch( b -> b )); |
38 | 41 | } |
39 | 42 |
|
| 43 | + // Relates to #696 (caused by #685, coming from #449) where an empty |
| 44 | + // StyleSpans being applied to an empty paragraph results in an Exception |
| 45 | + @Test |
| 46 | + public void restylingEmptyParagraphViaEmptyStyleSpansWorks() { |
| 47 | + |
| 48 | + Collection<String> test = Collections.singleton("test"); |
| 49 | + TextOps<String, Collection<String>> segOps = SegmentOps.styledTextOps(); |
| 50 | + Paragraph<Void, String, Collection<String>> p = new Paragraph<>(null, segOps, "", test); |
| 51 | + assertEquals( 0, p.length() ); |
| 52 | + |
| 53 | + StyleSpans<Collection<String>> spans = new StyleSpans<Collection<String>>() |
| 54 | + { |
| 55 | + @Override public Position position( int major, int minor ) { return null; } |
| 56 | + @Override public Position offsetToPosition( int offset, Bias bias ) { return null; } |
| 57 | + @Override public StyleSpan<Collection<String>> getStyleSpan( int index ) { return null; } |
| 58 | + @Override public int getSpanCount() { return 0; } |
| 59 | + @Override public int length() { return 0; } |
| 60 | + }; |
| 61 | + |
| 62 | + Paragraph<Void, String, Collection<String>> restyledP = p.restyle(0, spans); |
| 63 | + assertEquals( test, restyledP.getStyleSpans().getStyleSpan( 0 ).getStyle() ); |
| 64 | + } |
40 | 65 | } |
0 commit comments