b8f94615c948b474d676b8c597167e7a449118ed
[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 /**
23  * @author Sergey Simonchik
24  */
25 public class TestFailedEvent extends TreeNodeEvent {
26
27   private final String myLocalizedFailureMessage;
28   private final String myStacktrace;
29   private final boolean myTestError;
30   private final String myComparisonFailureActualText;
31   private final String myComparisonFailureExpectedText;
32   private final String myFilePath;
33
34   public TestFailedEvent(@NotNull TestFailed testFailed, boolean testError) {
35     this(testFailed, testError, null);
36   }
37   public TestFailedEvent(@NotNull TestFailed testFailed, boolean testError, String filePath) {
38     super(testFailed.getTestName(), TreeNodeEvent.getNodeId(testFailed));
39     if (testFailed.getFailureMessage() == null) throw new NullPointerException();
40     myLocalizedFailureMessage = testFailed.getFailureMessage();
41     myStacktrace = testFailed.getStacktrace();
42     myTestError = testError;
43     myComparisonFailureActualText = testFailed.getActual();
44     myComparisonFailureExpectedText = testFailed.getExpected();
45     myFilePath = filePath;
46   }
47
48   public TestFailedEvent(@NotNull String testName,
49                          @NotNull String localizedFailureMessage,
50                          @Nullable String stackTrace,
51                          boolean testError,
52                          @Nullable String comparisonFailureActualText,
53                          @Nullable String comparisonFailureExpectedText) {
54     super(testName, -1);
55     myLocalizedFailureMessage = localizedFailureMessage;
56     myStacktrace = stackTrace;
57     myTestError = testError;
58     myComparisonFailureActualText = comparisonFailureActualText;
59     myComparisonFailureExpectedText = comparisonFailureExpectedText;
60     myFilePath = null;
61   }
62
63   @NotNull
64   public String getLocalizedFailureMessage() {
65     return myLocalizedFailureMessage;
66   }
67
68   @Nullable
69   public String getStacktrace() {
70     return myStacktrace;
71   }
72
73   public boolean isTestError() {
74     return myTestError;
75   }
76
77   @Nullable
78   public String getComparisonFailureActualText() {
79     return myComparisonFailureActualText;
80   }
81
82   @Nullable
83   public String getComparisonFailureExpectedText() {
84     return myComparisonFailureExpectedText;
85   }
86
87   @Override
88   protected void appendToStringInfo(@NotNull StringBuilder buf) {
89     append(buf, "localizedFailureMessage", myLocalizedFailureMessage);
90     append(buf, "stacktrace", myStacktrace);
91     append(buf, "isTestError", myTestError);
92     append(buf, "comparisonFailureActualText", myComparisonFailureActualText);
93     append(buf, "comparisonFailureExpectedText", myComparisonFailureExpectedText);
94   }
95
96   public String getFilePath() {
97     return myFilePath;
98   }
99 }