Browse Source

Test: Iterate over all spec combinations if extensive testing is enabled.

For now this options is disabled as the number of combinations gets very large.
modulesv2
weisj 3 years ago
parent
commit
730147262f
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 28
      core/src/test/java/com/github/weisj/darklaf/core/test/DemoTest.java
  2. 11
      core/src/test/java/com/github/weisj/darklaf/ui/DemoLauncher.java

28
core/src/test/java/com/github/weisj/darklaf/core/test/DemoTest.java

@ -33,6 +33,9 @@ import java.util.logging.Logger;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import com.github.weisj.darklaf.ui.demo.ComponentDemo;
import com.github.weisj.darklaf.ui.demo.DemoSpec;
import com.github.weisj.darklaf.util.Pair;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -42,11 +45,13 @@ import com.github.weisj.darklaf.ui.DemoLauncher;
import com.github.weisj.darklaf.util.Lambdas;
import com.github.weisj.darklaf.util.LogUtil;
import javax.swing.JComponent;
import javax.swing.UIManager;
class DemoTest implements NonThreadSafeTest {
private static final Logger LOGGER = LogUtil.getLogger(DemoTest.class);
private static final boolean EXTENSIVE = false;
@Test
void runningDemosDoesNotThrow() {
@ -86,7 +91,9 @@ class DemoTest implements NonThreadSafeTest {
return;
}
try {
AtomicReference<Window> windowRef = demo.start(Level.WARNING);
Pair<AtomicReference<Window>, ComponentDemo> startedDemo = demo.start(Level.WARNING);
AtomicReference<Window> windowRef = startedDemo.getFirst();
ComponentDemo componentDemo = startedDemo.getSecond();
if (robot != null) robot.waitForIdle();
synchronized (windowRef) {
while (windowRef.get() == null) {
@ -95,6 +102,9 @@ class DemoTest implements NonThreadSafeTest {
}
TestUtils.runOnSwingThreadNotThrowing(
() -> Assertions.assertNotNull(windowRef.get()));
TestUtils.runOnSwingThreadNotThrowing(
() -> testConfigurations(componentDemo));
if (!demo.isDarklafOnly()) {
TestUtils.runOnSwingThreadNotThrowing(() -> {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
@ -109,4 +119,20 @@ class DemoTest implements NonThreadSafeTest {
}
}
private void testConfigurations(final ComponentDemo demo) {
if (!EXTENSIVE) return;
final List<DemoSpec<?>> specs = demo.getSpecs();
testConfigurations(demo.getComponent(), specs, 0);
}
@SuppressWarnings("unchecked")
private void testConfigurations(final JComponent c, final List<DemoSpec<?>> specs, final int index) {
if (index >= specs.size()) return;
DemoSpec<Object> spec = (DemoSpec<Object>) specs.get(index);
for (Object possibleValue : spec.getPossibleValues()) {
spec.set(c, possibleValue);
testConfigurations(c, specs, index + 1);
}
}
}

11
core/src/test/java/com/github/weisj/darklaf/ui/DemoLauncher.java

@ -36,6 +36,8 @@ import com.github.weisj.darklaf.core.test.util.Instantiable;
import com.github.weisj.darklaf.ui.demo.BaseComponentDemo;
import com.github.weisj.darklaf.ui.demo.ComponentDemo;
import com.github.weisj.darklaf.ui.demo.DemoExecutor;
import com.github.weisj.darklaf.util.LazyValue;
import com.github.weisj.darklaf.util.Pair;
public class DemoLauncher extends BaseComponentDemo {
@ -91,11 +93,14 @@ public class DemoLauncher extends BaseComponentDemo {
}
public AtomicReference<Window> start() {
return start(null);
return start(null).getFirst();
}
public AtomicReference<Window> start(final Level logLevel) {
return DemoExecutor.showDemo(demo.instantiate(), true, logLevel);
public Pair<AtomicReference<Window>, ComponentDemo> start(final Level logLevel) {
ComponentDemo componentDemo = demo.instantiate();
return new Pair<>(
DemoExecutor.showDemo(componentDemo, true, logLevel),
componentDemo);
}
@Override

Loading…
Cancel
Save