package com.ajlopez.ajtalk.language;

import static org.junit.Assert.*;

import org.junit.Test;

import com.ajlopez.ajtalk.Machine;

public class BaseClassTests {

	@Test
	public void createClass() {
		BaseClass klass = new BaseClass(null);
		assertEquals(0, klass.getObjectSize());
		assertEquals(-1, klass.getVariableOffset("a"));
	}

	@Test
	public void createClassWithInstanceVariables() {
		BaseClass klass = new BaseClass(null, new String[] { "x", "y" });
		assertEquals(2, klass.getObjectSize());
		assertEquals(-1, klass.getVariableOffset("z"));
		assertEquals(0, klass.getVariableOffset("x"));
		assertEquals(1, klass.getVariableOffset("y"));
	}

	@Test
	public void createSubclassWithInstanceVariables() {
		BaseClass superklass = new BaseClass(null, new String[] { "x", "y" });
		BaseClass klass = new BaseClass(superklass, new String[] { "z" });
		assertEquals(3, klass.getObjectSize());
		assertEquals(0, klass.getVariableOffset("x"));
		assertEquals(1, klass.getVariableOffset("y"));
		assertEquals(2, klass.getVariableOffset("z"));
	}

	@Test
	public void defineMethod() {
		BaseClass klass = new BaseClass(null);
		IMethod method = new MyMethod();
		klass.defineMethod("mymethod", method);
		assertEquals(method, klass.getMethod("mymethod"));
	}

	@Test
	public void createInstance() {
		BaseClass klass = new BaseClass(null, new String[] { "x", "y" });
		IObject object = klass.createInstance();
		
		assertNotNull(object);
		assertNull(object.getVariable(0));
		assertNull(object.getVariable(1));
		assertEquals(klass, object.getBehavior());
	}

	private class MyMethod implements IMethod {
		@Override
		public Object execute(Object self, Object[] arguments, Machine machine) {
			// TODO Auto-generated method stub
			return null;
		}	
	}
}

@@ -92,24 +92,71 @@
 it.Test;%0D%0A%0D%0A
+import com.ajlopez.ajtalk.ExecutionException;%0D%0A
 import com.a
@@ -1659,16 +1659,362 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@Test%0D%0A%09public void invokeInstanceMethod() throws ExecutionException %7B%0D%0A%09%09BaseClass klass = new BaseClass(null, new String%5B%5D %7B %22x%22, %22y%22 %7D);%0D%0A%09%09IMethod method = new MyMethod();%0D%0A%09%09klass.defineMethod(%22mymethod%22, method);%0D%0A%09%09IObject object = klass.createInstance();%0D%0A%09%09%0D%0A%09%09assertEquals(1, object.send(%22mymethod%22, new Object%5B%5D %7B 1 %7D, null));%0D%0A%09%7D%0D%0A%0D%0A
 %09private
@@ -2051,16 +2051,16 @@
 thod %7B%0D%0A
-
 %09%09@Overr
@@ -2148,58 +2148,27 @@
 %0A%09%09%09
-// TODO Auto-generated method stub%0D%0A%09%09%09return null
+return arguments%5B0%5D
 ;%0D%0A%09

Test create instance and invoke method