public void simulateTypedWord(CharSequence typedWord) {
    final var typedCodes = new int[1];
    mTypedWord.insert(mCursorPosition, typedWord);

    int index = 0;
    while (index < typedWord.length()) {
      final int codePoint = Character.codePointAt(typedWord, index);
      typedCodes[0] = codePoint;
      final var codesFromPool = getReusableArray(typedCodes);
      mCodes.add(mTypedWord.codePointCount(0, mCursorPosition), codesFromPool);
      if (Character.isUpperCase(codePoint)) mCapsCount++;
      final var charCount = Character.charCount(codePoint);
      index += charCount;
      mCursorPosition += charCount;
    }
  }
@Test
  public void testSimulateTypedWord() {
    final var underTest = new WordComposer();

    underTest.simulateTypedWord("hello");
    Assert.assertEquals("hello", underTest.getTypedWord());
    Assert.assertEquals(5, underTest.charCount());
    Assert.assertEquals(5, underTest.codePointCount());
    Assert.assertEquals(5, underTest.cursorPosition());

    Assert.assertArrayEquals(new int[] {'h'}, underTest.getCodesAt(0));
    Assert.assertArrayEquals(new int[] {'o'}, underTest.getCodesAt(4));

    underTest.simulateTypedWord("there");
    Assert.assertEquals("hellothere", underTest.getTypedWord());
    Assert.assertEquals(10, underTest.charCount());
    Assert.assertEquals(10, underTest.codePointCount());
    Assert.assertEquals(10, underTest.cursorPosition());

    Assert.assertArrayEquals(new int[] {'h'}, underTest.getCodesAt(0));
    Assert.assertArrayEquals(new int[] {'o'}, underTest.getCodesAt(4));
    Assert.assertArrayEquals(new int[] {'t'}, underTest.getCodesAt(5));
    Assert.assertArrayEquals(new int[] {'e'}, underTest.getCodesAt(9));

    underTest.setCursorPosition(2);

    underTest.simulateTypedWord("wr");
    Assert.assertEquals("hewrllothere", underTest.getTypedWord());
    Assert.assertEquals(12, underTest.charCount());
    Assert.assertEquals(12, underTest.codePointCount());
    Assert.assertEquals(4, underTest.cursorPosition());

    Assert.assertArrayEquals(new int[] {'h'}, underTest.getCodesAt(0));
    Assert.assertArrayEquals(new int[] {'o'}, underTest.getCodesAt(6));
    Assert.assertArrayEquals(new int[] {'t'}, underTest.getCodesAt(7));
    Assert.assertArrayEquals(new int[] {'e'}, underTest.getCodesAt(11));
    Assert.assertArrayEquals(new int[] {'w'}, underTest.getCodesAt(2));
    Assert.assertArrayEquals(new int[] {'r'}, underTest.getCodesAt(3));
  }