]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java
Default property editing restores assertions
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / junit / v2 / ModelledSTSSuiteRunner.java
1 package org.simantics.tests.modelled.junit.v2;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.junit.runner.Description;
9 import org.junit.runner.notification.Failure;
10 import org.junit.runner.notification.RunNotifier;
11 import org.junit.runners.ParentRunner;
12 import org.junit.runners.model.InitializationError;
13 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
14 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
15 import org.simantics.tests.modelled.utils.ModelledSTSTest;
16 import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
17
18 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
19
20     private final ModelledSTSSuite suite;
21     private final List<ModelledSTSTestRunner> children;
22     private Map<String, List<CommandSessionVariable>> storedVariables = new HashMap<>();
23
24     public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
25         super(ModelledSTSSuiteRunner.class);
26         this.suite = suite;
27         this.children = new ArrayList<>(suite.getChildren().size());
28         for (ModelledSTSTest test : suite.getSortedChildren()) {
29             children.add(new ModelledSTSTestRunner(test));
30         }
31     }
32
33     @Override
34     protected String getName() {
35         return suite.getName();
36     }
37
38     @Override
39     protected List<ModelledSTSTestRunner> getChildren() {
40         return children;
41     }
42
43     @Override
44     protected Description describeChild(ModelledSTSTestRunner child) {
45         return child.getDescription();
46     }
47
48     @Override
49     protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
50         Description description = describeChild(child);
51         if (isIgnored(child)) {
52             notifier.fireTestIgnored(description);
53         } else {
54             try {
55                 List<CommandSessionVariable> variables = new ArrayList<>();
56                 for (String dep : child.getTest().getDependencies()) {
57                     List<CommandSessionVariable> storedVars = storedVariables.get(dep);
58                     if (storedVars != null) {
59                         variables.addAll(storedVars);
60                     }
61                 }
62                 notifier.fireTestStarted(description);
63                 List<CommandSessionVariable> newVars = child.runWithVars(variables);
64                 storedVariables.put(child.getTest().getName(), newVars);
65                 notifier.fireTestFinished(description);
66             } catch (Throwable e) {
67                 notifier.fireTestFailure(new Failure(description, e));
68             }
69         } 
70     }
71
72     @Override
73     protected boolean isIgnored(ModelledSTSTestRunner child) {
74         return child.isIgnored();
75     }
76
77     public CombinedCoverage getCoverage() {
78         return suite.getCoverage();
79     }
80
81 }