@Test public void testPrintStackTrace() { TestTraceExtractor traceExtractor = new TestTraceExtractor(); TestBase testProxy = (TestBase) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{TestBase.class}, traceExtractor); testProxy.testBaseMethod(); String stackTraceString = StackTraceExtractor.printStackTrace(traceExtractor.traceElements); Assert.assertNotNull(stackTraceString); Assert.assertTrue(stackTraceString.startsWith("io.sniffy.util.StackTraceExtractorTest.TestBase.testBaseMethod(Unknown Source)")); Assert.assertTrue(stackTraceString.contains("io.sniffy.util.StackTraceExtractorTest.testPrintStackTrace(StackTraceExtractorTest.java")); }
public static String printStackTrace(List<StackTraceElement> stackTraceElements) { if (stackTraceElements == null) { return ""; } StringBuilder sb = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); for (StackTraceElement stackTraceElement : stackTraceElements) { sb.append(stackTraceElement.toString()).append(lineSeparator); } if (sb.length() > 0) { return sb.substring(0, sb.length() - 1); } else { return ""; } }
StackTraceExtractor { public static String printStackTrace(List<StackTraceElement> stackTraceElements) { if (stackTraceElements == null) { return ""; } StringBuilder sb = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); for (StackTraceElement stackTraceElement : stackTraceElements) { sb.append(stackTraceElement.toString()).append(lineSeparator); } if (sb.length() > 0) { return sb.substring(0, sb.length() - 1); } else { return ""; } } }
StackTraceExtractor { public static String printStackTrace(List<StackTraceElement> stackTraceElements) { if (stackTraceElements == null) { return ""; } StringBuilder sb = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); for (StackTraceElement stackTraceElement : stackTraceElements) { sb.append(stackTraceElement.toString()).append(lineSeparator); } if (sb.length() > 0) { return sb.substring(0, sb.length() - 1); } else { return ""; } } private  StackTraceExtractor(); }
StackTraceExtractor { public static String printStackTrace(List<StackTraceElement> stackTraceElements) { if (stackTraceElements == null) { return ""; } StringBuilder sb = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); for (StackTraceElement stackTraceElement : stackTraceElements) { sb.append(stackTraceElement.toString()).append(lineSeparator); } if (sb.length() > 0) { return sb.substring(0, sb.length() - 1); } else { return ""; } } private  StackTraceExtractor(); static List<StackTraceElement> getTraceForProxiedMethod(Method method); static List<StackTraceElement> getTraceForImplementingMethod(Method method, Method methodImpl); static List<StackTraceElement> getTraceTillPackage(String packageName); static String printStackTrace(List<StackTraceElement> stackTraceElements); }
StackTraceExtractor { public static String printStackTrace(List<StackTraceElement> stackTraceElements) { if (stackTraceElements == null) { return ""; } StringBuilder sb = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); for (StackTraceElement stackTraceElement : stackTraceElements) { sb.append(stackTraceElement.toString()).append(lineSeparator); } if (sb.length() > 0) { return sb.substring(0, sb.length() - 1); } else { return ""; } } private  StackTraceExtractor(); static List<StackTraceElement> getTraceForProxiedMethod(Method method); static List<StackTraceElement> getTraceForImplementingMethod(Method method, Method methodImpl); static List<StackTraceElement> getTraceTillPackage(String packageName); static String printStackTrace(List<StackTraceElement> stackTraceElements);  }