Skip to content

Commit

Permalink
Bump mockito to 5.14.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbylight committed Nov 29, 2024
1 parent c754c90 commit 68ab6e8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
import org.fife.ui.rsyntaxtextarea.parser.Parser;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.DefaultHighlighter;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;


/**
* Unit tests for the {@link RSyntaxTextArea} class.
Expand Down Expand Up @@ -791,33 +796,17 @@ void testSyntaxEditingStyle() {
@Test
void testSyntaxEditingStyle_dontUpdateDocumentIfCalledViaSetDocument() {

// Unfortunately we can't use Mockito here because of its issues
// running in Java 17 (as of Mockito 4.4.0).
int[] stringOverloadCalled = { 0 };
int[] tokenMakerOverloadCalled = { 0 };

RSyntaxDocument doc = new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_NONE) {
@Override
public void setSyntaxStyle(TokenMaker tm) {
tokenMakerOverloadCalled[0]++;
super.setSyntaxStyle(tm);
}
@Override
public void setSyntaxStyle(String style) {
stringOverloadCalled[0]++;
super.setSyntaxStyle(style);
}
};
doc.setSyntaxStyle(new JavaTokenMaker());
RSyntaxTextArea textArea = new RSyntaxTextArea(doc);
RSyntaxDocument doc = new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_NONE);
RSyntaxDocument docSpy = Mockito.spy(doc);
docSpy.setSyntaxStyle(new JavaTokenMaker());
new RSyntaxTextArea(docSpy);

// Verify the Document has its syntax style set only once, by the explicit
// call to the setSyntaxStyle(TokenMaker) overload.
// Verifying the string overload isn't called (after the initial call
// Specifically, the string overload isn't called (after the initial call
// via its constructor) per GitHub issue 206.
Assertions.assertEquals(1, stringOverloadCalled[0]);
Assertions.assertEquals(1, tokenMakerOverloadCalled[0]);

verify(docSpy, times(0)).setSyntaxStyle(ArgumentMatchers.anyString());
verify(docSpy, times(1)).setSyntaxStyle(ArgumentMatchers.any(TokenMaker.class));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ void testCommon_yypushback_valid() {
void testCommon_yypushback_invalid() {
TokenMaker tm = createTokenMaker();
if (tm instanceof AbstractJFlexTokenMaker) {
Assertions.assertThrows(Error.class, () -> {
((AbstractJFlexTokenMaker)tm).yypushback(1);
});
Assertions.assertThrows(Error.class, () ->
((AbstractJFlexTokenMaker)tm).yypushback(1)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
package org.fife.ui.rtextarea;

import org.fife.ui.SwingRunnerExtension;
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.awt.*;

Expand All @@ -18,7 +21,6 @@
* @author Robert Futrell
* @version 1.0
*/
// TODO: Mock various OS code paths when migrating to Java 11/Mockito 5.x
@ExtendWith(SwingRunnerExtension.class)
class FontUtilTest {

Expand Down Expand Up @@ -80,12 +82,41 @@ void testDeriveFont_4Arg_noChange() {


@Test
void testGetDefaultMonospacedFont() {
// Unfortunately we can't test platform-specific code paths
// even with setting os.name, since that causes specific
// sun.awt.*FontManager class implementations to be looked
// that are platform-specific and not in all JREs.
Font font = FontUtil.getDefaultMonospacedFont();
Assertions.assertNotNull(font);
void testGetDefaultMonospacedFont_linux() {
try (MockedStatic<RSyntaxUtilities> utils = Mockito.mockStatic(RSyntaxUtilities.class)) {
utils.when(RSyntaxUtilities::getOS).thenReturn(RSyntaxUtilities.OS_LINUX);
// Can't verify too precisely since the test can run on any OS
Assertions.assertNotNull(FontUtil.getDefaultMonospacedFont());
}
}


@Test
void testGetDefaultMonospacedFont_macOS() {
try (MockedStatic<RSyntaxUtilities> utils = Mockito.mockStatic(RSyntaxUtilities.class)) {
utils.when(RSyntaxUtilities::getOS).thenReturn(RSyntaxUtilities.OS_MAC_OSX);
// Can't verify too precisely since the test can run on any OS
Assertions.assertNotNull(FontUtil.getDefaultMonospacedFont());
}
}


@Test
void testGetDefaultMonospacedFont_other() {
try (MockedStatic<RSyntaxUtilities> utils = Mockito.mockStatic(RSyntaxUtilities.class)) {
utils.when(RSyntaxUtilities::getOS).thenReturn(RSyntaxUtilities.OS_OTHER);
// Can't verify too precisely since the test can run on any OS
Assertions.assertNotNull(FontUtil.getDefaultMonospacedFont());
}
}


@Test
void testGetDefaultMonospacedFont_windows() {
try (MockedStatic<RSyntaxUtilities> utils = Mockito.mockStatic(RSyntaxUtilities.class)) {
utils.when(RSyntaxUtilities::getOS).thenReturn(RSyntaxUtilities.OS_WINDOWS);
// Can't verify too precisely since the test can run on any OS
Assertions.assertNotNull(FontUtil.getDefaultMonospacedFont());
}
}
}
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.gradle.api.JavaVersion

buildscript {
repositories {
mavenCentral()
Expand Down Expand Up @@ -82,7 +80,7 @@ subprojects {
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.3'
testImplementation 'org.mockito:mockito-inline:4.11.0'
testImplementation 'org.mockito:mockito-core:5.14.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.3'
}

Expand Down

0 comments on commit 68ab6e8

Please sign in to comment.