Exemplo n.º 1
0
  public void testAddText() throws BuildException {
    IntrospectionHelper ih = IntrospectionHelper.getHelper(java.lang.String.class);
    try {
      ih.addText("", "test");
      fail("String doesn\'t support addText");
    } catch (BuildException be) {
    }

    ih = IntrospectionHelper.getHelper(getClass());
    ih.addText(this, "test");
    try {
      ih.addText(this, "test2");
      fail("test2 shouldn\'t be equal to test");
    } catch (BuildException be) {
      assertTrue(be.getException() instanceof AssertionFailedError);
    }
  }
Exemplo n.º 2
0
 public void testAttributeSetters() throws BuildException {
   Project p = new Project();
   p.setBasedir("/tmp");
   IntrospectionHelper ih = IntrospectionHelper.getHelper(getClass());
   try {
     ih.setAttribute(p, this, "one", "test");
     fail("setOne doesn't exist");
   } catch (BuildException be) {
   }
   try {
     ih.setAttribute(p, this, "two", "test");
     fail("setTwo returns non void");
   } catch (BuildException be) {
   }
   try {
     ih.setAttribute(p, this, "three", "test");
     fail("setThree takes no args");
   } catch (BuildException be) {
   }
   try {
     ih.setAttribute(p, this, "four", "test");
     fail("setFour takes two args");
   } catch (BuildException be) {
   }
   try {
     ih.setAttribute(p, this, "five", "test");
     fail("setFive takes array arg");
   } catch (BuildException be) {
   }
   try {
     ih.setAttribute(p, this, "six", "test");
     fail("Project doesn't have a String constructor");
   } catch (BuildException be) {
   }
   ih.setAttribute(p, this, "seven", "2");
   try {
     ih.setAttribute(p, this, "seven", "3");
     fail("2 shouldn't be equals to three");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "eight", "2");
   try {
     ih.setAttribute(p, this, "eight", "3");
     fail("2 shouldn't be equals to three - as int");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "nine", "2");
   try {
     ih.setAttribute(p, this, "nine", "3");
     fail("2 shouldn't be equals to three - as Integer");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "ten", "2");
   try {
     ih.setAttribute(p, this, "ten", "3");
     fail("/tmp/2 shouldn't be equals to /tmp/3");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "eleven", "2");
   try {
     ih.setAttribute(p, this, "eleven", "on");
     fail("on shouldn't be false");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "twelve", "2");
   try {
     ih.setAttribute(p, this, "twelve", "on");
     fail("on shouldn't be false");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project");
   try {
     ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.ProjectHelper");
     fail("org.apache.tools.ant.Project shouldn't be equal to org.apache.tools.ant.ProjectHelper");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   try {
     ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project2");
     fail("org.apache.tools.ant.Project2 doesn't exist");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof ClassNotFoundException);
   }
   ih.setAttribute(p, this, "fourteen", "2");
   try {
     ih.setAttribute(p, this, "fourteen", "on");
     fail("2 shouldn't be equals to three - as StringBuffer");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "fifteen", "abcd");
   try {
     ih.setAttribute(p, this, "fifteen", "on");
     fail("o shouldn't be equal to a");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
   ih.setAttribute(p, this, "sixteen", "abcd");
   try {
     ih.setAttribute(p, this, "sixteen", "on");
     fail("o shouldn't be equal to a");
   } catch (BuildException be) {
     assertTrue(be.getException() instanceof AssertionFailedError);
   }
 }
Exemplo n.º 3
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);
    }
  }