-
-
Notifications
You must be signed in to change notification settings - Fork 2
test: add CodeHighlighter unit tests #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.d4rk.androidtutorials.java.utils; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyInt; | ||
| import static org.mockito.Mockito.doAnswer; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| import com.amrdeveloper.codeview.CodeView; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Tests for {@link CodeHighlighter} ensuring themes register syntax patterns and refresh highlighting. | ||
| */ | ||
| public class CodeHighlighterTest { | ||
|
|
||
| @Test | ||
| public void applyJavaTheme_addsPatternsAndReHighlights() { | ||
| CodeView codeView = mock(CodeView.class); | ||
| List<Pattern> patterns = new ArrayList<>(); | ||
| List<Integer> colors = new ArrayList<>(); | ||
|
|
||
| doAnswer(invocation -> { | ||
| patterns.add(invocation.getArgument(0)); | ||
| colors.add(invocation.getArgument(1)); | ||
| return null; | ||
| }).when(codeView).addSyntaxPattern(any(Pattern.class), anyInt()); | ||
|
|
||
| CodeHighlighter.applyJavaTheme(codeView); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Guard unit tests against Android Color dependency Running Useful? React with 👍 / 👎. |
||
|
|
||
| assertEquals(5, patterns.size()); | ||
| assertEquals(5, colors.size()); | ||
| verify(codeView).reHighlightSyntax(); | ||
| } | ||
|
|
||
| @Test | ||
| public void applyXmlTheme_addsPatternsAndReHighlights() { | ||
| CodeView codeView = mock(CodeView.class); | ||
| List<Pattern> patterns = new ArrayList<>(); | ||
| List<Integer> colors = new ArrayList<>(); | ||
|
|
||
| doAnswer(invocation -> { | ||
| patterns.add(invocation.getArgument(0)); | ||
| colors.add(invocation.getArgument(1)); | ||
| return null; | ||
| }).when(codeView).addSyntaxPattern(any(Pattern.class), anyInt()); | ||
|
|
||
| CodeHighlighter.applyXmlTheme(codeView); | ||
|
|
||
| assertEquals(4, patterns.size()); | ||
| assertEquals(4, colors.size()); | ||
| verify(codeView).reHighlightSyntax(); | ||
| } | ||
| } | ||