Search in sources :

Example 21 with ClassBuilder

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));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 22 with ClassBuilder

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));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 23 with ClassBuilder

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());
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 24 with ClassBuilder

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());
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 25 with ClassBuilder

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());
}
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