use of spoon.processing.ProcessorPropertiesImpl in project spoon by INRIA.
the class ProcessingTest method testInitProperties.
@Test
public void testInitProperties() throws Exception {
class AProcessor extends AbstractManualProcessor {
@Property
String aString;
@Property
int anInt;
@Property
Object anObject;
@Property
int[] arrayInt;
@Property
List<String> listString;
@Property
boolean[] arrayBoolean;
@Property
Map<String, Double> mapStringDouble;
@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("anInt", 5);
Object o = new Object();
props.set("anObject", o);
int[] arrayInt = new int[] { 1, 2, 3 };
props.set("arrayInt", arrayInt);
props.set("listString", Arrays.asList(new String[] { "42" }));
boolean[] arrayBoolean = new boolean[] { true };
props.set("arrayBoolean", arrayBoolean);
HashMap<String, Double> mapTest = new HashMap<>();
mapTest.put("foobar", 42.42);
props.set("mapStringDouble", mapTest);
ProcessorUtils.initProperties(p, props);
assertEquals("foo", p.aString);
assertEquals(5, p.anInt);
assertSame(o, p.anObject);
assertSame(arrayInt, p.arrayInt);
assertEquals(Arrays.asList(new String[] { "42" }), p.listString);
assertSame(arrayBoolean, p.arrayBoolean);
assertSame(mapTest, p.mapStringDouble);
}
use of spoon.processing.ProcessorPropertiesImpl 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.processing.ProcessorPropertiesImpl in project spoon by INRIA.
the class ProcessingTest method testInitPropertiesWithStringType.
@Test
public void testInitPropertiesWithStringType() throws Exception {
class AProcessor extends AbstractManualProcessor {
@Property
String aString;
@Property
int anInt;
@Property
Object anObject;
@Property
int[] arrayInt;
@Property
List<String> listString;
@Property
boolean[] arrayBoolean;
@Property
Map<String, Double> mapStringDouble;
@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("anInt", "42");
props.set("anObject", "{}");
props.set("arrayInt", "[42,43]");
props.set("listString", "[\"foo\", \"bar\"]");
props.set("arrayBoolean", "[true]");
props.set("mapStringDouble", "{\"foo\": 10.21, \"bar\": 14.42}");
ProcessorUtils.initProperties(p, props);
assertEquals("foo", p.aString);
assertEquals(42, p.anInt);
assertNotNull(p.anObject);
assertArrayEquals(new int[] { 42, 43 }, p.arrayInt);
assertEquals(Arrays.asList(new String[] { "foo", "bar" }), p.listString);
assertArrayEquals(new boolean[] { true }, p.arrayBoolean);
Map<String, Double> mamap = new HashMap<>();
mamap.put("foo", 10.21);
mamap.put("bar", 14.42);
assertEquals(mamap, p.mapStringDouble);
}
Aggregations