You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IntrospectionHelperTest.java 24 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant;
  19. import junit.framework.TestCase;
  20. import junit.framework.AssertionFailedError;
  21. import java.io.File;
  22. import java.lang.reflect.Method;
  23. import java.lang.reflect.InvocationTargetException;
  24. import java.util.Enumeration;
  25. import java.util.HashMap;
  26. import java.util.Hashtable;
  27. import java.util.Iterator;
  28. import java.util.List;
  29. import java.util.Locale;
  30. import java.util.Map;
  31. import org.apache.tools.ant.taskdefs.condition.Os;
  32. /**
  33. * JUnit 3 testcases for org.apache.tools.ant.IntrospectionHelper.
  34. *
  35. */
  36. public class IntrospectionHelperTest extends TestCase {
  37. private Project p;
  38. private IntrospectionHelper ih;
  39. private static final String projectBasedir = File.separator;
  40. public IntrospectionHelperTest(String name) {
  41. super(name);
  42. }
  43. public void setUp() {
  44. p = new Project();
  45. p.setBasedir(projectBasedir);
  46. ih = IntrospectionHelper.getHelper(getClass());
  47. }
  48. public void testIsDynamic() {
  49. assertTrue("Not dynamic", false == ih.isDynamic());
  50. }
  51. public void testIsContainer() {
  52. assertTrue("Not a container", false == ih.isContainer());
  53. }
  54. public void testAddText() throws BuildException {
  55. ih.addText(p, this, "test");
  56. try {
  57. ih.addText(p, this, "test2");
  58. fail("test2 shouldn\'t be equal to test");
  59. } catch (BuildException be) {
  60. assertTrue(be.getException() instanceof AssertionFailedError);
  61. }
  62. ih = IntrospectionHelper.getHelper(String.class);
  63. try {
  64. ih.addText(p, "", "test");
  65. fail("String doesn\'t support addText");
  66. } catch (BuildException be) {
  67. }
  68. }
  69. public void testGetAddTextMethod() {
  70. Method m = ih.getAddTextMethod();
  71. assertMethod(m, "addText", String.class, "test", "bing!");
  72. ih = IntrospectionHelper.getHelper(String.class);
  73. try {
  74. m = ih.getAddTextMethod();
  75. } catch (BuildException e) {}
  76. }
  77. public void testSupportsCharacters() {
  78. assertTrue("IntrospectionHelperTest supports addText",
  79. ih.supportsCharacters());
  80. ih = IntrospectionHelper.getHelper(String.class);
  81. assertTrue("String doesn\'t support addText", !ih.supportsCharacters());
  82. }
  83. public void addText(String text) {
  84. assertEquals("test", text);
  85. }
  86. public void testElementCreators() throws BuildException {
  87. try {
  88. ih.getElementType("one");
  89. fail("don't have element type one");
  90. } catch (BuildException be) {
  91. }
  92. try {
  93. ih.getElementType("two");
  94. fail("createTwo takes arguments");
  95. } catch (BuildException be) {
  96. }
  97. try {
  98. ih.getElementType("three");
  99. fail("createThree returns void");
  100. } catch (BuildException be) {
  101. }
  102. try {
  103. ih.getElementType("four");
  104. fail("createFour returns array");
  105. } catch (BuildException be) {
  106. }
  107. try {
  108. ih.getElementType("five");
  109. fail("createFive returns primitive type");
  110. } catch (BuildException be) {
  111. }
  112. assertEquals(String.class, ih.getElementType("six"));
  113. assertEquals("test", ih.createElement(p, this, "six"));
  114. try {
  115. ih.getElementType("seven");
  116. fail("addSeven takes two arguments");
  117. } catch (BuildException be) {
  118. }
  119. try {
  120. ih.getElementType("eight");
  121. fail("addEight takes no arguments");
  122. } catch (BuildException be) {
  123. }
  124. try {
  125. ih.getElementType("nine");
  126. fail("nine return non void");
  127. } catch (BuildException be) {
  128. }
  129. try {
  130. ih.getElementType("ten");
  131. fail("addTen takes array argument");
  132. } catch (BuildException be) {
  133. }
  134. try {
  135. ih.getElementType("eleven");
  136. fail("addEleven takes primitive argument");
  137. } catch (BuildException be) {
  138. }
  139. try {
  140. ih.getElementType("twelve");
  141. fail("no primitive constructor for java.lang.Class");
  142. } catch (BuildException be) {
  143. }
  144. assertEquals(StringBuffer.class, ih.getElementType("thirteen"));
  145. assertEquals("test", ih.createElement(p, this, "thirteen").toString());
  146. try {
  147. ih.createElement(p, this, "fourteen");
  148. fail("fourteen throws NullPointerException");
  149. } catch (BuildException be) {
  150. assertTrue(be.getException() instanceof NullPointerException);
  151. }
  152. try {
  153. ih.createElement(p, this, "fourteen");
  154. fail("fifteen throws NullPointerException");
  155. } catch (BuildException be) {
  156. assertTrue(be.getException() instanceof NullPointerException);
  157. }
  158. }
  159. private Map getExpectedNestedElements() {
  160. Map elemMap = new Hashtable();
  161. elemMap.put("six", String.class);
  162. elemMap.put("thirteen", StringBuffer.class);
  163. elemMap.put("fourteen", StringBuffer.class);
  164. elemMap.put("fifteen", StringBuffer.class);
  165. return elemMap;
  166. }
  167. public void testGetNestedElements() {
  168. Map elemMap = getExpectedNestedElements();
  169. Enumeration e = ih.getNestedElements();
  170. while (e.hasMoreElements()) {
  171. String name = (String) e.nextElement();
  172. Class expect = (Class) elemMap.get(name);
  173. assertNotNull("Support for "+name+" in IntrospectioNHelperTest?",
  174. expect);
  175. assertEquals("Return type of "+name, expect, ih.getElementType(name));
  176. elemMap.remove(name);
  177. }
  178. assertTrue("Found all", elemMap.isEmpty());
  179. }
  180. public void testGetNestedElementMap() {
  181. Map elemMap = getExpectedNestedElements();
  182. Map actualMap = ih.getNestedElementMap();
  183. for (Iterator i = actualMap.entrySet().iterator(); i.hasNext();) {
  184. Map.Entry entry = (Map.Entry) i.next();
  185. String elemName = (String) entry.getKey();
  186. Class elemClass = (Class) elemMap.get(elemName);
  187. assertNotNull("Support for " + elemName +
  188. " in IntrospectionHelperTest?", elemClass);
  189. assertEquals("Type of " + elemName, elemClass, entry.getValue());
  190. elemMap.remove(elemName);
  191. }
  192. assertTrue("Found all", elemMap.isEmpty());
  193. // Check it's a read-only map.
  194. try {
  195. actualMap.clear();
  196. } catch (UnsupportedOperationException e) {}
  197. }
  198. public void testGetElementMethod() {
  199. assertElemMethod("six", "createSix", String.class, null);
  200. assertElemMethod("thirteen", "addThirteen", null, StringBuffer.class);
  201. assertElemMethod("fourteen", "addFourteen", null, StringBuffer.class);
  202. assertElemMethod("fifteen", "createFifteen", StringBuffer.class, null);
  203. }
  204. private void assertElemMethod(String elemName, String methodName,
  205. Class returnType, Class methodArg) {
  206. Method m = ih.getElementMethod(elemName);
  207. assertEquals("Method name", methodName, m.getName());
  208. Class expectedReturnType = (returnType == null)? Void.TYPE: returnType;
  209. assertEquals("Return type", expectedReturnType, m.getReturnType());
  210. Class[] args = m.getParameterTypes();
  211. if (methodArg != null) {
  212. assertEquals("Arg Count", 1, args.length);
  213. assertEquals("Arg Type", methodArg, args[0]);
  214. } else {
  215. assertEquals("Arg Count", 0, args.length);
  216. }
  217. }
  218. public Object createTwo(String s) {
  219. return null;
  220. }
  221. public void createThree() {}
  222. public Object[] createFour() {
  223. return null;
  224. }
  225. public int createFive() {
  226. return 0;
  227. }
  228. public String createSix() {
  229. return "test";
  230. }
  231. public StringBuffer createFifteen() {
  232. throw new NullPointerException();
  233. }
  234. public void addSeven(String s, String s2) {}
  235. public void addEight() {}
  236. public String addNine(String s) {
  237. return null;
  238. }
  239. public void addTen(String[] s) {}
  240. public void addEleven(int i) {}
  241. public void addTwelve(Class c) {}
  242. public void addThirteen(StringBuffer sb) {
  243. sb.append("test");
  244. }
  245. public void addFourteen(StringBuffer s) {
  246. throw new NullPointerException();
  247. }
  248. public void testAttributeSetters() throws BuildException {
  249. try {
  250. ih.setAttribute(p, this, "one", "test");
  251. fail("setOne doesn't exist");
  252. } catch (BuildException be) {
  253. }
  254. try {
  255. ih.setAttribute(p, this, "two", "test");
  256. fail("setTwo returns non void");
  257. } catch (BuildException be) {
  258. }
  259. try {
  260. ih.setAttribute(p, this, "three", "test");
  261. fail("setThree takes no args");
  262. } catch (BuildException be) {
  263. }
  264. try {
  265. ih.setAttribute(p, this, "four", "test");
  266. fail("setFour takes two args");
  267. } catch (BuildException be) {
  268. }
  269. try {
  270. ih.setAttribute(p, this, "five", "test");
  271. fail("setFive takes array arg");
  272. } catch (BuildException be) {
  273. }
  274. try {
  275. ih.setAttribute(p, this, "six", "test");
  276. fail("Project doesn't have a String constructor");
  277. } catch (BuildException be) {
  278. }
  279. ih.setAttribute(p, this, "seven", "2");
  280. try {
  281. ih.setAttribute(p, this, "seven", "3");
  282. fail("2 shouldn't be equals to three");
  283. } catch (BuildException be) {
  284. assertTrue(be.getException() instanceof AssertionFailedError);
  285. }
  286. ih.setAttribute(p, this, "eight", "2");
  287. try {
  288. ih.setAttribute(p, this, "eight", "3");
  289. fail("2 shouldn't be equals to three - as int");
  290. } catch (BuildException be) {
  291. assertTrue(be.getException() instanceof AssertionFailedError);
  292. }
  293. ih.setAttribute(p, this, "nine", "2");
  294. try {
  295. ih.setAttribute(p, this, "nine", "3");
  296. fail("2 shouldn't be equals to three - as Integer");
  297. } catch (BuildException be) {
  298. assertTrue(be.getException() instanceof AssertionFailedError);
  299. }
  300. ih.setAttribute(p, this, "ten", "2");
  301. try {
  302. ih.setAttribute(p, this, "ten", "3");
  303. fail(projectBasedir+"2 shouldn't be equals to "+projectBasedir+"3");
  304. } catch (BuildException be) {
  305. assertTrue(be.getException() instanceof AssertionFailedError);
  306. }
  307. ih.setAttribute(p, this, "eleven", "2");
  308. try {
  309. ih.setAttribute(p, this, "eleven", "on");
  310. fail("on shouldn't be false");
  311. } catch (BuildException be) {
  312. assertTrue(be.getException() instanceof AssertionFailedError);
  313. }
  314. ih.setAttribute(p, this, "twelve", "2");
  315. try {
  316. ih.setAttribute(p, this, "twelve", "on");
  317. fail("on shouldn't be false");
  318. } catch (BuildException be) {
  319. assertTrue(be.getException() instanceof AssertionFailedError);
  320. }
  321. ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project");
  322. try {
  323. ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.ProjectHelper");
  324. fail("org.apache.tools.ant.Project shouldn't be equal to org.apache.tools.ant.ProjectHelper");
  325. } catch (BuildException be) {
  326. assertTrue(be.getException() instanceof AssertionFailedError);
  327. }
  328. try {
  329. ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project2");
  330. fail("org.apache.tools.ant.Project2 doesn't exist");
  331. } catch (BuildException be) {
  332. assertTrue(be.getException() instanceof ClassNotFoundException);
  333. }
  334. ih.setAttribute(p, this, "fourteen", "2");
  335. try {
  336. ih.setAttribute(p, this, "fourteen", "on");
  337. fail("2 shouldn't be equals to three - as StringBuffer");
  338. } catch (BuildException be) {
  339. assertTrue(be.getException() instanceof AssertionFailedError);
  340. }
  341. ih.setAttribute(p, this, "fifteen", "abcd");
  342. try {
  343. ih.setAttribute(p, this, "fifteen", "on");
  344. fail("o shouldn't be equal to a");
  345. } catch (BuildException be) {
  346. assertTrue(be.getException() instanceof AssertionFailedError);
  347. }
  348. ih.setAttribute(p, this, "sixteen", "abcd");
  349. try {
  350. ih.setAttribute(p, this, "sixteen", "on");
  351. fail("o shouldn't be equal to a");
  352. } catch (BuildException be) {
  353. assertTrue(be.getException() instanceof AssertionFailedError);
  354. }
  355. ih.setAttribute(p, this, "seventeen", "17");
  356. try {
  357. ih.setAttribute(p, this, "seventeen", "3");
  358. fail("17 shouldn't be equals to three");
  359. } catch (BuildException be) {
  360. assertTrue(be.getException() instanceof AssertionFailedError);
  361. }
  362. ih.setAttribute(p, this, "eightteen", "18");
  363. try {
  364. ih.setAttribute(p, this, "eightteen", "3");
  365. fail("18 shouldn't be equals to three");
  366. } catch (BuildException be) {
  367. assertTrue(be.getException() instanceof AssertionFailedError);
  368. }
  369. ih.setAttribute(p, this, "nineteen", "19");
  370. try {
  371. ih.setAttribute(p, this, "nineteen", "3");
  372. fail("19 shouldn't be equals to three");
  373. } catch (BuildException be) {
  374. assertTrue(be.getException() instanceof AssertionFailedError);
  375. }
  376. }
  377. private Map getExpectedAttributes() {
  378. Map attrMap = new Hashtable();
  379. attrMap.put("seven", String.class);
  380. attrMap.put("eight", Integer.TYPE);
  381. attrMap.put("nine", Integer.class);
  382. attrMap.put("ten", File.class);
  383. attrMap.put("eleven", Boolean.TYPE);
  384. attrMap.put("twelve", Boolean.class);
  385. attrMap.put("thirteen", Class.class);
  386. attrMap.put("fourteen", StringBuffer.class);
  387. attrMap.put("fifteen", Character.TYPE);
  388. attrMap.put("sixteen", Character.class);
  389. attrMap.put("seventeen", Byte.TYPE);
  390. attrMap.put("eightteen", Short.TYPE);
  391. attrMap.put("nineteen", Double.TYPE);
  392. /*
  393. * JUnit 3.7 adds a getName method to TestCase - so we now
  394. * have a name attribute in IntrospectionHelperTest if we run
  395. * under JUnit 3.7 but not in earlier versions.
  396. *
  397. * Simply add it here and remove it after the tests.
  398. */
  399. attrMap.put("name", String.class);
  400. return attrMap;
  401. }
  402. public void testGetAttributes() {
  403. Map attrMap = getExpectedAttributes();
  404. Enumeration e = ih.getAttributes();
  405. while (e.hasMoreElements()) {
  406. String name = (String) e.nextElement();
  407. Class expect = (Class) attrMap.get(name);
  408. assertNotNull("Support for "+name+" in IntrospectionHelperTest?",
  409. expect);
  410. assertEquals("Type of "+name, expect, ih.getAttributeType(name));
  411. attrMap.remove(name);
  412. }
  413. attrMap.remove("name");
  414. assertTrue("Found all", attrMap.isEmpty());
  415. }
  416. public void testGetAttributeMap() {
  417. Map attrMap = getExpectedAttributes();
  418. Map actualMap = ih.getAttributeMap();
  419. for (Iterator i = actualMap.entrySet().iterator(); i.hasNext();) {
  420. Map.Entry entry = (Map.Entry) i.next();
  421. String attrName = (String) entry.getKey();
  422. Class attrClass = (Class) attrMap.get(attrName);
  423. assertNotNull("Support for " + attrName +
  424. " in IntrospectionHelperTest?", attrClass);
  425. assertEquals("Type of " + attrName, attrClass, entry.getValue());
  426. attrMap.remove(attrName);
  427. }
  428. attrMap.remove("name");
  429. assertTrue("Found all", attrMap.isEmpty());
  430. // Check it's a read-only map.
  431. try {
  432. actualMap.clear();
  433. } catch (UnsupportedOperationException e) {}
  434. }
  435. public void testGetAttributeMethod() {
  436. assertAttrMethod("seven", "setSeven", String.class,
  437. "2", "3");
  438. assertAttrMethod("eight", "setEight", Integer.TYPE,
  439. new Integer(2), new Integer(3));
  440. assertAttrMethod("nine", "setNine", Integer.class,
  441. new Integer(2), new Integer(3));
  442. assertAttrMethod("ten", "setTen", File.class,
  443. new File(projectBasedir + 2), new File("toto"));
  444. assertAttrMethod("eleven", "setEleven", Boolean.TYPE,
  445. Boolean.FALSE, Boolean.TRUE);
  446. assertAttrMethod("twelve", "setTwelve", Boolean.class,
  447. Boolean.FALSE, Boolean.TRUE);
  448. assertAttrMethod("thirteen", "setThirteen", Class.class,
  449. Project.class, Map.class);
  450. assertAttrMethod("fourteen", "setFourteen", StringBuffer.class,
  451. new StringBuffer("2"), new StringBuffer("3"));
  452. assertAttrMethod("fifteen", "setFifteen", Character.TYPE,
  453. new Character('a'), new Character('b'));
  454. assertAttrMethod("sixteen", "setSixteen", Character.class,
  455. new Character('a'), new Character('b'));
  456. assertAttrMethod("seventeen", "setSeventeen", Byte.TYPE,
  457. new Byte((byte)17), new Byte((byte)10));
  458. assertAttrMethod("eightteen", "setEightteen", Short.TYPE,
  459. new Short((short)18), new Short((short)10));
  460. assertAttrMethod("nineteen", "setNineteen", Double.TYPE,
  461. new Double(19), new Double((short)10));
  462. try {
  463. assertAttrMethod("onehundred", null, null, null, null);
  464. fail("Should have raised a BuildException!");
  465. } catch (BuildException e) {}
  466. }
  467. private void assertAttrMethod(String attrName, String methodName,
  468. Class methodArg, Object arg, Object badArg) {
  469. Method m = ih.getAttributeMethod(attrName);
  470. assertMethod(m, methodName, methodArg, arg, badArg);
  471. }
  472. public int setTwo(String s) {
  473. return 0;
  474. }
  475. public void setThree() {}
  476. public void setFour(String s1, String s2) {}
  477. public void setFive(String[] s) {}
  478. public void setSix(Project p) {}
  479. public void setSeven(String s) {
  480. assertEquals("2", s);
  481. }
  482. public void setEight(int i) {
  483. assertEquals(2, i);
  484. }
  485. public void setNine(Integer i) {
  486. assertEquals(2, i.intValue());
  487. }
  488. public void setTen(File f) {
  489. String path = f.getAbsolutePath();
  490. if (Os.isFamily("unix") || Os.isFamily("openvms")) {
  491. assertEquals(projectBasedir+"2", path);
  492. } else if (Os.isFamily("netware")) {
  493. assertEquals(projectBasedir+"2", path.toLowerCase(Locale.US));
  494. } else {
  495. assertEquals(":"+projectBasedir+"2",
  496. path.toLowerCase(Locale.US).substring(1));
  497. }
  498. }
  499. public void setEleven(boolean b) {
  500. assertTrue(!b);
  501. }
  502. public void setTwelve(Boolean b) {
  503. assertTrue(!b.booleanValue());
  504. }
  505. public void setThirteen(Class c) {
  506. assertEquals(Project.class, c);
  507. }
  508. public void setFourteen(StringBuffer sb) {
  509. assertEquals("2", sb.toString());
  510. }
  511. public void setFifteen(char c) {
  512. assertEquals(c, 'a');
  513. }
  514. public void setSixteen(Character c) {
  515. assertEquals(c.charValue(), 'a');
  516. }
  517. public void setSeventeen(byte b) {
  518. assertEquals(17, b);
  519. }
  520. public void setEightteen(short s) {
  521. assertEquals(18, s);
  522. }
  523. public void setNineteen(double d) {
  524. assertEquals(19, d, 1e-6);
  525. }
  526. public void testGetExtensionPoints() {
  527. List extensions = ih.getExtensionPoints();
  528. final int adders = 2;
  529. assertEquals("extension count", adders, extensions.size());
  530. // this original test assumed something about the order of
  531. // add(Number) and addConfigured(Map) returned by reflection.
  532. // Unfortunately the assumption doesn't hold for all VMs
  533. // (failed on MacOS X using JDK 1.4.2_05) and the possible
  534. // combinatorics are too hard to check. We really only want
  535. // to ensure that the more derived Hashtable can be found
  536. // before Map.
  537. // assertExtMethod(extensions.get(0), "add", Number.class,
  538. // new Integer(2), new Integer(3));
  539. // addConfigured(Hashtable) should come before addConfigured(Map)
  540. assertExtMethod(extensions.get(adders - 2),
  541. "addConfigured", Hashtable.class,
  542. makeTable("key", "value"), makeTable("1", "2"));
  543. assertExtMethod(extensions.get(adders - 1), "addConfigured", Map.class,
  544. new HashMap(), makeTable("1", "2"));
  545. }
  546. private void assertExtMethod(Object mo, String methodName, Class methodArg,
  547. Object arg, Object badArg) {
  548. assertMethod((Method) mo, methodName, methodArg, arg, badArg);
  549. }
  550. private void assertMethod(Method m, String methodName, Class methodArg,
  551. Object arg, Object badArg) {
  552. assertEquals("Method name", methodName, m.getName());
  553. assertEquals("Return type", Void.TYPE, m.getReturnType());
  554. Class[] args = m.getParameterTypes();
  555. assertEquals("Arg Count", 1, args.length);
  556. assertEquals("Arg Type", methodArg, args[0]);
  557. try {
  558. m.invoke(this, new Object[] { arg });
  559. } catch (IllegalAccessException e) {
  560. throw new BuildException(e);
  561. } catch (InvocationTargetException e) {
  562. throw new BuildException(e);
  563. }
  564. try {
  565. m.invoke(this, new Object[] { badArg });
  566. fail("Should have raised an assertion exception");
  567. } catch (IllegalAccessException e) {
  568. throw new BuildException(e);
  569. } catch (InvocationTargetException e) {
  570. Throwable t = e.getTargetException();
  571. assertTrue(t instanceof junit.framework.AssertionFailedError);
  572. }
  573. }
  574. public List add(List l) {
  575. // INVALID extension point
  576. return null;
  577. }
  578. // see comments in testGetExtensionPoints
  579. // public void add(Number n) {
  580. // // Valid extension point
  581. // assertEquals(2, n.intValue());
  582. // }
  583. public void add(List l, int i) {
  584. // INVALID extension point
  585. }
  586. public void addConfigured(Map m) {
  587. // Valid extension point
  588. assertTrue(m.size() == 0);
  589. }
  590. public void addConfigured(Hashtable h) {
  591. // Valid extension point, more derived than Map above, but *after* it!
  592. assertEquals(makeTable("key", "value"), h);
  593. }
  594. private Hashtable makeTable(Object key, Object value) {
  595. Hashtable table = new Hashtable();
  596. table.put(key, value);
  597. return table;
  598. }
  599. } // IntrospectionHelperTest