### Question:
TreeMetaDataProvider { public Optional<Token> firstToken(TextRange textRange) { int textRangeIndex = indexOfFirstElement(sortedTokens, textRange); if (textRangeIndex == -1) { return Optional.empty(); } else { return Optional.of(sortedTokens.get(textRangeIndex)); } } 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 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.firstToken(range(1, 0, 1, 1)).isPresent()).isFalse(); assertThat(provider.firstToken(range(1, 1, 1, 3)).get().text()).isEqualTo("ab"); assertThat(provider.firstToken(range(1, 2, 1, 20)).get().text()).isEqualTo("cd"); assertThat(provider.firstToken(range(1, 5, 1, 20)).isPresent()).isFalse(); }