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.

DeclareMixinTests.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*******************************************************************************
  2. * Copyright (c) 2008 Contributors
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc164;
  12. import org.aspectj.testing.XMLBasedAjcTestCase;
  13. import junit.framework.Test;
  14. /**
  15. * <h4>Design and test coverage</h4><br>
  16. * In many ways the design is similar to DeclareParents now - so we have to plug in at the same points, but the code generation for
  17. * generating the delegate object and the choice of which interfaces (and methods within those) to mixin is different.
  18. *
  19. * <h4>Tested:</h4><br>
  20. * <ul>
  21. * <li>Factory method with void or primitive return value
  22. * <li>Check the factory method has at most one parameter
  23. * <li>incremental compilation
  24. * <li>error message if mixin target instance not compatible with factory method parameter
  25. * </ul>
  26. *
  27. * <h4>Still to test/explore:</h4><br>
  28. * <ul>
  29. * <li>model relationships
  30. * <li>ltw
  31. * <li>generic factory methods
  32. * <li>showWeaveInfo
  33. * <li>Clashing with existing methods
  34. * <li>varying parameter type on the factory method
  35. * </ul>
  36. *
  37. * @author Andy Clement
  38. */
  39. public class DeclareMixinTests extends org.aspectj.testing.XMLBasedAjcTestCase {
  40. // Very basics with a simple static factory method
  41. public void testCaseA() {
  42. runTest("casea");
  43. }
  44. // non static factory method, will need aspectOf() calling on
  45. // the aspect before the factory is called
  46. public void testCaseB() {
  47. runTest("caseb");
  48. }
  49. // factory method takes the object for which the delegate exists
  50. public void testCaseC() {
  51. runTest("casec");
  52. }
  53. // factory method is non static and takes the object for which the delegate is being created
  54. public void testCaseD() {
  55. runTest("cased");
  56. }
  57. // multiple instances causing factory invocation multiple times (but is cached)
  58. public void testCaseE() {
  59. runTest("casee");
  60. }
  61. // multiple instances causing factory invocation multiple times (but is cached), concurrent case
  62. // see https://github.com/eclipse-aspectj/aspectj/issues/198
  63. public void testCaseEConcurrent() {
  64. runTest("casee_concurrent");
  65. }
  66. // Factory method directly takes the type specified in the Mixin target (strongly typed)
  67. public void testCaseF() {
  68. runTest("casef");
  69. }
  70. // targeting multiple types from the Mixin
  71. public void testCaseG() {
  72. runTest("caseg");
  73. }
  74. // Null value for mixin target pattern
  75. public void testCaseH() {
  76. runTest("caseh");
  77. }
  78. // Invalid interfaces annotation value entries
  79. public void testCaseI() {
  80. runTest("casei");
  81. }
  82. // invalid return type for factory method
  83. public void testCaseJ() {
  84. runTest("casej");
  85. }
  86. // too many arguments to the factory method
  87. public void testCaseK() {
  88. runTest("casek");
  89. }
  90. // mixin of a class - should be an error (this one reported by the compiler due to a failed cast)
  91. public void testCaseL() {
  92. runTest("casel");
  93. }
  94. // mixin of a class - should be an error (this one reported by the annotation processing)
  95. public void testCaseM() {
  96. runTest("casem");
  97. }
  98. // factory returns class but interface specified - this is OK
  99. public void testCaseN() {
  100. runTest("casen");
  101. }
  102. // factory returns class but interface specified - not ok as class doesn't implement interface
  103. public void testCaseO() {
  104. runTest("caseo");
  105. }
  106. // interface subsetting used (factory returns class) - but only one method should be delegated
  107. public void testCaseP() {
  108. runTest("casep");
  109. }
  110. // factory return type implements two interfaces, both should be mixed as specified
  111. public void testCaseQ() {
  112. runTest("caseq");
  113. }
  114. // testing a pure marker interface - no methods added
  115. public void testCaseR() {
  116. runTest("caser");
  117. }
  118. // factory method has incompatible return type - verifyerror if we did use that factory
  119. public void testCaseS() {
  120. runTest("cases");
  121. }
  122. // weave info - what happens?
  123. public void testCaseT() {
  124. runTest("caset");
  125. }
  126. // --
  127. public static Test suite() {
  128. return XMLBasedAjcTestCase.loadSuite(DeclareMixinTests.class);
  129. }
  130. protected java.net.URL getSpecFile() {
  131. return getClassResource("declareMixin.xml");
  132. }
  133. }