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.

MakeTestClass.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Created on 02-Aug-2004
  3. *
  4. */
  5. package org.aspectj.testing;
  6. import java.io.FileInputStream;
  7. import java.io.FileOutputStream;
  8. import java.io.InputStreamReader;
  9. import java.io.PrintStream;
  10. import java.text.NumberFormat;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import org.apache.commons.digester3.Digester;
  14. /**
  15. * @author colyer
  16. *
  17. * TODO To change the template for this generated type comment go to
  18. * Window - Preferences - Java - Code Style - Code Templates
  19. */
  20. public class MakeTestClass {
  21. private static final String HEADER =
  22. "/* *******************************************************************\n" +
  23. " * Copyright (c) 2004 IBM Corporation\n" +
  24. " * All rights reserved.\n" +
  25. " * This program and the accompanying materials are made available\n" +
  26. " * under the terms of the Eclipse Public License v 2.0\n" +
  27. " * which accompanies this distribution and is available at\n" +
  28. " * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt\n" +
  29. " * \n" +
  30. " * ******************************************************************/\n" +
  31. "package org.aspectj.systemtest.XXX;\n" +
  32. "\n" +
  33. "import java.io.File;\n" +
  34. "import junit.framework.Test;\n" +
  35. "import org.aspectj.testing.XMLBasedAjcTestCase;\n" +
  36. "\n" +
  37. "public class ";
  38. private static final String BODY_1 =
  39. " extends org.aspectj.testing.XMLBasedAjcTestCase {\n" +
  40. "\n" +
  41. " public static Test suite() {\n" +
  42. " return XMLBasedAjcTestCase.loadSuite(";
  43. private static final String BODY_2 =
  44. ".class);\n" +
  45. " }\n" +
  46. "\n" +
  47. " protected File getSpecFile() {\n" +
  48. " return new File(\"";
  49. private static final String BODY_3 =
  50. "\");\n" +
  51. " }\n";
  52. private static final String FOOTER =
  53. "}\n";
  54. private List<AjcTest> tests = new ArrayList<>();
  55. private String className;
  56. private String suiteFile;
  57. public static void main(String[] args) throws Exception {
  58. new MakeTestClass(args[0],args[1]).makeTestClass();
  59. }
  60. public MakeTestClass(String className, String suiteFile)throws Exception {
  61. this.className = className;
  62. this.suiteFile = suiteFile;
  63. Digester d = getDigester();
  64. InputStreamReader isr = new InputStreamReader(new FileInputStream(suiteFile));
  65. d.parse(isr);
  66. }
  67. public void addTest(AjcTest test) {
  68. tests.add(test);
  69. }
  70. public void makeTestClass() throws Exception {
  71. FileOutputStream fos = new FileOutputStream(className + ".java");
  72. PrintStream out = new PrintStream(fos);
  73. out.print(HEADER);
  74. out.print(className);
  75. out.print(BODY_1);
  76. out.print(className);
  77. out.print(BODY_2);
  78. out.print(suiteFile);
  79. out.print(BODY_3);
  80. out.println();
  81. int testNo = 1;
  82. NumberFormat nf = NumberFormat.getInstance();
  83. nf.setMinimumIntegerDigits(3);
  84. for (AjcTest test: tests) {
  85. out.println();
  86. out.print(" public void test");
  87. out.print(nf.format(testNo++));
  88. out.println("(){");
  89. out.println(" runTest(\"" + test.getTitle() + "\");");
  90. out.println(" }");
  91. }
  92. out.println();
  93. out.println(FOOTER);
  94. out.close();
  95. }
  96. private Digester getDigester() {
  97. Digester digester = new Digester();
  98. digester.push(this);
  99. digester.addObjectCreate("suite/ajc-test",AjcTest.class);
  100. digester.addSetProperties("suite/ajc-test");
  101. digester.addSetNext("suite/ajc-test","addTest","org.aspectj.testing.AjcTest");
  102. return digester;
  103. }
  104. }