use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BlockTest method testCopyingBlock.
@Test
public void testCopyingBlock() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testCopyingBlock").method("foo: bar\n" + " | block |\n" + " block := [:a | a + bar].\n" + " ^block value: 4").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
assertEquals(Integer.valueOf(7), method.invoke(fooObject, 3));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BlockTest method testTwoArgCleanBlock.
@Test
public void testTwoArgCleanBlock() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testTwoArgCleanBlock").method("foo: foo bar: bar\n" + " | block |\n" + " block := [:a :b| a + b].\n" + " ^block value: foo value: bar").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_bar_", Object.class, Object.class);
assertEquals(Integer.valueOf(7), method.invoke(fooObject, 3, 4));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class CollectionsTest method testOrderedCollectionAdd.
@Test
public void testOrderedCollectionAdd() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class stClass = new ClassBuilder("FooObject_testOrderedCollectionAdd").method("foo | coll |" + " coll := OrderedCollection new." + " coll add: 1." + " coll add: 'Fromage'." + " coll add: 2." + " ^coll asJavaList").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Object result = method.invoke(fooObject);
assertEquals(3, ((ArrayList) result).size());
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class CollectionsTest method testSetAdd.
@Test
public void testSetAdd() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class stClass = new ClassBuilder("FooObject_testSetAdd").method("foo | set |" + " set := Set new." + " set add: 1." + " set add: 'Fromage'." + " set add: 2." + " ^set asJavaSet").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Object result = method.invoke(fooObject);
assertEquals(3, ((Set) result).size());
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class CollectionsTest method testOrderedCollectionRemoveFirst.
@Test
public void testOrderedCollectionRemoveFirst() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class stClass = new ClassBuilder("FooObject_testOrderedCollectionRemoveFirst").method("foo | coll |" + " coll := OrderedCollection new." + " coll add: 1." + " coll add: 'Fromage'." + " coll add: 2." + " coll removeFirst." + " ^coll asJavaList").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Object result = method.invoke(fooObject);
assertEquals(2, ((ArrayList) result).size());
}
Aggregations