diff --git a/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeHighlighterTest.java b/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeHighlighterTest.java new file mode 100644 index 00000000..45ee4c70 --- /dev/null +++ b/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeHighlighterTest.java @@ -0,0 +1,46 @@ +package com.d4rk.androidtutorials.java.utils; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; + +import com.amrdeveloper.codeview.CodeView; + +import org.junit.Test; +import org.mockito.InOrder; + +import java.util.regex.Pattern; + +/** + * Tests for {@link CodeHighlighter}. + */ +public class CodeHighlighterTest { + + @Test + public void applyJavaTheme_resetsPatternsAndReHighlights() { + CodeView codeView = mock(CodeView.class); + + CodeHighlighter.applyJavaTheme(codeView); + + InOrder order = inOrder(codeView); + order.verify(codeView).resetSyntaxPatternList(); + order.verify(codeView).resetHighlighter(); + order.verify(codeView, times(5)).addSyntaxPattern(any(Pattern.class), anyInt()); + order.verify(codeView).reHighlightSyntax(); + } + + @Test + public void applyXmlTheme_resetsPatternsAndReHighlights() { + CodeView codeView = mock(CodeView.class); + + CodeHighlighter.applyXmlTheme(codeView); + + InOrder order = inOrder(codeView); + order.verify(codeView).resetSyntaxPatternList(); + order.verify(codeView).resetHighlighter(); + order.verify(codeView, times(4)).addSyntaxPattern(any(Pattern.class), anyInt()); + order.verify(codeView).reHighlightSyntax(); + } +} diff --git a/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeViewUtilsTest.java b/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeViewUtilsTest.java index 7c630d5f..6bb2dbdd 100644 --- a/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeViewUtilsTest.java +++ b/app/src/test/java/com/d4rk/androidtutorials/java/utils/CodeViewUtilsTest.java @@ -26,12 +26,24 @@ private void verifyDefaults(CodeView view, Typeface typeface) { } @Test - public void applyDefaults_configuresAllViews() { + public void applyDefaults_configuresNonNullViews() { Typeface typeface = mock(Typeface.class); CodeView first = mock(CodeView.class); CodeView second = mock(CodeView.class); - CodeViewUtils.applyDefaults(typeface, first, second, null); + CodeViewUtils.applyDefaults(typeface, first, second); + + verifyDefaults(first, typeface); + verifyDefaults(second, typeface); + } + + @Test + public void applyDefaults_ignoresNullViews() { + Typeface typeface = mock(Typeface.class); + CodeView first = mock(CodeView.class); + CodeView second = mock(CodeView.class); + + CodeViewUtils.applyDefaults(typeface, null, first, null, second, null); verifyDefaults(first, typeface); verifyDefaults(second, typeface);