-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 592: RTextArea.setUI should not override non-UIResource Fonts
- Loading branch information
1 parent
8a5d657
commit 54a2d04
Showing
2 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
RSyntaxTextArea/src/test/java/org/fife/ui/rtextarea/RTextAreaUITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* This library is distributed under a modified BSD license. See the included | ||
* LICENSE file for details. | ||
*/ | ||
package org.fife.ui.rtextarea; | ||
|
||
import org.fife.ui.SwingRunnerExtension; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import javax.swing.*; | ||
import javax.swing.plaf.FontUIResource; | ||
import java.awt.*; | ||
|
||
|
||
/** | ||
* Unit tests for {@code RTextAreaUI}. | ||
*/ | ||
@ExtendWith(SwingRunnerExtension.class) | ||
class RTextAreaUITest extends AbstractRTextAreaTest { | ||
|
||
@Test | ||
void testCreateUI_error_notRTextArea() { | ||
Assertions.assertThrows(IllegalArgumentException.class, | ||
() -> RTextAreaUI.createUI(new JTextArea())); | ||
} | ||
|
||
@Test | ||
void testCreateUI_happyPath() { | ||
Assertions.assertDoesNotThrow(() -> RTextAreaUI.createUI(new RTextArea())); | ||
} | ||
|
||
@Test | ||
void testInstallDefaults_doesNotOverrideRegularFont() { | ||
|
||
RTextArea textArea = new RTextArea(); | ||
Font oldFont = new Font(FontUIResource.DIALOG, FontUIResource.ITALIC, 23); | ||
textArea.setFont(oldFont); | ||
|
||
RTextAreaUI ui = (RTextAreaUI)textArea.getUI(); | ||
ui.installDefaults(); | ||
Assertions.assertEquals(oldFont, textArea.getFont()); | ||
} | ||
|
||
@Test | ||
void testInstallDefaults_overridesFontUIResource() { | ||
|
||
RTextArea textArea = new RTextArea(); | ||
Font oldFont = new FontUIResource(FontUIResource.DIALOG, FontUIResource.ITALIC, 23); | ||
textArea.setFont(oldFont); | ||
|
||
RTextAreaUI ui = (RTextAreaUI)textArea.getUI(); | ||
ui.installDefaults(); | ||
Assertions.assertEquals(RTextArea.getDefaultFont(), textArea.getFont()); | ||
} | ||
|
||
@Test | ||
void testInstallDefaults_overridesNullFont() { | ||
|
||
RTextArea textArea = new RTextArea(); | ||
textArea.setFont(null); | ||
|
||
RTextAreaUI ui = (RTextAreaUI)textArea.getUI(); | ||
ui.installDefaults(); | ||
Assertions.assertEquals(RTextArea.getDefaultFont(), textArea.getFont()); | ||
} | ||
|
||
@Test | ||
void testInstallUI_error_notRTextArea() { | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> { | ||
RTextAreaUI ui = new RTextAreaUI(new RTextArea()); | ||
ui.installUI(new JTextArea()); | ||
}, "RTextAreaUI needs an instance of RTextArea!"); | ||
} | ||
|
||
@Test | ||
void testInstallUI_happyPath() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
}); | ||
} | ||
|
||
@Test | ||
void testPaintBackground_nullBackground_noError() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
textArea.setBackground(null); | ||
ui.paintBackground(createTestGraphics()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testPaintCurrentLineHighlight_false() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
textArea.setHighlightCurrentLine(false); | ||
ui.paintCurrentLineHighlight(createTestGraphics(), textArea.getVisibleRect()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testPaintCurrentLineHighlight_true() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
textArea.setHighlightCurrentLine(true); | ||
ui.paintCurrentLineHighlight(createTestGraphics(), textArea.getVisibleRect()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testPaintCurrentLineHighlight_true_andFadeCurrentLineHighlight() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
textArea.setHighlightCurrentLine(true); | ||
textArea.setFadeCurrentLineHighlight(true); | ||
ui.paintCurrentLineHighlight(createTestGraphics(), textArea.getVisibleRect()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testPaintMarginLine_false() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
textArea.setMarginLineEnabled(false); | ||
ui.paintMarginLine(createTestGraphics(), textArea.getVisibleRect()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testPaintMarginLine_true() { | ||
Assertions.assertDoesNotThrow(() -> { | ||
RTextArea textArea = new RTextArea(); | ||
RTextAreaUI ui = new RTextAreaUI(textArea); | ||
ui.installUI(textArea); | ||
textArea.setMarginLineEnabled(true); | ||
ui.paintMarginLine(createTestGraphics(), textArea.getVisibleRect()); | ||
}); | ||
} | ||
} |