use of spoon.SpoonException in project spoon by INRIA.
the class ProcessingTest method testInitPropertiesWithWrongType.
@Test
public void testInitPropertiesWithWrongType() throws Exception {
class AProcessor extends AbstractManualProcessor {
@Property
String aString;
@Property
int anInt;
@Property
Object anObject;
@Override
public void process() {
}
}
;
AProcessor p = new AProcessor();
Launcher launcher = new Launcher();
p.setFactory(launcher.getFactory());
ProcessorProperties props = new ProcessorPropertiesImpl();
props.set("aString", "foo");
props.set("anObject", "foo");
props.set("anInt", "foo");
try {
ProcessorUtils.initProperties(p, props);
fail();
} catch (SpoonException e) {
assertTrue(e.getMessage().contains("anInt"));
}
assertEquals("foo", p.aString);
assertEquals(0, p.anInt);
assertNull(p.anObject);
}
use of spoon.SpoonException in project spoon by INRIA.
the class ProcessingTest method testProcessorWithNoArgumentsInConstructor.
@Test
public void testProcessorWithNoArgumentsInConstructor() throws Exception {
/* throw correctly an exception when trying to use a processor with constructor with args */
Launcher l = new Launcher();
l.getEnvironment().setLevel(Level.ERROR.toString());
l.buildModel();
try {
new JDTBasedSpoonCompiler(l.getFactory()).instantiateAndProcess(Collections.singletonList("spoon.test.processing.ProcessingTest$WrongProcessor"));
fail();
} catch (SpoonException e) {
assertTrue(e.getMessage().startsWith("Unable to instantiate processor"));
assertTrue(e.getMessage().endsWith("Your processor should have a constructor with no arguments"));
// we are able to retrieve the exception parent
assertTrue(e.getCause() instanceof java.lang.InstantiationException);
}
}
Aggregations