JavaCompilerCore/test/bytecode/NewClassTest.java

62 lines
1.5 KiB
Java
Raw Normal View History

package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class NewClassTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "NewClass";
}
@Test
public void testInit() throws Exception {
ClassLoader cl = getClassLoader();
cl.loadClass(testName).newInstance();
}
@Test
public void testMethod() throws Exception {
try{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
File file = new File(rootDirectory);
URL url = file.toURL();
URL[] urls = new URL[]{url};
Class[] params = new Class[0];
Method method = cls.getDeclaredMethod("method", params);
Object returnValue = method.invoke(obj);
assertTrue(returnValue instanceof String);
}catch(Exception e){
throw new RuntimeException(e);
}
}
}