use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class ExceptionTest method testNested_on_do_2.
@Test
public void testNested_on_do_2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testNested_on_do_2").instVar("bar").method("foo" + " ^self foo: [TestExceptionA raise. bar := #failed]").method("isFailed ^bar notNil").method("foo: aBlock " + "^[[aBlock value] on: TestExceptionB do: [:ex | ex testValue]] on: TestExceptionA do: [:ex1 | ex1 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 FlowControlTest method testIfFalse3.
@Test
public void testIfFalse3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testIfFalse3").method("foo: bar\n" + " ^bar ifFalse: [1]").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
assertEquals(null, method.invoke(fooObject, true));
assertEquals(Integer.valueOf(1), method.invoke(fooObject, false));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class FlowControlTest method testIfFalse1.
@Test
public void testIfFalse1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testIfFalse1").method("foo: bar\n" + " bar ifFalse: [^1].\n" + " ^2").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
assertEquals(Integer.valueOf(2), method.invoke(fooObject, true));
assertEquals(Integer.valueOf(1), method.invoke(fooObject, false));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class FlowControlTest method testIfTrueIfFalse2.
@Test
public void testIfTrueIfFalse2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testIfTrueIfFalse2").method("foo: bar\n" + " |res|\n" + " res := bar ifTrue: [1] ifFalse: [2].\n" + " ^res").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
assertEquals(Integer.valueOf(1), method.invoke(fooObject, true));
assertEquals(Integer.valueOf(2), method.invoke(fooObject, false));
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class FlowControlTest method testIfTrue3.
@Test
public void testIfTrue3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Class stClass = new ClassBuilder("FooObject_testIfTrue3").method("foo: bar ^bar ifTrue: [1]").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
assertEquals(Integer.valueOf(1), method.invoke(fooObject, true));
assertEquals(null, method.invoke(fooObject, false));
}
Aggregations