You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuntimeTest.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package org.aspectj.runtime;
  2. /* *******************************************************************
  3. * Copyright (c) 1999-2001 Xerox Corporation,
  4. * 2002 Palo Alto Research Center, Incorporated (PARC).
  5. * All rights reserved.
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Public License v1.0
  8. * which accompanies this distribution and is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. *
  11. * Contributors:
  12. * Xerox/PARC initial implementation
  13. * ******************************************************************/
  14. import java.io.*;
  15. import org.aspectj.lang.*;
  16. import org.aspectj.runtime.reflect.JoinPointImplTest;
  17. import org.aspectj.runtime.reflect.RuntimePerformanceTest;
  18. import org.aspectj.runtime.reflect.SignatureTest;
  19. import junit.framework.*;
  20. public class RuntimeTest extends TestCase {
  21. public RuntimeTest(String name) { super(name); }
  22. public void testNoAspectBoundException() {
  23. RuntimeException fun = new RuntimeException("fun");
  24. NoAspectBoundException nab = new NoAspectBoundException("Foo", fun);
  25. assertEquals(fun,nab.getCause());
  26. }
  27. public void testSoftExceptionPrintStackTrace() {
  28. // let's see
  29. // Throwable t = new Error("xyz");
  30. // new SoftException(t).printStackTrace();
  31. // save to specified PrintStream
  32. ByteArrayOutputStream sink = new ByteArrayOutputStream();
  33. PrintStream out = new PrintStream(sink);
  34. new SoftException(new Error("xyz")).printStackTrace(out);
  35. String s = new String(sink.toByteArray());
  36. out.flush();
  37. checkSoftExceptionString(s);
  38. // save to specified PrintWriter
  39. sink = new ByteArrayOutputStream();
  40. PrintWriter pout = new PrintWriter(sink);
  41. new SoftException(new Error("xyz")).printStackTrace(pout);
  42. pout.flush();
  43. s = new String(sink.toByteArray());
  44. checkSoftExceptionString(s);
  45. // check System.err redirect
  46. PrintStream systemErr = System.err;
  47. try {
  48. sink = new ByteArrayOutputStream();
  49. out = new PrintStream(sink);
  50. System.setErr(out);
  51. new SoftException(new Error("xyz")).printStackTrace();
  52. out.flush();
  53. s = new String(sink.toByteArray());
  54. checkSoftExceptionString(s);
  55. } finally {
  56. System.setErr(systemErr);
  57. }
  58. }
  59. static void checkSoftExceptionString(String s) {
  60. assertTrue(-1 != s.indexOf("SoftException"));
  61. assertTrue(-1 != s.indexOf("Caused by: java.lang.Error"));
  62. assertTrue(-1 != s.indexOf("xyz"));
  63. assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace"));
  64. }
  65. }