JavaCompilerCore/test/bytecode/operators/AddOperatorTest.java
Enrico Schrödter 32741f41e9 - Addition für alle Typen implementiert
- Mehrere Klassen in einer jav Datei möglich
- OLTest läuft
2016-04-29 15:52:20 +02:00

109 lines
2.5 KiB
Java

package bytecode.operators;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Ignore;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class AddOperatorTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "AddOperator";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
@Test
public void testTwoIntegers() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Integer x = new Integer(1);
Class[] params = new Class[]{
x.getClass()
};
Method method = cls.getDeclaredMethod("method", params);
Integer returnValue = (Integer) method.invoke(obj, x);
assertEquals(new Integer(2), returnValue);
}
@Test
public void testTwoDoubles() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Double x = new Double(1.0);
Class[] params = new Class[]{
x.getClass()
};
Method method = cls.getDeclaredMethod("method", params);
Double returnValue = (Double) method.invoke(obj, x);
assertEquals(new Double(2.0), returnValue);
}
@Test
public void testTwoFloats() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Float x = new Float(1.0);
Class[] params = new Class[]{
x.getClass()
};
Method method = cls.getDeclaredMethod("method", params);
Float returnValue = (Float) method.invoke(obj, x);
assertEquals(new Float(2.0), returnValue);
}
@Test
public void testTwoLongs() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Long x = new Long(1);
Class[] params = new Class[]{
x.getClass()
};
Method method = cls.getDeclaredMethod("method", params);
Long returnValue = (Long) method.invoke(obj, x);
assertEquals(new Long(3), returnValue);
}
}