Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RuntimeModuleTests.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 RuntimeModuleTests extends TestCase {
  21. public static TestSuite suite() {
  22. TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName());
  23. suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing)
  24. suite.addTestSuite(SignatureTest.class);
  25. suite.addTestSuite(JoinPointImplTest.class);
  26. suite.addTestSuite(RuntimePerformanceTest.class);
  27. return suite;
  28. }
  29. public RuntimeModuleTests(String name) { super(name); }
  30. public void testNoAspectBoundException() {
  31. RuntimeException fun = new RuntimeException("fun");
  32. NoAspectBoundException nab = new NoAspectBoundException("Foo", fun);
  33. assertEquals(fun,nab.getCause());
  34. }
  35. public void testSoftExceptionPrintStackTrace() {
  36. // let's see
  37. // Throwable t = new Error("xyz");
  38. // new SoftException(t).printStackTrace();
  39. // save to specified PrintStream
  40. ByteArrayOutputStream sink = new ByteArrayOutputStream();
  41. PrintStream out = new PrintStream(sink);
  42. new SoftException(new Error("xyz")).printStackTrace(out);
  43. String s = new String(sink.toByteArray());
  44. out.flush();
  45. checkSoftExceptionString(s);
  46. // save to specified PrintWriter
  47. sink = new ByteArrayOutputStream();
  48. PrintWriter pout = new PrintWriter(sink);
  49. new SoftException(new Error("xyz")).printStackTrace(pout);
  50. pout.flush();
  51. s = new String(sink.toByteArray());
  52. checkSoftExceptionString(s);
  53. // check System.err redirect
  54. PrintStream systemErr = System.err;
  55. try {
  56. sink = new ByteArrayOutputStream();
  57. out = new PrintStream(sink);
  58. System.setErr(out);
  59. new SoftException(new Error("xyz")).printStackTrace();
  60. out.flush();
  61. s = new String(sink.toByteArray());
  62. checkSoftExceptionString(s);
  63. } finally {
  64. System.setErr(systemErr);
  65. }
  66. }
  67. static void checkSoftExceptionString(String s) {
  68. assertTrue(-1 != s.indexOf("SoftException"));
  69. assertTrue(-1 != s.indexOf("Caused by: java.lang.Error"));
  70. assertTrue(-1 != s.indexOf("xyz"));
  71. assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace"));
  72. }
  73. }