1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 package com.ibm.icu.dev.test.rbbi; 4 5 import java.text.CharacterIterator; 6 7 import org.junit.Before; 8 import org.junit.Test; 9 10 import com.ibm.icu.dev.test.TestFmwk; 11 import com.ibm.icu.text.BreakIterator; 12 13 /** 14 * @author sgill 15 * 16 */ 17 public class AbstractBreakIteratorTests extends TestFmwk { 18 19 private class AbstractBreakIterator extends BreakIterator { 20 private int position = 0; 21 private static final int LIMIT = 100; 22 23 private int set(int n) { 24 position = n; 25 if (position > LIMIT) { 26 position = LIMIT; 27 return DONE; 28 } 29 if (position < 0) { 30 position = 0; 31 return DONE; 32 } 33 return position; 34 } 35 36 @Override 37 public int first() { 38 return set(0); 39 } 40 41 @Override 42 public int last() { 43 return set(LIMIT); 44 } 45 46 @Override 47 public int next(int n) { 48 return set(position + n); 49 } 50 51 @Override 52 public int next() { 53 return next(1); 54 } 55 56 @Override 57 public int previous() { 58 return next(-1); 59 } 60 61 @Override 62 public int following(int offset) { 63 return set(offset + 1); 64 } 65 66 @Override 67 public int current() { 68 return position; 69 } 70 71 @Override 72 public CharacterIterator getText() { 73 return null; 74 } 75 76 @Override 77 public void setText(CharacterIterator newText) { 78 } 79 80 } 81 82 private BreakIterator bi; 83 84 @Before 85 public void createBreakIterator() { 86 bi = new AbstractBreakIterator(); 87 } 88 89 @Test 90 public void testPreceding() { 91 int pos = bi.preceding(0); 92 TestFmwk.assertEquals("BreakIterator preceding position not correct", BreakIterator.DONE, pos); 93 94 pos = bi.preceding(5); 95 TestFmwk.assertEquals("BreakIterator preceding position not correct", 4, pos); 96 } 97 98 @Test 99 public void testIsBoundary() { 100 boolean b = bi.isBoundary(0); 101 TestFmwk.assertTrue("BreakIterator is boundary not correct", b); 102 103 b = bi.isBoundary(5); 104 TestFmwk.assertTrue("BreakIterator is boundary not correct", b); 105 } 106 107 } 108