This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 216334
Collapse All | Expand All

(-)a/junit/src/org/netbeans/modules/junit/output/JUnitTestMethodNode.java (-1 / +2 lines)
Lines 38-43 Link Here
38
 * Contributor(s):
38
 * Contributor(s):
39
 *
39
 *
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 * markiewb@netbeans.org
41
 */
42
 */
42
43
43
package org.netbeans.modules.junit.output;
44
package org.netbeans.modules.junit.output;
Lines 131-137 Link Here
131
132
132
    @Override
133
    @Override
133
    public Action getPreferredAction() {
134
    public Action getPreferredAction() {
134
        return new JumpAction(this, null);
135
        return JumpAction.createForMethod(this, testcase.getTrouble() != null);
135
    }
136
    }
136
137
137
    public JUnitTestcase getTestcase(){
138
    public JUnitTestcase getTestcase(){
(-)a/junit/src/org/netbeans/modules/junit/output/JumpAction.java (-2 / +24 lines)
Lines 29-34 Link Here
29
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
31
 * Microsystems, Inc. All Rights Reserved.
32
 * 
33
 * markiewb@netbeans.org
32
 *
34
 *
33
 * If you wish your version of this file to be governed by only the CDDL
35
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
36
 * or only the GPL Version 2, indicate your decision by adding
Lines 58-73 Link Here
58
 */
60
 */
59
final class JumpAction extends AbstractAction {
61
final class JumpAction extends AbstractAction {
60
62
63
    public static JumpAction createForMethod (JUnitTestMethodNode node, boolean isFailingMethod) {
64
        return new JumpAction(node, isFailingMethod);
65
    }
66
61
    /** */
67
    /** */
62
    private final Node node;
68
    private final Node node;
63
    /** */
69
    /** */
64
    private final String callstackFrameInfo;
70
    private final String callstackFrameInfo;
71
    private boolean isFailingMethod = false;
65
72
66
    /** Creates a new instance of JumpAction */
73
    /** Creates a new instance of JumpAction */
67
    public JumpAction(Node node, String callstackFrameInfo) {
74
    public JumpAction(Node node, String callstackFrameInfo) {
68
        this.node = node;
75
        this.node = node;
69
        this.callstackFrameInfo = callstackFrameInfo;
76
        this.callstackFrameInfo = callstackFrameInfo;
70
    }
77
    }
78
    /**
79
     * 
80
     * @param node
81
     * @param isFailingMethod 
82
     */
83
    private JumpAction(JUnitTestMethodNode node, boolean isFailingMethod) {
84
        this(node, null);
85
        this.isFailingMethod = isFailingMethod;
86
    }
71
87
72
    /**
88
    /**
73
     * If the <code>callstackFrameInfo</code> is not <code>null</code>,
89
     * If the <code>callstackFrameInfo</code> is not <code>null</code>,
Lines 78-85 Link Here
78
            OutputUtils.openTestsuite((TestsuiteNode)node);
94
            OutputUtils.openTestsuite((TestsuiteNode)node);
79
        } else if (node instanceof CallstackFrameNode){
95
        } else if (node instanceof CallstackFrameNode){
80
            OutputUtils.openCallstackFrame(node, callstackFrameInfo);
96
            OutputUtils.openCallstackFrame(node, callstackFrameInfo);
81
        } else if (node instanceof JUnitTestMethodNode){
97
        } else if (node instanceof JUnitTestMethodNode) {
82
            OutputUtils.openTestMethod((JUnitTestMethodNode)node);
98
            if (isFailingMethod) {
99
                // if method failed, then find the failing line 
100
                // within the testMethod using the stacktrace
101
                OutputUtils.openCallstackFrame(node, "");
102
            } else {
103
                OutputUtils.openTestMethod((JUnitTestMethodNode) node);
104
            }
83
        }
105
        }
84
    }
106
    }
85
107
(-)a/junit/src/org/netbeans/modules/junit/output/OutputUtils.java (-13 / +26 lines)
Lines 154-173 Link Here
154
        }
154
        }
155
    }
155
    }
156
156
157
    static void openCallstackFrame(Node node, String frameInfo) {
157
    static void openCallstackFrame (Node node, String frameInfo) {
158
            JUnitTestMethodNode methodNode = getTestMethodNode(node);
158
        //code taken from org.netbeans.modules.maven.junit.nodes.OutputUtils
159
            FileLocator locator =  methodNode.getTestcase().getSession().getFileLocator();
159
        //see http://netbeans.org/bugzilla/show_bug.cgi?id=213935
160
            if (locator == null){
160
        JUnitTestMethodNode methodNode = getTestMethodNode(node);
161
                return;
161
        FileLocator locator = methodNode.getTestcase().getSession().getFileLocator();
162
        if (locator == null) {
163
            return;
164
        }
165
        FileObject testfo = methodNode.getTestcase().getClassFileObject();
166
        final int[] lineNumStorage = new int[1];
167
        FileObject file = getFile(frameInfo, lineNumStorage, locator);
168
        //lineNumStorage -1 means no regexp for stacktrace was matched.
169
        if ((file == null) && (methodNode.getTestcase().getTrouble() != null) && lineNumStorage[0] == -1) {
170
            //213935 we could not recognize the stack trace line and map it to known file
171
            //if it's a failure text, grab the testcase's own line from the stack.
172
            String[] st = methodNode.getTestcase().getTrouble().getStackTrace();
173
            if ((st != null) && (st.length > 0)) {
174
                int index = st.length - 1;
175
                //213935 we need to find the testcase linenumber to jump to.
176
                // and ignore the infrastructure stack lines in the process
177
                while (!testfo.equals(file) && index != -1) {
178
                    file = getFile(st[index], lineNumStorage, locator);
179
                    index = index - 1;
180
                }
162
            }
181
            }
163
            final int[] lineNumStorage = new int[1];
182
        }
164
            FileObject file = getFile(frameInfo, lineNumStorage, locator);
183
        Utils.openFile(file, lineNumStorage[0]);
165
            if ((file == null) && (methodNode.getTestcase().getTrouble() != null)){
166
                String[] st = methodNode.getTestcase().getTrouble().getStackTrace();
167
                if ((st != null) && (st.length > 0))
168
                file = getFile(st[st.length - 1], lineNumStorage, locator);
169
            }
170
            Utils.openFile(file, lineNumStorage[0]);
171
    }
184
    }
172
185
173
    /**
186
    /**
(-)a/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JUnitTestMethodNode.java (-1 / +1 lines)
Lines 138-144 Link Here
138
138
139
    @Override
139
    @Override
140
    public Action getPreferredAction() {
140
    public Action getPreferredAction() {
141
        return new JumpAction(this, null);
141
        return JumpAction.createForMethod(this, testcase.getTrouble() != null);
142
    }
142
    }
143
143
144
    public Testcase getTestcase() {
144
    public Testcase getTestcase() {
(-)a/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JumpAction.java (-2 / +24 lines)
Lines 58-67 Link Here
58
 */
58
 */
59
final class JumpAction extends AbstractAction {
59
final class JumpAction extends AbstractAction {
60
60
61
    public static JumpAction createForMethod (JUnitTestMethodNode node, boolean isFailingMethod) {
62
        return new JumpAction(node, isFailingMethod);
63
    }
64
61
    /** */
65
    /** */
62
    private final Node node;
66
    private final Node node;
63
    /** */
67
    /** */
64
    private final String callstackFrameInfo;
68
    private final String callstackFrameInfo;
69
    private boolean isFailingMethod = false;
65
70
66
    /** Creates a new instance of JumpAction */
71
    /** Creates a new instance of JumpAction */
67
    public JumpAction(Node node, String callstackFrameInfo) {
72
    public JumpAction(Node node, String callstackFrameInfo) {
Lines 70-75 Link Here
70
    }
75
    }
71
76
72
    /**
77
    /**
78
     * 
79
     * @param node
80
     * @param isFailingMethod 
81
     */
82
    private JumpAction(JUnitTestMethodNode node, boolean isFailingMethod) {
83
        this(node, null);
84
        this.isFailingMethod = isFailingMethod;
85
    }
86
87
88
    /**
73
     * If the <code>callstackFrameInfo</code> is not <code>null</code>,
89
     * If the <code>callstackFrameInfo</code> is not <code>null</code>,
74
     * tries to jump to the callstack frame source code. Otherwise does nothing.
90
     * tries to jump to the callstack frame source code. Otherwise does nothing.
75
     */
91
     */
Lines 79-86 Link Here
79
            OutputUtils.openTestsuite((TestsuiteNode)node);
95
            OutputUtils.openTestsuite((TestsuiteNode)node);
80
        } else if (node instanceof JUnitCallstackFrameNode){
96
        } else if (node instanceof JUnitCallstackFrameNode){
81
            OutputUtils.openCallstackFrame(node, callstackFrameInfo);
97
            OutputUtils.openCallstackFrame(node, callstackFrameInfo);
82
        } else if (node instanceof JUnitTestMethodNode){
98
        } else if (node instanceof JUnitTestMethodNode) {
83
            OutputUtils.openTestMethod((JUnitTestMethodNode)node);
99
            if (isFailingMethod) {
100
                // if method failed, then find the failing line 
101
                // within the testMethod using the stacktrace
102
                OutputUtils.openCallstackFrame(node, "");
103
            } else {
104
                OutputUtils.openTestMethod((JUnitTestMethodNode) node);
105
            }
84
        }
106
        }
85
    }
107
    }
86
108

Return to bug 216334