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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  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. // Factory method directly takes the type specified in the Mixin target (strongly typed)
  62. public void testCaseF() {
  63. runTest("casef");
  64. }
  65. // targeting multiple types from the Mixin
  66. public void testCaseG() {
  67. runTest("caseg");
  68. }
  69. // Null value for mixin target pattern
  70. public void testCaseH() {
  71. runTest("caseh");
  72. }
  73. // Invalid interfaces annotation value entries
  74. public void testCaseI() {
  75. runTest("casei");
  76. }
  77. // invalid return type for factory method
  78. public void testCaseJ() {
  79. runTest("casej");
  80. }
  81. // too many arguments to the factory method
  82. public void testCaseK() {
  83. runTest("casek");
  84. }
  85. // mixin of a class - should be an error (this one reported by the compiler due to a failed cast)
  86. public void testCaseL() {
  87. runTest("casel");
  88. }
  89. // mixin of a class - should be an error (this one reported by the annotation processing)
  90. public void testCaseM() {
  91. runTest("casem");
  92. }
  93. // factory returns class but interface specified - this is OK
  94. public void testCaseN() {
  95. runTest("casen");
  96. }
  97. // factory returns class but interface specified - not ok as class doesn't implement interface
  98. public void testCaseO() {
  99. runTest("caseo");
  100. }
  101. // interface subsetting used (factory returns class) - but only one method should be delegated
  102. public void testCaseP() {
  103. runTest("casep");
  104. }
  105. // factory return type implements two interfaces, both should be mixed as specified
  106. public void testCaseQ() {
  107. runTest("caseq");
  108. }
  109. // testing a pure marker interface - no methods added
  110. public void testCaseR() {
  111. runTest("caser");
  112. }
  113. // factory method has incompatible return type - verifyerror if we did use that factory
  114. public void testCaseS() {
  115. runTest("cases");
  116. }
  117. // weave info - what happens?
  118. public void testCaseT() {
  119. runTest("caset");
  120. }
  121. // --
  122. public static Test suite() {
  123. return XMLBasedAjcTestCase.loadSuite(DeclareMixinTests.class);
  124. }
  125. protected java.net.URL getSpecFile() {
  126. return getClassResource("declareMixin.xml");
  127. }
  128. }