sm runner: code cleanup
[idea/community.git] / platform / smRunner / src / com / intellij / execution / testframework / sm / runner / events / TestFailedEvent.java
1 /*
2  * Copyright 2000-2012 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.execution.testframework.sm.runner.events;
17
18 import jetbrains.buildServer.messages.serviceMessages.TestFailed;
19 import org.jetbrains.annotations.NotNull;
20 import org.jetbrains.annotations.Nullable;
21
22 public class TestFailedEvent extends TreeNodeEvent {
23
24   private final String myLocalizedFailureMessage;
25   private final String myStacktrace;
26   private final boolean myTestError;
27   private final String myComparisonFailureActualText;
28   private final String myComparisonFailureExpectedText;
29   private final String myFilePath;
30
31   public TestFailedEvent(@NotNull TestFailed testFailed, boolean testError) {
32     this(testFailed, testError, null);
33   }
34   public TestFailedEvent(@NotNull TestFailed testFailed, boolean testError, String filePath) {
35     super(testFailed.getTestName(), TreeNodeEvent.getNodeId(testFailed));
36     if (testFailed.getFailureMessage() == null) throw new NullPointerException();
37     myLocalizedFailureMessage = testFailed.getFailureMessage();
38     myStacktrace = testFailed.getStacktrace();
39     myTestError = testError;
40     myComparisonFailureActualText = testFailed.getActual();
41     myComparisonFailureExpectedText = testFailed.getExpected();
42     myFilePath = filePath;
43   }
44
45   public TestFailedEvent(@NotNull String testName,
46                          @NotNull String localizedFailureMessage,
47                          @Nullable String stackTrace,
48                          boolean testError,
49                          @Nullable String comparisonFailureActualText,
50                          @Nullable String comparisonFailureExpectedText) {
51     super(testName, -1);
52     myLocalizedFailureMessage = localizedFailureMessage;
53     myStacktrace = stackTrace;
54     myTestError = testError;
55     myComparisonFailureActualText = comparisonFailureActualText;
56     myComparisonFailureExpectedText = comparisonFailureExpectedText;
57     myFilePath = null;
58   }
59
60   @NotNull
61   public String getLocalizedFailureMessage() {
62     return myLocalizedFailureMessage;
63   }
64
65   @Nullable
66   public String getStacktrace() {
67     return myStacktrace;
68   }
69
70   public boolean isTestError() {
71     return myTestError;
72   }
73
74   @Nullable
75   public String getComparisonFailureActualText() {
76     return myComparisonFailureActualText;
77   }
78
79   @Nullable
80   public String getComparisonFailureExpectedText() {
81     return myComparisonFailureExpectedText;
82   }
83
84   @Override
85   protected void appendToStringInfo(@NotNull StringBuilder buf) {
86     append(buf, "localizedFailureMessage", myLocalizedFailureMessage);
87     append(buf, "stacktrace", myStacktrace);
88     append(buf, "isTestError", myTestError);
89     append(buf, "comparisonFailureActualText", myComparisonFailureActualText);
90     append(buf, "comparisonFailureExpectedText", myComparisonFailureExpectedText);
91   }
92
93   public String getFilePath() {
94     return myFilePath;
95   }
96 }