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

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