use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class CollectionsTest method testArrayCollect.
@Test
public void testArrayCollect() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class stClass = new ClassBuilder("FooObject_testArrayAdd").method("foo | coll |" + " ^#(1 2 3) collect: [:each | each + 4]").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Object result = method.invoke(fooObject);
assertEquals(3, ((Object[]) result).length);
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class ExceptionTest method testNested_on_do_1.
@Test
public void testNested_on_do_1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testNested_on_do_1").instVar("bar").method("foo" + " ^self foo: [TestExceptionA raise. bar := #failed]").method("isFailed ^bar notNil").method("foo: aBlock " + "^[[aBlock value] on: TestExceptionA do: [:ex1 | ex1 testValue]] on: TestExceptionB do: [:ex | ex testValue]").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Method isFailed = fooObject.getClass().getMethod("isFailed");
assertEquals(Integer.valueOf(7), method.invoke(fooObject));
assertEquals(Boolean.FALSE, isFailed.invoke(fooObject));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class ExceptionTest method test_MessageNotUnderstood1.
@Test
public void test_MessageNotUnderstood1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_test_MessageNotUnderstood1").method("foo" + "^[3 zork] on: MessageNotUnderstood do: [:ex | 7]").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
assertEquals(Integer.valueOf(7), method.invoke(fooObject));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class ExceptionTest method test_on_do_.
@Test
public void test_on_do_() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_test_on_do_").instVar("bar").method("foo" + " ^self foo: [TestExceptionA raise. bar := #failed]").method("isFailed ^bar notNil").method("foo: aBlock " + "^[aBlock value] on: TestExceptionA do: [:ex | ex testValue]").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Method isFailed = fooObject.getClass().getMethod("isFailed");
assertEquals(Integer.valueOf(7), method.invoke(fooObject));
assertEquals(Boolean.FALSE, isFailed.invoke(fooObject));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BlockTest method testReadWriteInstVarInBlock.
@Test
public void testReadWriteInstVarInBlock() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testReadWriteInstVarInBlock").method("foo: bar\n" + "bar setNameInBlock: 'Fromage'.\n" + "^bar readNameInBlock").build();
Class barClass = new ClassBuilder("BarObject_testReadWriteInstVarInBlock").method("setNameInBlock: anObject\n" + " [name := anObject] value").method("readNameInBlock\n" + " ^[name] value").instVar("name").build();
Object fooObject = stClass.newInstance();
Object barObject = barClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
assertEquals("Fromage", method.invoke(fooObject, barObject));
}
Aggregations