1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package patterntesting.tool.aspectj;
22
23 import static org.junit.Assert.*;
24
25 import java.io.*;
26
27 import org.aspectj.tools.ant.taskdefs.AjcTask;
28 import org.junit.Test;
29 import org.slf4j.LoggerFactory;
30
31
32
33
34
35
36
37 public final class AjcXmlTaskTest {
38
39 private static final org.slf4j.Logger log = LoggerFactory.getLogger(AjcXmlTaskTest.class);
40 private final AjcXmlTask compiler = new AjcXmlTask();
41
42
43
44
45
46 @Test
47 public void testEmptyExecute() throws IOException {
48 ByteArrayOutputStream baos = new ByteArrayOutputStream();
49 compiler.setOutputStream(baos);
50 compiler.execute();
51 String xmlString = baos.toString();
52 baos.close();
53 checkXML(xmlString);
54 }
55
56
57
58
59
60 @Test
61 public void testGetResult() {
62 compiler.execute();
63 String xmlString = compiler.getResult();
64 checkXML(xmlString);
65 }
66
67 private static void checkXML(final String xmlString) {
68 log.debug(xmlString);
69 assertTrue(xmlString, xmlString.trim().startsWith("<"));
70 }
71
72
73
74
75
76
77
78 @Test
79 public void testHasAspectjPath() {
80 String classpath = System.getProperty("java.class.path");
81 log.info("classpath=" + classpath);
82 try {
83 System.setProperty("java.class.path", "/tmp/aspectjrt.jar");
84 assertTrue("aspectjrt.jar not recognized", AjcXmlTask
85 .hasAspectjPath());
86 System.setProperty("java.class.path", "/tmp/aspectjrt-1.6.8.jar");
87 assertTrue("aspectjrt-1.6.8.jar not recognized", AjcXmlTask
88 .hasAspectjPath());
89 } finally {
90 System.setProperty("java.class.path", classpath);
91 }
92 }
93
94
95
96
97
98
99
100 @Test
101 public void testFindAspectjPath() {
102 String classpath = System.getProperty("java.class.path");
103 try {
104 System.setProperty("java.class.path", ".");
105 File jarFile = AjcXmlTask.findAspectjPath();
106 log.info("aspectjrt.jar found: " + jarFile);
107 assertTrue(jarFile + " not found", jarFile.exists());
108 } finally {
109 System.setProperty("java.class.path", classpath);
110 }
111
112 }
113
114
115
116
117
118 @Test
119 public void testFindAspectjtoolsJar() {
120 File aspectjtoolsJar = AjcTask.findAspectjtoolsJar();
121 log.info("aspectjtoolsJar=" + aspectjtoolsJar);
122 assertNotNull(aspectjtoolsJar);
123 assertTrue(aspectjtoolsJar + " not found", aspectjtoolsJar.exists());
124 }
125
126 }
127