diff --git a/junit/src/org/netbeans/modules/junit/output/JUnitTestMethodNode.java b/junit/src/org/netbeans/modules/junit/output/JUnitTestMethodNode.java --- a/junit/src/org/netbeans/modules/junit/output/JUnitTestMethodNode.java +++ b/junit/src/org/netbeans/modules/junit/output/JUnitTestMethodNode.java @@ -38,6 +38,7 @@ * Contributor(s): * * Portions Copyrighted 2009 Sun Microsystems, Inc. + * markiewb@netbeans.org */ package org.netbeans.modules.junit.output; @@ -131,7 +132,7 @@ @Override public Action getPreferredAction() { - return new JumpAction(this, null); + return JumpAction.createForMethod(this, testcase.getTrouble() != null); } public JUnitTestcase getTestcase(){ diff --git a/junit/src/org/netbeans/modules/junit/output/JumpAction.java b/junit/src/org/netbeans/modules/junit/output/JumpAction.java --- a/junit/src/org/netbeans/modules/junit/output/JumpAction.java +++ b/junit/src/org/netbeans/modules/junit/output/JumpAction.java @@ -29,6 +29,8 @@ * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. + * + * markiewb@netbeans.org * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding @@ -58,16 +60,30 @@ */ final class JumpAction extends AbstractAction { + public static JumpAction createForMethod (JUnitTestMethodNode node, boolean isFailingMethod) { + return new JumpAction(node, isFailingMethod); + } + /** */ private final Node node; /** */ private final String callstackFrameInfo; + private boolean isFailingMethod = false; /** Creates a new instance of JumpAction */ public JumpAction(Node node, String callstackFrameInfo) { this.node = node; this.callstackFrameInfo = callstackFrameInfo; } + /** + * + * @param node + * @param isFailingMethod + */ + private JumpAction(JUnitTestMethodNode node, boolean isFailingMethod) { + this(node, null); + this.isFailingMethod = isFailingMethod; + } /** * If the callstackFrameInfo is not null, @@ -78,8 +94,14 @@ OutputUtils.openTestsuite((TestsuiteNode)node); } else if (node instanceof CallstackFrameNode){ OutputUtils.openCallstackFrame(node, callstackFrameInfo); - } else if (node instanceof JUnitTestMethodNode){ - OutputUtils.openTestMethod((JUnitTestMethodNode)node); + } else if (node instanceof JUnitTestMethodNode) { + if (isFailingMethod) { + // if method failed, then find the failing line + // within the testMethod using the stacktrace + OutputUtils.openCallstackFrame(node, ""); + } else { + OutputUtils.openTestMethod((JUnitTestMethodNode) node); + } } } diff --git a/junit/src/org/netbeans/modules/junit/output/OutputUtils.java b/junit/src/org/netbeans/modules/junit/output/OutputUtils.java --- a/junit/src/org/netbeans/modules/junit/output/OutputUtils.java +++ b/junit/src/org/netbeans/modules/junit/output/OutputUtils.java @@ -154,20 +154,33 @@ } } - static void openCallstackFrame(Node node, String frameInfo) { - JUnitTestMethodNode methodNode = getTestMethodNode(node); - FileLocator locator = methodNode.getTestcase().getSession().getFileLocator(); - if (locator == null){ - return; + static void openCallstackFrame (Node node, String frameInfo) { + //code taken from org.netbeans.modules.maven.junit.nodes.OutputUtils + //see http://netbeans.org/bugzilla/show_bug.cgi?id=213935 + JUnitTestMethodNode methodNode = getTestMethodNode(node); + FileLocator locator = methodNode.getTestcase().getSession().getFileLocator(); + if (locator == null) { + return; + } + FileObject testfo = methodNode.getTestcase().getClassFileObject(); + final int[] lineNumStorage = new int[1]; + FileObject file = getFile(frameInfo, lineNumStorage, locator); + //lineNumStorage -1 means no regexp for stacktrace was matched. + if ((file == null) && (methodNode.getTestcase().getTrouble() != null) && lineNumStorage[0] == -1) { + //213935 we could not recognize the stack trace line and map it to known file + //if it's a failure text, grab the testcase's own line from the stack. + String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); + if ((st != null) && (st.length > 0)) { + int index = st.length - 1; + //213935 we need to find the testcase linenumber to jump to. + // and ignore the infrastructure stack lines in the process + while (!testfo.equals(file) && index != -1) { + file = getFile(st[index], lineNumStorage, locator); + index = index - 1; + } } - final int[] lineNumStorage = new int[1]; - FileObject file = getFile(frameInfo, lineNumStorage, locator); - if ((file == null) && (methodNode.getTestcase().getTrouble() != null)){ - String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); - if ((st != null) && (st.length > 0)) - file = getFile(st[st.length - 1], lineNumStorage, locator); - } - Utils.openFile(file, lineNumStorage[0]); + } + Utils.openFile(file, lineNumStorage[0]); } /** diff --git a/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JUnitTestMethodNode.java b/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JUnitTestMethodNode.java --- a/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JUnitTestMethodNode.java +++ b/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JUnitTestMethodNode.java @@ -138,7 +138,7 @@ @Override public Action getPreferredAction() { - return new JumpAction(this, null); + return JumpAction.createForMethod(this, testcase.getTrouble() != null); } public Testcase getTestcase() { diff --git a/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JumpAction.java b/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JumpAction.java --- a/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JumpAction.java +++ b/maven.junit/src/org/netbeans/modules/maven/junit/nodes/JumpAction.java @@ -58,10 +58,15 @@ */ final class JumpAction extends AbstractAction { + public static JumpAction createForMethod (JUnitTestMethodNode node, boolean isFailingMethod) { + return new JumpAction(node, isFailingMethod); + } + /** */ private final Node node; /** */ private final String callstackFrameInfo; + private boolean isFailingMethod = false; /** Creates a new instance of JumpAction */ public JumpAction(Node node, String callstackFrameInfo) { @@ -70,6 +75,17 @@ } /** + * + * @param node + * @param isFailingMethod + */ + private JumpAction(JUnitTestMethodNode node, boolean isFailingMethod) { + this(node, null); + this.isFailingMethod = isFailingMethod; + } + + + /** * If the callstackFrameInfo is not null, * tries to jump to the callstack frame source code. Otherwise does nothing. */ @@ -79,8 +95,14 @@ OutputUtils.openTestsuite((TestsuiteNode)node); } else if (node instanceof JUnitCallstackFrameNode){ OutputUtils.openCallstackFrame(node, callstackFrameInfo); - } else if (node instanceof JUnitTestMethodNode){ - OutputUtils.openTestMethod((JUnitTestMethodNode)node); + } else if (node instanceof JUnitTestMethodNode) { + if (isFailingMethod) { + // if method failed, then find the failing line + // within the testMethod using the stacktrace + OutputUtils.openCallstackFrame(node, ""); + } else { + OutputUtils.openTestMethod((JUnitTestMethodNode) node); + } } }