Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 129929 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/internal/junit/ui/TestViewer.java (-25 / +24 lines)
Lines 12-21 Link Here
12
package org.eclipse.jdt.internal.junit.ui;
12
package org.eclipse.jdt.internal.junit.ui;
13
13
14
import java.util.AbstractList;
14
import java.util.AbstractList;
15
import java.util.ArrayList;
16
import java.util.Arrays;
15
import java.util.Arrays;
17
import java.util.HashSet;
16
import java.util.HashSet;
18
import java.util.Iterator;
17
import java.util.Iterator;
18
import java.util.LinkedHashSet;
19
import java.util.LinkedList;
19
import java.util.LinkedList;
20
import java.util.List;
20
import java.util.List;
21
import java.util.ListIterator;
21
import java.util.ListIterator;
Lines 461-494 Link Here
461
461
462
	private void updateElementInTree(final TestElement testElement) {
462
	private void updateElementInTree(final TestElement testElement) {
463
		if (isShown(testElement)) {
463
		if (isShown(testElement)) {
464
			ArrayList toCreate= null;
464
			updateShownElementInTree(testElement);
465
			TestElement current= testElement;
466
			while (! (current instanceof TestRoot)) {
467
				if (fTreeViewer.testFindItem(current) == null) {
468
					if (toCreate == null)
469
						toCreate= new ArrayList();
470
					toCreate.add(current);
471
				} else {
472
					TestElement parent= current;
473
					if (toCreate != null) {
474
						ListIterator iter= toCreate.listIterator(toCreate.size()); // backwards, top first
475
						while (iter.hasPrevious()) {
476
							TestElement child= (TestElement) iter.previous();
477
							fTreeViewer.add(parent, child);
478
							parent= child;
479
						}
480
					}					
481
					fTreeViewer.update(current, null);
482
				}
483
				current= (TestElement) fTreeContentProvider.getParent(current);
484
			}
485
			
486
		} else {
465
		} else {
487
			TestElement current= testElement;
466
			TestElement current= testElement;
488
			do {
467
			do {
489
				fTreeViewer.remove(current);
468
				if (fTreeViewer.testFindItem(current) != null)
469
					fTreeViewer.remove(current);
490
				current= current.getParent();
470
				current= current.getParent();
491
			} while (! (current instanceof TestRoot) && ! isShown(current));
471
			} while (! (current instanceof TestRoot) && ! isShown(current));
472
			
473
			while (current != null && ! (current instanceof TestRoot)) {
474
				fTreeViewer.update(current, null);
475
				current= current.getParent();
476
			}
477
		}
478
	}
479
480
	private void updateShownElementInTree(TestElement testElement) {
481
		if (testElement == null || testElement instanceof TestRoot) // paranoia null check
482
			return;
483
		
484
		TestSuiteElement parent= testElement.getParent();
485
		updateShownElementInTree(parent); // make sure parent is shown and up-to-date
486
		
487
		if (fTreeViewer.testFindItem(testElement) == null) {
488
			fTreeViewer.add(parent, testElement); // if not yet in tree: add
489
		} else {
490
			fTreeViewer.update(testElement, null); // if in tree: update
492
		}
491
		}
493
	}
492
	}
494
493
Lines 640-646 Link Here
640
	}
639
	}
641
640
642
	private void clearUpdateAndExpansion() {
641
	private void clearUpdateAndExpansion() {
643
		fNeedUpdate= new HashSet();
642
		fNeedUpdate= new LinkedHashSet();
644
		fAutoClose= new LinkedList();
643
		fAutoClose= new LinkedList();
645
		fAutoExpand= new HashSet();
644
		fAutoExpand= new HashSet();
646
	}
645
	}
(-)src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java (-4 / +4 lines)
Lines 73-84 Link Here
73
			Status status=testCaseElement.getStatus();
73
			Status status=testCaseElement.getStatus();
74
			if (status.isNotRun())
74
			if (status.isNotRun())
75
				return fTestRunnerPart.fTestIcon;
75
				return fTestRunnerPart.fTestIcon;
76
			else if (status.isRunning())
77
				return fTestRunnerPart.fTestRunningIcon;
76
			else if (status.isError())
78
			else if (status.isError())
77
				return fTestRunnerPart.fTestErrorIcon;
79
				return fTestRunnerPart.fTestErrorIcon;
78
			else if (status.isFailure())
80
			else if (status.isFailure())
79
				return fTestRunnerPart.fTestFailIcon;
81
				return fTestRunnerPart.fTestFailIcon;
80
			else if (status.isRunning())
81
				return fTestRunnerPart.fTestRunningIcon;
82
			else if (status.isOK())
82
			else if (status.isOK())
83
				return fTestRunnerPart.fTestOkIcon;
83
				return fTestRunnerPart.fTestOkIcon;
84
			else
84
			else
Lines 88-99 Link Here
88
			Status status= ((TestSuiteElement) element).getStatus();
88
			Status status= ((TestSuiteElement) element).getStatus();
89
			if (status.isNotRun())
89
			if (status.isNotRun())
90
				return fTestRunnerPart.fSuiteIcon;
90
				return fTestRunnerPart.fSuiteIcon;
91
			else if (status.isRunning())
92
				return fTestRunnerPart.fSuiteRunningIcon;
91
			else if (status.isError())
93
			else if (status.isError())
92
				return fTestRunnerPart.fSuiteErrorIcon;
94
				return fTestRunnerPart.fSuiteErrorIcon;
93
			else if (status.isFailure())
95
			else if (status.isFailure())
94
				return fTestRunnerPart.fSuiteFailIcon;
96
				return fTestRunnerPart.fSuiteFailIcon;
95
			else if (status.isRunning())
96
				return fTestRunnerPart.fSuiteRunningIcon;
97
			else if (status.isOK())
97
			else if (status.isOK())
98
				return fTestRunnerPart.fSuiteOkIcon;
98
				return fTestRunnerPart.fSuiteOkIcon;
99
			else
99
			else
(-)src/org/eclipse/jdt/internal/junit/model/TestSuiteElement.java (-3 / +40 lines)
Lines 19-44 Link Here
19
	
19
	
20
	private List/*<TestElement>*/ fChildren;
20
	private List/*<TestElement>*/ fChildren;
21
	
21
	
22
	private Status fCachedStatus;
23
	
22
	public TestSuiteElement(TestSuiteElement parent, String id, String testName, int childrenCount) {
24
	public TestSuiteElement(TestSuiteElement parent, String id, String testName, int childrenCount) {
23
		super(parent, id, testName);
25
		super(parent, id, testName);
24
		fChildren= new ArrayList(childrenCount);
26
		fChildren= new ArrayList(childrenCount);
25
	}
27
	}
26
28
27
	public void addChild(TestElement child) {
29
	public synchronized void addChild(TestElement child) {
28
		fChildren.add(child);
30
		fChildren.add(child);
31
		fCachedStatus= null;
29
	}
32
	}
30
	
33
	
31
	public TestElement[] getChildren() {
34
	public synchronized TestElement[] getChildren() {
32
		return (TestElement[]) fChildren.toArray(new TestElement[fChildren.size()]);
35
		return (TestElement[]) fChildren.toArray(new TestElement[fChildren.size()]);
33
	}
36
	}
34
	
37
	
35
	public Status getStatus() {
38
	public Status getStatus() {
39
		synchronized (this) {
40
			if (fCachedStatus != null) {
41
				return fCachedStatus;
42
			} else {
43
				fCachedStatus= Status.NOT_RUN; // fill cache with dummy value (to find out later whether cache has been reset in the meantime)
44
			}
45
		}
46
		
47
		/*
48
		 * Child stati can be changed by another thread, since internalGetStatus() is not synchronized.
49
		 * However, this is not a problem, since every change triggers a UI update event, which in turn
50
		 * causes another call to getStatus() later.
51
		 */
52
		Status status= internalGetStatus(); // do not synchronize call to collect child stati
53
		
54
		synchronized (this) {
55
			if (fCachedStatus == null) {
56
				return status; // cache has been reset -> return current status, but don't store in cache
57
			} else {
58
				fCachedStatus= status; // cache not reset -> flush parents
59
				return status;
60
			}
61
		}
62
		
63
	}
64
	
65
	private Status internalGetStatus() {
36
		//TODO: Cache failure count in hierarchy? Recheck behavior when introducing filters
66
		//TODO: Cache failure count in hierarchy? Recheck behavior when introducing filters
37
		Status suiteStatus= getSuiteStatus();
67
		Status suiteStatus= getSuiteStatus();
38
//		Assert.isTrue(suiteStatus.isNotRun()
68
//		Assert.isTrue(suiteStatus.isNotRun()
39
//				|| (suiteStatus == Status.FAILURE || suiteStatus == Status.ERROR));
69
//				|| (suiteStatus == Status.FAILURE || suiteStatus == Status.ERROR));
40
		
70
		
41
		TestElement[] children= (TestElement[]) fChildren.toArray(new TestElement[fChildren.size()]); // copy list to avoid concurreny problems
71
		TestElement[] children= getChildren(); // copy list to avoid concurreny problems
42
		if (children.length == 0)
72
		if (children.length == 0)
43
			return suiteStatus;
73
			return suiteStatus;
44
		
74
		
Lines 62-65 Link Here
62
		return super.toString() + " (" + fChildren.size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
92
		return super.toString() + " (" + fChildren.size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
63
	}
93
	}
64
94
95
	public synchronized void childChangedStatus() {
96
		fCachedStatus= null;
97
		TestSuiteElement parent= getParent();
98
		if (parent != null)
99
			parent.childChangedStatus();
100
	}
101
65
}
102
}
(-)src/org/eclipse/jdt/internal/junit/model/TestElement.java (-1 / +7 lines)
Lines 155-163 Link Here
155
		fParent= parent;
155
		fParent= parent;
156
		fId= id;
156
		fId= id;
157
		fTestName= testName;
157
		fTestName= testName;
158
		fStatus= Status.NOT_RUN;
158
		if (parent != null)
159
		if (parent != null)
159
			parent.addChild(this);
160
			parent.addChild(this);
160
		fStatus= Status.NOT_RUN;
161
	}
161
	}
162
	
162
	
163
	/**
163
	/**
Lines 183-188 Link Here
183
		//TODO: notify about change?
183
		//TODO: notify about change?
184
		//TODO: multiple errors/failures per test https://bugs.eclipse.org/bugs/show_bug.cgi?id=125296
184
		//TODO: multiple errors/failures per test https://bugs.eclipse.org/bugs/show_bug.cgi?id=125296
185
		fStatus= status;
185
		fStatus= status;
186
		TestSuiteElement parent= getParent();
187
		if (parent != null)
188
			parent.childChangedStatus();
186
	}
189
	}
187
	
190
	
188
	public void setStatus(Status status, String trace, String expected, String actual) {
191
	public void setStatus(Status status, String trace, String expected, String actual) {
Lines 192-197 Link Here
192
		fTrace= trace;
195
		fTrace= trace;
193
		fExpected= expected;
196
		fExpected= expected;
194
		fActual= actual;
197
		fActual= actual;
198
		TestSuiteElement parent= getParent();
199
		if (parent != null)
200
			parent.childChangedStatus();
195
	}
201
	}
196
202
197
	public Status getStatus() {
203
	public Status getStatus() {

Return to bug 129929