Search in sources :

Example 16 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class InheritanceTest method testSuperSend2.

@Test
public void testSuperSend2() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class classA = new ClassBuilder("ClassA_testSuperSend2").method("sendSuper: bar ^bar + 1").build();
    Class classB = new ClassBuilder("ClassB_testSuperSend2").superclassName("ClassA_testSuperSend2").build();
    Class classC = new ClassBuilder("ClassC_testSuperSend2").superclassName("ClassB_testSuperSend2").method("sendSuper: bar ^(super sendSuper: bar) + 2").build();
    Object fooObject = classC.newInstance();
    Method method = fooObject.getClass().getMethod("sendSuper_", Object.class);
    Object result = method.invoke(fooObject, 4);
    assertEquals(Integer.valueOf(7), result);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 17 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class InstanceCreationTest method testCreateInstance.

@Test
public void testCreateInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class classA = new ClassBuilder("ClassA").method("foo ^3").build();
    Class classB = new ClassBuilder("ClassB").method("newClassA ^ClassA new").build();
    Object classBObject = classB.newInstance();
    Method method = classBObject.getClass().getMethod("newClassA");
    Object classAObj = method.invoke(classBObject);
    Method fooMethod = classAObj.getClass().getMethod("foo");
    Object result = fooMethod.invoke(classAObj);
    assertEquals(Integer.valueOf(3), result);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 18 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class InstanceCreationTest method testSendClassMethod.

@Test
public void testSendClassMethod() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class classA = new ClassBuilder("ClassA_testSendClassMethod").classMethod("foo ^3").build();
    Class classB = new ClassBuilder("ClassB_testSendClassMethod").method("bar ^ClassA_testSendClassMethod foo").build();
    Object classBObject = classB.newInstance();
    Method method = classBObject.getClass().getMethod("bar");
    Object result = method.invoke(classBObject);
    assertEquals(Integer.valueOf(3), result);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 19 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class BlockTest method testReadOuterTemp1.

@Test
public void testReadOuterTemp1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testReadOuterTemp1").method("foo: bar\n" + "| a ar aw |\n" + "a := 0.\n" + "ar := [a + 7].\n" + "a := bar.	\n" + "^ar value").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(9), method.invoke(fooObject, 2));
    assertEquals(Integer.valueOf(8), method.invoke(fooObject, 1));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 20 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class BlockTest method testCleanBlock.

@Test
public void testCleanBlock() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject").method("foo: bar\n" + "	| block |\n" + "	block := [:a | a + 4].\n" + "	^block value: bar").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(7), method.invoke(fooObject, 3));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)69 ClassBuilder (st.gravel.support.compiler.testtools.ClassBuilder)69 Method (java.lang.reflect.Method)65 BigInteger (java.math.BigInteger)4 Date (java.util.Date)1