Exemplo n.º 1
0
 public void testGetNestedElements() {
   Hashtable h = new Hashtable();
   h.put("six", java.lang.String.class);
   h.put("thirteen", java.lang.StringBuffer.class);
   h.put("fourteen", java.lang.StringBuffer.class);
   h.put("fifteen", java.lang.StringBuffer.class);
   IntrospectionHelper ih = IntrospectionHelper.getHelper(getClass());
   Enumeration enum_ = ih.getNestedElements();
   while (enum_.hasMoreElements()) {
     String name = (String) enum_.nextElement();
     Class expect = (Class) h.get(name);
     assertNotNull("Support for " + name + " in IntrospectioNHelperTest?", expect);
     assertEquals("Return type of " + name, expect, ih.getElementType(name));
     h.remove(name);
   }
   assertTrue("Found all", h.isEmpty());
 }
Exemplo n.º 2
0
  public void testElementCreators() throws BuildException {
    IntrospectionHelper ih = IntrospectionHelper.getHelper(getClass());
    try {
      ih.getElementType("one");
      fail("don't have element type one");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("two");
      fail("createTwo takes arguments");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("three");
      fail("createThree returns void");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("four");
      fail("createFour returns array");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("five");
      fail("createFive returns primitive type");
    } catch (BuildException be) {
    }
    assertEquals(java.lang.String.class, ih.getElementType("six"));
    assertEquals("test", ih.createElement(this, "six"));

    try {
      ih.getElementType("seven");
      fail("addSeven takes two arguments");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("eight");
      fail("addEight takes no arguments");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("nine");
      fail("nine return non void");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("ten");
      fail("addTen takes array argument");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("eleven");
      fail("addTen takes primitive argument");
    } catch (BuildException be) {
    }
    try {
      ih.getElementType("twelve");
      fail("no primitive constructor for java.lang.Class");
    } catch (BuildException be) {
    }
    assertEquals(java.lang.StringBuffer.class, ih.getElementType("thirteen"));
    assertEquals("test", ih.createElement(this, "thirteen").toString());

    try {
      ih.createElement(this, "fourteen");
      fail("fourteen throws NullPointerException");
    } catch (BuildException be) {
      assertTrue(be.getException() instanceof NullPointerException);
    }

    try {
      ih.createElement(this, "fourteen");
      fail("fifteen throws NullPointerException");
    } catch (BuildException be) {
      assertTrue(be.getException() instanceof NullPointerException);
    }
  }