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.

RuntimeModuleTests.java 2.9KB

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