1 package com
.intellij
.execution
.testframework
.sm
.runner
;
3 import com
.intellij
.openapi
.diagnostic
.Logger
;
4 import org
.jetbrains
.annotations
.NonNls
;
5 import org
.jetbrains
.annotations
.NotNull
;
6 import org
.jetbrains
.annotations
.Nullable
;
8 import java
.util
.EmptyStackException
;
9 import java
.util
.Stack
;
12 * @author Roman Chernyatchik
14 public class TestSuiteStack
{
15 private static final Logger LOG
= Logger
.getInstance(TestSuiteStack
.class.getName());
17 @NonNls private static final String EMPTY
= "empty";
19 private final Stack
<SMTestProxy
> myStack
= new Stack
<SMTestProxy
>();
21 public void pushSuite(@NotNull final SMTestProxy suite
) {
26 * @return Top element of non stack or null for empty stack
29 public SMTestProxy
getCurrentSuite() {
30 if (getStackSize() != 0) {
31 return myStack
.peek();
37 * Pop element form stack and checks consistency
38 * @param suiteName Predictable name of top suite in stack
41 public SMTestProxy
popSuite(final String suiteName
) throws EmptyStackException
{
42 if (myStack
.isEmpty()) {
43 LOG
.assertTrue(false, "Pop error: Test runner tried to close test suite which has been already closed or wasn't started at all. Unexpected suite name [" + suiteName
+ "]");
46 final SMTestProxy currentSuite
= myStack
.pop();
48 if (!suiteName
.equals(currentSuite
.getName())) {
49 LOG
.assertTrue(false, "Pop error: Unexpected closing suite. Expected [" + suiteName
+ "] but [" + currentSuite
.getName() + "] was found. Rest of stack: " + getSuitePathPresentation());
56 public final boolean isEmpty() {
57 return getStackSize() == 0;
60 protected int getStackSize() {
61 return myStack
.size();
64 protected String
[] getSuitePath() {
65 final int stackSize
= getStackSize();
66 final String
[] names
= new String
[stackSize
];
67 for (int i
= 0; i
< stackSize
; i
++) {
68 names
[i
] = myStack
.get(i
).getName();
73 protected String
getSuitePathPresentation() {
74 final String
[] names
= getSuitePath();
75 if (names
.length
== 0) {
79 final StringBuilder builder
= new StringBuilder();
80 final String lastName
= names
[names
.length
- 1];
81 for (String name
: names
) {
82 builder
.append('[').append(name
).append(']');
83 //Here we can use != instead of !equals()
84 //noinspection StringEquality
85 if (name
!= lastName
) {
89 return builder
.toString();