Browse Source

Test: Ensure laf doesn't get installed multiple times.

pull/245/head
weisj 3 years ago
parent
commit
afbd91d58a
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 13
      core/src/test/java/test/CustomTitleBarTest.java
  2. 9
      core/src/test/java/test/FontTest.java
  3. 2
      core/src/test/java/test/MemoryTest.java
  4. 9
      core/src/test/java/test/TestUtils.java
  5. 4
      core/src/test/java/test/TooltipTest.java

13
core/src/test/java/test/CustomTitleBarTest.java

@ -36,8 +36,6 @@ import org.junit.jupiter.api.condition.OS;
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.color.ColorUtil;
import com.github.weisj.darklaf.theme.DarculaTheme;
import com.github.weisj.darklaf.theme.IntelliJTheme;
import com.github.weisj.darklaf.ui.rootpane.DarkRootPaneUI;
import com.github.weisj.darklaf.util.SystemInfo;
@ -55,12 +53,13 @@ class CustomTitleBarTest extends AbstractImageTest {
@BeforeAll
static void setup() {
LafManager.registerInitTask((t, d) -> {
TestUtils.runOnSwingThreadNotThrowing(() -> LafManager.registerInitTask((t, d) -> {
d.put("MacOS.TitlePane.background", TITLE_BAR_COLOR);
d.put("MacOS.TitlePane.inactiveBackground", TITLE_BAR_COLOR);
d.put("Windows.TitlePane.background", TITLE_BAR_COLOR);
d.put("Windows.TitlePane.inactiveBackground", TITLE_BAR_COLOR);
});
}));
TestUtils.ensureLafInstalled();
}
@BeforeEach
@ -155,7 +154,6 @@ class CustomTitleBarTest extends AbstractImageTest {
@Test
@EnabledOnOs({OS.MAC, OS.WINDOWS})
void checkTitleBarColored() {
SwingUtilities.invokeLater(() -> LafManager.install(new IntelliJTheme()));
UIManager.put("macos.coloredTitleBar", true);
checkImage("colored_title_" + SystemInfo.getOsName(),
img -> assertScreenColorEquals(TITLE_BAR_COLOR, new Color(img.getRGB(img.getWidth() / 2, TITLE_BAR_Y)),
@ -165,7 +163,6 @@ class CustomTitleBarTest extends AbstractImageTest {
@Test
@EnabledOnOs(OS.MAC)
void checkTitleBarNotColored() {
SwingUtilities.invokeLater(() -> LafManager.install(new IntelliJTheme()));
UIManager.put("macos.coloredTitleBar", false);
checkImage("non_colored_title_" + SystemInfo.getOsName(), img -> {
Color c = new Color(img.getRGB(img.getWidth() / 2, TITLE_BAR_Y));
@ -177,7 +174,6 @@ class CustomTitleBarTest extends AbstractImageTest {
@Test
@EnabledOnOs(OS.MAC)
void checkForDarkNativeTitle() {
SwingUtilities.invokeLater(() -> LafManager.install(new DarculaTheme()));
UIManager.put("macos.coloredTitleBar", false);
checkImage("native_title_dark_mac", img -> {
assertScreenColorNotEquals(CONTENT_COLOR, new Color(img.getRGB(img.getWidth() / 2, TITLE_BAR_Y)),
@ -192,7 +188,6 @@ class CustomTitleBarTest extends AbstractImageTest {
@Test
@EnabledOnOs(OS.MAC)
void checkForLightNativeTitle() {
SwingUtilities.invokeLater(() -> LafManager.install(new IntelliJTheme()));
UIManager.put("macos.coloredTitleBar", false);
checkImage("native_title_light_mac", img -> {
assertScreenColorNotEquals(CONTENT_COLOR, new Color(img.getRGB(img.getWidth() / 2, TITLE_BAR_Y)),
@ -207,7 +202,6 @@ class CustomTitleBarTest extends AbstractImageTest {
@Test
@EnabledOnOs({OS.MAC, OS.WINDOWS})
void checkTitleBarHidden() {
TestUtils.runOnSwingThreadNotThrowing(() -> LafManager.install(new IntelliJTheme()));
UIManager.put("macos.coloredTitleBar", true);
Assertions.assertTrue(LafManager.isDecorationsEnabled());
checkImage("title_bar_hidden_" + SystemInfo.getOsName(),
@ -222,7 +216,6 @@ class CustomTitleBarTest extends AbstractImageTest {
@Test
@EnabledOnOs(OS.WINDOWS)
void checkDisableCustomDecoration() {
SwingUtilities.invokeLater(() -> LafManager.install(new IntelliJTheme()));
checkImage("native_title_bar_window",
f -> LafManager.setDecorationsEnabled(false),
img -> assertScreenColorNotEquals(TITLE_BAR_COLOR,

9
core/src/test/java/test/FontTest.java

@ -32,14 +32,13 @@ import java.util.Map;
import javax.swing.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import ui.DemoResources;
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.theme.IntelliJTheme;
import com.github.weisj.darklaf.util.SystemInfo;
class FontTest extends AbstractImageTest {
@ -54,10 +53,14 @@ class FontTest extends AbstractImageTest {
super("font");
}
@BeforeAll
static void setup() {
TestUtils.ensureLafInstalled();
}
@Test
@EnabledOnOs({OS.MAC, OS.WINDOWS, OS.LINUX})
void testFontChoices() {
LafManager.install(new IntelliJTheme());
JTextArea textArea = new JTextArea();
textArea.setText(DemoResources.KERNING_TEST);
textArea.setSize(textArea.getPreferredSize());

2
core/src/test/java/test/MemoryTest.java

@ -54,7 +54,7 @@ class MemoryTest {
@BeforeAll
static void setupLaf() {
TestUtils.runOnSwingThreadNotThrowing(LafManager::install);
TestUtils.ensureLafInstalled();
}
@BeforeEach

9
core/src/test/java/test/TestUtils.java

@ -26,12 +26,21 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.swing.*;
import com.github.weisj.darklaf.theme.IntelliJTheme;
import org.junit.jupiter.api.Assertions;
import com.github.weisj.darklaf.LafManager;
final class TestUtils {
private TestUtils() {}
static void ensureLafInstalled() {
if (!LafManager.isInstalled()) {
runOnSwingThreadNotThrowing(() -> LafManager.install(new IntelliJTheme()));
}
}
static void runOnThreadNotThrowing(final Runnable action) {
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
try {

4
core/src/test/java/test/TooltipTest.java

@ -33,8 +33,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.theme.IntelliJTheme;
import com.github.weisj.darklaf.ui.DarkPopupFactory;
import com.github.weisj.darklaf.ui.tooltip.ToolTipConstants;
import com.github.weisj.darklaf.util.DarkUIUtil;
@ -51,7 +49,7 @@ class TooltipTest extends AbstractImageTest {
@BeforeAll
static void setup() {
TestUtils.runOnSwingThreadNotThrowing(() -> LafManager.install(new IntelliJTheme()));
TestUtils.ensureLafInstalled();
}
private JToolTip createTooltip() {

Loading…
Cancel
Save