/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cope.instrument;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import com.exedio.cope.instrument.testmodel.Standard;


public class GeneratorTest extends InstrumentorTest
{
	public static final int PUBLIC = Modifier.PUBLIC;
	public static final int FINAL = Modifier.FINAL;
	
	public void testStandard()
	{
		final Class standard = Standard.class;
		assertMethod(standard, "getDefaultString", String.class, PUBLIC|FINAL);
		assertMethod(standard, "setDefaultString", new Class[]{String.class}, PUBLIC|FINAL);
	}
	
	void assertMethod(final Class javaClass, final String name, final Class returnType, final int modifiers)
	{
		assertMethod(javaClass, name, null, returnType, modifiers);
	}
	
	void assertMethod(final Class javaClass, final String name, final Class[] parameterTypes, final int modifiers)
	{
		assertMethod(javaClass, name, parameterTypes, Void.TYPE, modifiers);
	}

	void assertMethod(
			final Class javaClass, final String name, final Class[] parameterTypes,
			final Class returnType, final int modifiers)
	{
		final Method method;
		try
		{
			method = javaClass.getDeclaredMethod(name, parameterTypes);
		}
		catch(NoSuchMethodException e)
		{
			throw new AssertionError(e);
		}
		assertEquals(returnType, method.getReturnType());
		assertEquals(modifiers, method.getModifiers());
	}

}

@@ -834,16 +834,48 @@
 ument;%0A%0A
+import java.lang.reflect.Field;%0A
 import j
@@ -989,16 +989,49 @@
 andard;%0A
+import com.exedio.cope.lib.Type;%0A
 %0A%0Apublic
@@ -1129,16 +1129,67 @@
 PUBLIC;%0A
+%09public static final int STATIC = Modifier.STATIC;%0A
 %09public 
@@ -1464,20 +1464,451 @@
 FINAL);%0A
+%09%09assertField(standard, %22TYPE%22, Type.class, PUBLIC%7CSTATIC%7CFINAL);%0A%09%7D%0A%09%0A%09void assertField(%0A%09%09%09final Class javaClass, final String name,%0A%09%09%09final Class returnType, final int modifiers)%0A%09%7B%0A%09%09final Field field;%0A%09%09try%0A%09%09%7B%0A%09%09%09field = javaClass.getDeclaredField(name);%0A%09%09%7D%0A%09%09catch(NoSuchFieldException e)%0A%09%09%7B%0A%09%09%09throw new AssertionError(e);%0A%09%09%7D%0A%09%09assertEquals(returnType, field.getType());%0A%09%09assertEquals(modifiers, field.getModifiers());%0A
 %09%7D%0A
-%09
 %0A%09void a

test for TYPE field