Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AssertInAdvice.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import org.aspectj.testing.Tester;
  2. /** @testcase PR#657 PUREJAVA assert statement in advice coverage [requires 1.4] */
  3. public class AssertInAdvice {
  4. public static void main(String[] args) {
  5. AssertInAdvice.class.getClassLoader().setClassAssertionStatus("Test", true);
  6. AssertInAdvice.class.getClassLoader().setClassAssertionStatus("AssertInAdvice", false);
  7. boolean expectAssert = false;
  8. boolean gotit = false;
  9. do {
  10. Test.throwAssert = expectAssert;
  11. gotit = false;
  12. // 6 cases - separate join point for advice below
  13. // call
  14. try { call1(); } catch (AssertionError e) { gotit = true; }
  15. Tester.check(gotit == expectAssert, "call1"+expectAssert); gotit = false;
  16. try { call2(); } catch (AssertionError e) { gotit = true; }
  17. Tester.check(gotit == expectAssert, "call2"+expectAssert); gotit = false;
  18. try { call3(); } catch (AssertionError e) { gotit = true; }
  19. Tester.check(gotit == expectAssert, "call3"+expectAssert); gotit = false;
  20. try { call4(); } catch (AssertionError e) { gotit = true; }
  21. Tester.check(gotit == expectAssert, "call4"+expectAssert); gotit = false;
  22. try { call5(); } catch (AssertionError e) { gotit = true; }
  23. Tester.check(gotit == expectAssert, "call5"+expectAssert); gotit = false;
  24. try { call6(); } catch (AssertionError e) { gotit = true; }
  25. Tester.check(gotit == expectAssert, "call6"+expectAssert); gotit = false;
  26. // execution
  27. try { execution1(); } catch (AssertionError e) { gotit = true; }
  28. Tester.check(gotit == expectAssert, "execution1"+expectAssert); gotit = false;
  29. try { execution2(); } catch (AssertionError e) { gotit = true; }
  30. Tester.check(gotit == expectAssert, "execution2"+expectAssert); gotit = false;
  31. try { execution3(); } catch (AssertionError e) { gotit = true; }
  32. Tester.check(gotit == expectAssert, "execution3"+expectAssert); gotit = false;
  33. try { execution4(); } catch (AssertionError e) { gotit = true; }
  34. Tester.check(gotit == expectAssert, "execution4"+expectAssert); gotit = false;
  35. try { execution5(); } catch (AssertionError e) { gotit = true; }
  36. Tester.check(gotit == expectAssert, "execution5"+expectAssert); gotit = false;
  37. try { execution6(); } catch (AssertionError e) { gotit = true; }
  38. Tester.check(gotit == expectAssert, "execution6"+expectAssert);
  39. // run for false, true
  40. if (expectAssert) break;
  41. expectAssert = true;
  42. } while (true);
  43. }
  44. public static void call1() {}
  45. public static void call2() {}
  46. public static void call3() {}
  47. public static void call4() {}
  48. public static void call5() {}
  49. public static void call6() {}
  50. public static void execution1() {}
  51. public static void execution2() {}
  52. public static void execution3() {}
  53. public static void execution4() {}
  54. public static void execution5() {}
  55. public static void execution6() {}
  56. }
  57. aspect Test {
  58. // todo: convert to 1.3 test?
  59. public static boolean throwAssert;
  60. public static boolean throwAssert() { return throwAssert; }
  61. public static final AssertionError EXPECTED = new AssertionError("expected");
  62. public static void testAssert() {
  63. //if (throwAssert) throw EXPECTED;
  64. assert !throwAssert() ;
  65. }
  66. // call
  67. after() returning : call(void AssertInAdvice.call1() ) {
  68. assert !throwAssert();
  69. }
  70. after() : call(void AssertInAdvice.call2() ) {
  71. assert !throwAssert();
  72. }
  73. before() : call(void AssertInAdvice.call3() ) { testAssert(); }
  74. void around() : call(void AssertInAdvice.call4() ) { testAssert(); }
  75. void around() : call(void AssertInAdvice.call5() ) { proceed(); testAssert(); }
  76. void around() : call(void AssertInAdvice.call6() ) { testAssert(); proceed(); }
  77. // execution
  78. after() returning : execution(void AssertInAdvice.execution1() ) { testAssert(); }
  79. after() : execution(void AssertInAdvice.execution2() ) { testAssert(); }
  80. before() : execution(void AssertInAdvice.execution3() ) { testAssert(); }
  81. void around() : execution(void AssertInAdvice.execution4() ) { testAssert(); }
  82. void around() : execution(void AssertInAdvice.execution5() ) { proceed(); testAssert(); }
  83. void around() : execution(void AssertInAdvice.execution6() ) { testAssert(); proceed(); }
  84. }