1 11 12 package org.eclipse.jdt.internal.junit.model; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.jdt.junit.model.ITestElement; 18 import org.eclipse.jdt.junit.model.ITestSuiteElement; 19 20 21 public class TestSuiteElement extends TestElement implements ITestSuiteElement { 22 23 private List fChildren; 24 private Status fChildrenStatus; 25 26 public TestSuiteElement(TestSuiteElement parent, String id, String testName, int childrenCount) { 27 super(parent, id, testName); 28 fChildren= new ArrayList (childrenCount); 29 } 30 31 34 public Result getTestResult(boolean includeChildren) { 35 if (includeChildren) { 36 return getStatus().convertToResult(); 37 } else { 38 return super.getStatus().convertToResult(); 39 } 40 } 41 42 45 public String getSuiteTypeName() { 46 return getClassName(); 47 } 48 49 52 public ITestElement[] getChildren() { 53 return (ITestElement[]) fChildren.toArray(new ITestElement[fChildren.size()]); 54 } 55 56 public void addChild(TestElement child) { 57 fChildren.add(child); 58 } 59 60 public Status getStatus() { 61 Status suiteStatus= getSuiteStatus(); 62 if (fChildrenStatus != null) { 63 return Status.combineStatus(fChildrenStatus, suiteStatus); 65 } else { 66 return suiteStatus; 67 } 68 } 69 70 private Status getCumulatedStatus() { 71 TestElement[] children= (TestElement[]) fChildren.toArray(new TestElement[fChildren.size()]); if (children.length == 0) 73 return getSuiteStatus(); 74 75 Status cumulated= children[0].getStatus(); 76 77 for (int i= 1; i < children.length; i++) { 78 Status childStatus= children[i].getStatus(); 79 cumulated= Status.combineStatus(cumulated, childStatus); 80 } 81 return cumulated; 85 } 86 87 public Status getSuiteStatus() { 88 return super.getStatus(); 89 } 90 91 public void childChangedStatus(TestElement child, Status childStatus) { 92 int childCount= fChildren.size(); 93 if (child == fChildren.get(0) && childStatus.isRunning()) { 94 internalSetChildrenStatus(childStatus); 96 return; 97 } 98 TestElement lastChild= (TestElement) fChildren.get(childCount - 1); 99 if (child == lastChild) { 100 if (childStatus.isDone()) { 101 internalSetChildrenStatus(getCumulatedStatus()); 103 return; 104 } 105 107 } else if (! lastChild.getStatus().isNotRun()) { 108 internalSetChildrenStatus(getCumulatedStatus()); 110 return; 111 } 112 113 if (childStatus.isFailure()) { 115 if (fChildrenStatus == null || ! fChildrenStatus.isErrorOrFailure()) { 116 internalSetChildrenStatus(Status.RUNNING_FAILURE); 117 return; 118 } 119 } else if (childStatus.isError()) { 120 if (fChildrenStatus == null || ! fChildrenStatus.isError()) { 121 internalSetChildrenStatus(Status.RUNNING_ERROR); 122 return; 123 } 124 } 125 } 126 127 private void internalSetChildrenStatus(Status status) { 128 if (fChildrenStatus == status) 129 return; 130 fChildrenStatus= status; 131 TestSuiteElement parent= getParent(); 132 if (parent != null) 133 parent.childChangedStatus(this, getStatus()); 134 } 135 136 public String toString() { 137 return "TestSuite: " + getSuiteTypeName() + " : " + super.toString() + " (" + fChildren.size() + ")"; } 139 140 } 141 | Popular Tags |