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.

PR520.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import org.aspectj.testing.Tester;
  2. /** @testcase for PR520 - NAB? */
  3. public class PR520 {
  4. public static void main(String[] args) {
  5. PR520 me = new PR520();
  6. me.testValidThreeArgumentCall() ;
  7. me.testValidThreeArgumentCallTwo();
  8. Tester.checkAllEvents();
  9. }
  10. public void testValidThreeArgumentCall() {
  11. for (int i = 0; i < Logger.PRIORITIES.length; i++) {
  12. Logger.log(Logger.PRIORITIES[i],
  13. Logger.API, "context=word_" + i);
  14. }
  15. }
  16. public void testValidThreeArgumentCallTwo() {
  17. Logger.log( Logger.EXCEPTION, Logger.API, "context=EXCEPTION" );
  18. Logger.log( Logger.DEBUG, Logger.API, "context=DEBUG" );
  19. Logger.log( Logger.DEBUG, Logger.API, "context=DEBUG-Exception",
  20. new Exception( "bad bad boy" ) );
  21. }
  22. public static void signal(String s, String context) {
  23. signal(context + ": " + s);
  24. }
  25. public static void signal(String s) {
  26. System.err.println(s);
  27. Tester.event(s);
  28. }
  29. private static final String[] EXPECTED;
  30. static {
  31. EXPECTED = new String[]
  32. { "context=word_0"
  33. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  34. , "context=word_1"
  35. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  36. , "context=word_2"
  37. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  38. , "context=word_3"
  39. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  40. , "context=word_4"
  41. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  42. , "context=EXCEPTION"
  43. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  44. , "context=DEBUG"
  45. , "call(void Logger.log(Logger.ChromePriority, Unknown, String))"
  46. , "context=DEBUG-Exception"
  47. , "call(void Logger.log(Logger.ChromePriority, Unknown, String, Exception))"
  48. };
  49. Tester.expectEventsInString(EXPECTED);
  50. }
  51. }
  52. class Unknown { }
  53. class Logger {
  54. static class ChromePriority { }
  55. public static final ChromePriority DEBUG;
  56. public static final ChromePriority EXCEPTION;
  57. public static final ChromePriority FATAL;
  58. public static final ChromePriority INFO;
  59. public static final ChromePriority WARN;
  60. public static final Unknown API;
  61. public static final Logger.ChromePriority[] PRIORITIES;
  62. static {
  63. API = new Unknown();
  64. PRIORITIES = new Logger.ChromePriority[ 5 ];
  65. DEBUG = new ChromePriority();
  66. EXCEPTION = new ChromePriority();
  67. FATAL = new ChromePriority();
  68. INFO = new ChromePriority();
  69. WARN = new ChromePriority();
  70. PRIORITIES[ 0 ] = Logger.DEBUG;
  71. PRIORITIES[ 1 ] = Logger.EXCEPTION;
  72. PRIORITIES[ 2 ] = Logger.FATAL;
  73. PRIORITIES[ 3 ] = Logger.INFO;
  74. PRIORITIES[ 4 ] = Logger.WARN;
  75. }
  76. public static void log(ChromePriority p, Unknown q,
  77. String message, Exception e) {
  78. PR520.signal(message);
  79. }
  80. public static void log(ChromePriority p, Unknown q,
  81. String message) {
  82. PR520.signal(message);
  83. }
  84. }
  85. aspect LoggerCategoryCreator {
  86. pointcut allLoggingCalls()
  87. : call(public void Logger.log(..));
  88. void around(): allLoggingCalls() {
  89. // s.b. no proceed() (i.e., replace) but testing invocation
  90. proceed();
  91. PR520.signal(thisJoinPointStaticPart.toString());
  92. }
  93. }