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.

IntroducedAssertion.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import org.aspectj.testing.Tester;
  2. /** @testcase PUREJAVA PR#725 asserts in aspect and declared methods */
  3. public class IntroducedAssertion {
  4. public static void main (String[] args) {
  5. IntroducedAssertion.class.getClassLoader().setClassAssertionStatus("A", true);
  6. IntroducedAssertion.class.getClassLoader().setClassAssertionStatus("B", true);
  7. boolean result = false;
  8. try {
  9. C.method(null);
  10. } catch (AssertionError e) {
  11. result = true;
  12. }
  13. Tester.check(result, "no assert: C.method(null)");
  14. result = false;
  15. try {
  16. new C(); // field initializer
  17. } catch (AssertionError e) {
  18. result = true;
  19. }
  20. Tester.check(result, "no assert: new C()");
  21. result = false;
  22. try {
  23. new D().method(null);
  24. } catch (AssertionError e) {
  25. result = true;
  26. }
  27. Tester.check(result, "no assert: new D().method(null)");
  28. }
  29. }
  30. class C {}
  31. class D {}
  32. aspect B {
  33. int C.i = method(null);
  34. // assertion in any introduced code conflicts with any local
  35. static int C.method( Object o) {
  36. assert o != null ;
  37. return 0;
  38. }
  39. }
  40. aspect A {
  41. void D.method( Object o) {
  42. assert o != null ;
  43. }
  44. // assertion in any introduced method conflicts with any local
  45. void method() {
  46. assert null != System.getProperty("java.version");
  47. }
  48. // XXX build test cases for other local variants - these work
  49. /*
  50. static {
  51. assert null != System.getProperty("java.version");
  52. }
  53. static void aStaticMethod( Object parameter ) {
  54. assert parameter != null ;
  55. }
  56. */
  57. }