]> gerrit.simantics Code Review - simantics/platform.git/blob
a568976cc6da745db0beba6a818ad738c98487c7
[simantics/platform.git] /
1 package org.simantics.tests.modelled.junit.v2;
2
3 import java.util.List;
4 import java.util.stream.Collectors;
5
6 import org.junit.runner.Description;
7 import org.junit.runner.notification.Failure;
8 import org.junit.runner.notification.RunNotifier;
9 import org.junit.runners.ParentRunner;
10 import org.simantics.scl.compiler.commands.CommandSession;
11 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
12 import org.simantics.scl.osgi.SCLOsgi;
13 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
14 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
15
16 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
17
18     private final ModelledSTSSuite suite;
19     private CommandSession commandSession;
20
21     public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws Exception {
22         super(ModelledSTSSuiteRunner.class);
23         this.suite = suite;
24     }
25
26     @Override
27     protected String getName() {
28         return suite.getName();
29     }
30
31     @Override
32     protected List<ModelledSTSTestRunner> getChildren() {
33         return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList());
34     }
35
36     @Override
37     protected Description describeChild(ModelledSTSTestRunner child) {
38         return child.getDescription();
39     }
40
41     @Override
42     protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
43         Description description = describeChild(child);
44         if (isIgnored(child)) {
45             notifier.fireTestIgnored(description);
46         } else {
47             notifier.fireTestStarted(description);
48             try {
49                 child.run(getCommandSession());
50                 notifier.fireTestFinished(description);
51                 STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession());
52             } catch (Throwable e) {
53                 notifier.fireTestFailure(new Failure(description, e));
54             }
55         }
56     }
57
58     @Override
59     protected boolean isIgnored(ModelledSTSTestRunner child) {
60         return child.isIgnored();
61     }
62
63     public void setCommandSesssion(CommandSession commandSession) {
64         this.commandSession = commandSession;
65     }
66
67     public CommandSession getCommandSession() {
68         if (commandSession == null)
69             commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
70         return commandSession;
71     }
72
73     public CombinedCoverage getCoverage() {
74         return suite.getCoverage();
75     }
76
77 }