2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.rt
.execution
.junit
;
18 import com
.intellij
.rt
.execution
.junit
.segments
.OutputObjectRegistryEx
;
19 import com
.intellij
.rt
.execution
.junit
.segments
.Packet
;
20 import com
.intellij
.rt
.execution
.junit
.states
.PoolOfTestStates
;
21 import junit
.framework
.ComparisonFailure
;
23 import java
.lang
.reflect
.Field
;
26 * @noinspection HardCodedStringLiteral
28 public class ComparisonDetailsExtractor
extends ExceptionPacketFactory
{
29 private static Field EXPECTED_FIELD
= null;
30 private static Field ACTUAL_FIELD
= null;
31 protected String myActual
= "";
32 protected String myExpected
= "";
36 Class exceptionClass
= ComparisonFailure
.class;
37 exceptionClass
.getDeclaredField("fExpected");
38 EXPECTED_FIELD
= exceptionClass
.getDeclaredField("fExpected");
39 EXPECTED_FIELD
.setAccessible(true);
40 ACTUAL_FIELD
= exceptionClass
.getDeclaredField("fActual");
41 ACTUAL_FIELD
.setAccessible(true);
42 } catch (Throwable e
) {}
45 public ComparisonDetailsExtractor(Throwable assertion
, String expected
, String actual
) {
46 super(PoolOfTestStates
.COMPARISON_FAILURE
, assertion
);
48 myExpected
= expected
;
51 public static ExceptionPacketFactory
create(Throwable assertion
) {
54 if (assertion
instanceof ComparisonFailure
) {
55 expected
= (String
)EXPECTED_FIELD
.get(assertion
);
58 Field field
= assertion
.getClass().getDeclaredField("fExpected");
59 field
.setAccessible(true);
60 expected
= (String
)field
.get(assertion
);
63 if (assertion
instanceof ComparisonFailure
) {
64 actual
= (String
)ACTUAL_FIELD
.get(assertion
);
67 Field field
= assertion
.getClass().getDeclaredField("fActual");
68 field
.setAccessible(true);
69 actual
= (String
)field
.get(assertion
);
71 return new ComparisonDetailsExtractor(assertion
, expected
, actual
);
74 return new ExceptionPacketFactory(PoolOfTestStates
.FAILED_INDEX
, assertion
);
78 public Packet
createPacket(OutputObjectRegistryEx registry
, Object test
) {
79 Packet packet
= super.createPacket(registry
, test
);
81 addLimitedString(myExpected
).
82 addLimitedString(myActual
);