### Question:
TreeMetaDataProvider { public int indexOfFirstToken(TextRange textRange) { return indexOfFirstElement(sortedTokens, textRange); } TreeMetaDataProvider(List<Comment> comments, List<Token> tokens); List<Comment> allComments(); List<Token> allTokens(); int indexOfFirstToken(TextRange textRange); Optional<Token> firstToken(TextRange textRange); Optional<Token> previousToken(TextRange textRange); Optional<Token> previousToken(TextRange textRange, String expectedTokenValue); Optional<Token> previousToken(TextRange textRange, Predicate<Token> expectedConditionToMatch); void updateTokenType(Token token, Token.Type newType); Token keyword(TextRange textRange); TreeMetaData metaData(TextRange textRange); static final Comparator<HasTextRange> COMPARATOR; }### Answer:
@Test public void index_of_first_token() { Token token1 = new TokenImpl(range(1, 1, 1, 3), "ab", Token.Type.KEYWORD); Token token2 = new TokenImpl(range(1, 4, 1, 6), "cd", Token.Type.KEYWORD); TreeMetaDataProvider provider = new TreeMetaDataProvider(emptyList(), Arrays.asList(token1, token2)); assertThat(provider.indexOfFirstToken(range(1, 0, 1, 1))).isEqualTo(-1); assertThat(provider.indexOfFirstToken(range(1, 0, 1, 2))).isEqualTo(-1); assertThat(provider.indexOfFirstToken(range(1, 0, 1, 3))).isEqualTo(0); assertThat(provider.indexOfFirstToken(range(1, 1, 1, 3))).isEqualTo(0); assertThat(provider.indexOfFirstToken(range(1, 2, 1, 3))).isEqualTo(-1); assertThat(provider.indexOfFirstToken(range(1, 2, 1, 6))).isEqualTo(1); assertThat(provider.indexOfFirstToken(range(1, 4, 1, 6))).isEqualTo(1); assertThat(provider.indexOfFirstToken(range(1, 4, 2, 0))).isEqualTo(1); assertThat(provider.indexOfFirstToken(range(1, 4, 1, 5))).isEqualTo(-1); assertThat(provider.indexOfFirstToken(range(1, 5, 1, 10))).isEqualTo(-1); assertThat(provider.indexOfFirstToken(range(1, 20, 1, 22))).isEqualTo(-1); }