Commit 3cd59d8f authored by Eric Bruneton's avatar Eric Bruneton

Refactor the unit tests to use JUnit 4 annotations.

Also remove the dependency from AnalyzerUnitTest to ClassWriterComputeMaxUnitTest (by duplicating some code; this will be needed to use a multi-project layout).
parent 48f8bfab
......@@ -153,7 +153,6 @@
<ant antfile="${test.conform}/adviceadapter.xml" inheritRefs="true"/>
<ant antfile="${test.conform}/analyzeradapter.xml" inheritRefs="true"/>
<ant antfile="${test.conform}/classremapper.xml" inheritRefs="true"/>
<ant antfile="${test.conform}/staticinitmerger.xml" inheritRefs="true"/>
<ant antfile="${test.conform}/unit.xml" inheritRefs="true"/>
</target>
......
......@@ -27,15 +27,18 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm;
import junit.framework.TestCase;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Attribute unit tests.
*
* @author Eric Bruneton
*/
public class AttributeTest extends TestCase {
public class AttributeTest {
@Test
public void testUnknown() {
assertTrue(new Attribute("Comment").isUnknown());
}
......
......@@ -27,10 +27,15 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.junit.Test;
/**
* ClassReader unit tests.
......@@ -38,8 +43,9 @@ import junit.framework.TestCase;
* @author Eric Bruneton
* @author Eugene Kuleshov
*/
public class ClassReaderUnitTest extends TestCase implements Opcodes {
public class ClassReaderUnitTest implements Opcodes {
@Test
public void testIllegalConstructorArgument() {
try {
new ClassReader((InputStream) null);
......@@ -48,6 +54,7 @@ public class ClassReaderUnitTest extends TestCase implements Opcodes {
}
}
@Test
public void testGetItem() throws IOException {
ClassReader cr = new ClassReader(getClass().getName());
int item = cr.getItem(1);
......@@ -55,28 +62,33 @@ public class ClassReaderUnitTest extends TestCase implements Opcodes {
assertTrue(item < cr.header);
}
@Test
public void testReadByte() throws IOException {
ClassReader cr = new ClassReader(getClass().getName());
assertEquals(cr.b[0] & 0xFF, cr.readByte(0));
}
@Test
public void testGetAccess() throws Exception {
String name = getClass().getName();
assertEquals(Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, new ClassReader(name).getAccess());
}
@Test
public void testGetClassName() throws Exception {
String name = getClass().getName();
assertEquals(name.replace('.', '/'), new ClassReader(name).getClassName());
}
@Test
public void testGetSuperName() throws Exception {
assertEquals(
TestCase.class.getName().replace('.', '/'),
Object.class.getName().replace('.', '/'),
new ClassReader(getClass().getName()).getSuperName());
assertEquals(null, new ClassReader(Object.class.getName()).getSuperName());
}
@Test
public void testGetInterfaces() throws Exception {
String[] interfaces = new ClassReader(getClass().getName()).getInterfaces();
assertNotNull(interfaces);
......
......@@ -27,6 +27,9 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.lang.reflect.Field;
......@@ -38,14 +41,15 @@ import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
/**
* ClassWriter unit tests for COMPUTE_MAXS option with JSR instructions.
*
* @author Eric Bruneton
*/
public class ClassWriterComputeMaxsUnitTest extends TestCase {
public class ClassWriterComputeMaxsUnitTest {
private Field successors;
......@@ -61,8 +65,8 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
private Label start;
@Override
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
Class<?> lClass = Label.class;
Class<?> eClass = Edge.class;
try {
......@@ -281,6 +285,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testBasic() {
Label L0 = new Label();
Label L1 = new Label();
......@@ -351,6 +356,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testIfElseInFinally() {
Label L0 = new Label();
Label L1 = new Label();
......@@ -433,6 +439,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testSimpleNestedFinally() {
Label L0 = new Label();
Label L1 = new Label();
......@@ -524,6 +531,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testSubroutineWithNoRet() {
Label L0 = new Label();
Label L1 = new Label();
......@@ -589,6 +597,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* RETURN
* </pre>
*/
@Test
public void testSubroutineWithNoRet2() {
Label L0 = new Label();
Label L1 = new Label();
......@@ -629,6 +638,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testImplicitExit() {
Label L0 = new Label();
Label L1 = new Label();
......@@ -714,6 +724,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* This example is from the paper, "Subroutine Inlining and Bytecode Abstraction to Simplify
* Static and Dynamic Analysis" by Cyrille Artho and Armin Biere.
*/
@Test
public void testImplicitExitToAnotherSubroutine() {
Label T1 = new Label();
Label C1 = new Label();
......@@ -805,6 +816,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
+ "N45=N5,N10\n");
}
@Test
public void testImplicitExitToAnotherSubroutine2() {
Label L1 = new Label();
Label L2 = new Label();
......@@ -840,6 +852,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
*
* <p>This would not normally be produced by a java compiler.
*/
@Test
public void testInterleavedCode() {
Label L1 = new Label();
Label L2 = new Label();
......@@ -907,6 +920,7 @@ public class ClassWriterComputeMaxsUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testImplicitExitInTryCatch() {
Label T1 = new Label();
Label C1 = new Label();
......
......@@ -27,15 +27,18 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm;
import junit.framework.TestCase;
import static org.junit.Assert.fail;
import org.junit.Test;
/**
* ClassWriter unit tests.
*
* @author Eric Bruneton
*/
public class ClassWriterUnitTest extends TestCase {
public class ClassWriterUnitTest {
@Test
public void testNewConst() {
ClassWriter cw = new ClassWriter(0);
cw.newConst(new Byte((byte) 0));
......@@ -46,6 +49,7 @@ public class ClassWriterUnitTest extends TestCase {
cw.newMethod("A", "m", "()V", false);
}
@Test
public void testIllegalNewConstArgument() {
ClassWriter cw = new ClassWriter(0);
try {
......@@ -55,6 +59,7 @@ public class ClassWriterUnitTest extends TestCase {
}
}
@Test
public void testIllegalGetCommonSuperClassArguments() {
ClassWriter cw = new ClassWriter(0);
try {
......
......@@ -25,17 +25,17 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.commons;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.Test;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
......@@ -54,8 +54,9 @@ import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
import org.objectweb.asm.tree.TypeInsnNode;
public class ClassRemapperUnitTest extends TestCase implements Opcodes {
public class ClassRemapperUnitTest implements Opcodes {
@Test
public void testClassRemapper() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("Boo", "B1");
......
......@@ -27,8 +27,11 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.commons;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
......@@ -42,15 +45,14 @@ import org.objectweb.asm.util.Textifier;
*
* @author Eugene Kuleshov, Niko Matsakis, Eric Bruneton
*/
public class JSRInlinerAdapterUnitTest extends TestCase {
public class JSRInlinerAdapterUnitTest {
private JSRInlinerAdapter jsr;
private MethodNode exp;
private MethodVisitor current;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
jsr =
new JSRInlinerAdapter(Opcodes.ASM5, null, 0, "m", "()V", null, null) {
@Override
......@@ -193,6 +195,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testBasic() {
{
Label L0 = new Label();
......@@ -290,7 +293,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 4);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -310,6 +313,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testIfElseInFinally() {
{
Label L0 = new Label();
......@@ -431,7 +435,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 4);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -452,6 +456,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testSimpleNestedFinally() {
{
Label L0 = new Label();
......@@ -613,7 +618,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(2, 6);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -637,6 +642,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testSubroutineWithNoRet() {
{
Label L0 = new Label();
......@@ -739,7 +745,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 4);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -752,6 +758,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* RETURN
* </pre>
*/
@Test
public void testSubroutineWithNoRet2() {
{
Label L0 = new Label();
......@@ -783,7 +790,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 1);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -808,6 +815,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testImplicitExit() {
{
Label L0 = new Label();
......@@ -923,7 +931,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 4);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -951,6 +959,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* This example is from the paper, "Subroutine Inlining and Bytecode Abstraction to Simplify
* Static and Dynamic Analysis" by Cyrille Artho and Armin Biere.
*/
@Test
public void testImplicitExitToAnotherSubroutine() {
{
Label T1 = new Label();
......@@ -1185,7 +1194,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 6);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -1195,6 +1204,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
*
* <p>I don't believe this can be represented in Java.
*/
@Test
public void testCommonCodeWhichMustBeDuplicated() {
{
Label L1 = new Label();
......@@ -1294,7 +1304,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 2);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -1303,6 +1313,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
*
* <p>This would not normally be produced by a java compiler.
*/
@Test
public void testInterleavedCode() {
{
Label L1 = new Label();
......@@ -1393,7 +1404,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 3);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -1424,6 +1435,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* }
* </pre>
*/
@Test
public void testImplicitExitInTryCatch() {
{
Label T1 = new Label();
......@@ -1705,7 +1717,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 6);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
/**
......@@ -1723,6 +1735,7 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
* LV "a" from 1 to 6
* </pre>
*/
@Test
public void testBasicLineNumberAndLocalVars() {
{
Label LM1 = new Label();
......@@ -1837,10 +1850,10 @@ public class JSRInlinerAdapterUnitTest extends TestCase {
END(1, 4);
}
assertEquals(exp, jsr);
assertMethodEquals(exp, jsr);
}
public void assertEquals(final MethodNode exp, final MethodNode actual) {
public void assertMethodEquals(final MethodNode exp, final MethodNode actual) {
String textexp = getText(exp);
String textact = getText(actual);
System.err.println("Expected=" + textexp);
......
......@@ -27,11 +27,12 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.commons;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.Serializable;
import junit.framework.TestCase;
import org.junit.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
......@@ -64,7 +65,7 @@ enum SerialVersionEnum {
* @author Alexandre Vasseur
* @author Eric Bruneton
*/
public class SerialVersionUIDAdderUnitTest extends TestCase implements Serializable {
public class SerialVersionUIDAdderUnitTest implements Serializable {
static {
System.setIn(System.in);
......@@ -84,21 +85,25 @@ public class SerialVersionUIDAdderUnitTest extends TestCase implements Serializa
return svuid[0];
}
@Test
public void testClass() throws Throwable {
long UID = computeSerialVersionUID(SerialVersionClass.class.getName());
assertEquals(4737241769335595888L, UID);
}
@Test
public void testInterface() throws Throwable {
long UID = computeSerialVersionUID(SerialVersionInterface.class.getName());
assertEquals(-1271936742430161320L, UID);
}
@Test
public void testEmptyInterface() throws Throwable {
long UID = computeSerialVersionUID(SerialVersionEmptyInterface.class.getName());
assertEquals(8675733916152748550L, UID);
}
@Test
public void testEnum() throws Throwable {
long UID = computeSerialVersionUID(SerialVersionEnum.class.getName());
assertEquals(0L, UID);
......
......@@ -28,22 +28,26 @@
package org.objectweb.asm.commons;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.Test;
public class SignatureRemapperUnitTest extends TestCase {
public class SignatureRemapperUnitTest {
public static void testRemappingParentOnlyNestedClassExtends() {
@Test
public void testRemappingParentOnlyNestedClassExtends() {
Remapper remapper = new SimpleRemapper(Collections.singletonMap("Outer", "RenamedOuter"));
assertEquals(
"LRenamedOuter<Ljava/lang/Object;>.Inner;",
remapper.mapSignature("LOuter<Ljava/lang/Object;>.Inner;", false));
}
public static void testRemappingChildOnlyNestedClassExtends() {
@Test
public void testRemappingChildOnlyNestedClassExtends() {
Remapper remapper =
new SimpleRemapper(Collections.singletonMap("Outer$Inner", "Outer$RenamedInner"));
assertEquals(
......@@ -51,7 +55,8 @@ public class SignatureRemapperUnitTest extends TestCase {
remapper.mapSignature("LOuter<Ljava/lang/Object;>.Inner;", false));
}
public static void testRemappingBothParentAndChildNestedClassExtends() {
@Test
public void testRemappingBothParentAndChildNestedClassExtends() {
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("Outer", "RenamedOuter");
mapping.put("Outer$Inner", "RenamedOuter$RenamedInner");
......
......@@ -27,8 +27,9 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.commons;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
......@@ -39,10 +40,11 @@ import org.objectweb.asm.Opcodes;
*
* @author Eric Bruneton
*/
public class StaticInitMergerTest extends TestCase implements Opcodes {
public class StaticInitMergerTest implements Opcodes {
private static final TestClassLoader LOADER = new TestClassLoader();
@Test
public void test() throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = new StaticInitMerger("$clinit$", cw);
......
......@@ -27,8 +27,10 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package org.objectweb.asm.tree;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
......@@ -38,19 +40,22 @@ import org.objectweb.asm.Opcodes;
*
* @author Eric Bruneton
*/
public class ClassNodeUnitTest extends TestCase implements Opcodes {
public class ClassNodeUnitTest implements Opcodes {
@Test
public void testFrameNode() {
FrameNode fn = new FrameNode(F_SAME, 0, null, 0, null);
assertEquals(AbstractInsnNode.FRAME, fn.getType());
}
@Test
public void testInsnNode() {
InsnNode in = new InsnNode(NOP);
assertEquals(in.getOpcode(), NOP);
assertEquals(AbstractInsnNode.INSN, in.getType());
}
@Test
public void testIntInsnNode() {
IntInsnNode iin = new IntInsnNode(BIPUSH, 0);
iin.setOpcode(SIPUSH);
......@@ -58,6 +63,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.INT_INSN, iin.getType());
}
@Test
public void testVarInsnNode() {
VarInsnNode vn = new VarInsnNode(ALOAD, 0);
vn.setOpcode(ASTORE);
......@@ -65,6 +71,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.VAR_INSN, vn.getType());
}
@Test
public void testTypeInsnNode() {
TypeInsnNode tin = new TypeInsnNode(NEW, "java/lang/Object");
tin.setOpcode(CHECKCAST);
......@@ -72,6 +79,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.TYPE_INSN, tin.getType());
}
@Test
public void testFieldInsnNode() {
FieldInsnNode fn = new FieldInsnNode(GETSTATIC, "owner", "name", "I");
fn.setOpcode(PUTSTATIC);
......@@ -79,6 +87,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.FIELD_INSN, fn.getType());
}
@Test
public void testMethodInsnNode() {
MethodInsnNode mn = new MethodInsnNode(INVOKESTATIC, "owner", "name", "I", false);
mn.setOpcode(INVOKESPECIAL);
......@@ -86,6 +95,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.METHOD_INSN, mn.getType());
}
@Test
public void testInvokeDynamicInsnNode() {
Handle bsm = new Handle(Opcodes.H_INVOKESTATIC, "owner", "name", "()V", false);
InvokeDynamicInsnNode mn = new InvokeDynamicInsnNode("name", "()V", bsm, new Object[0]);
......@@ -94,6 +104,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.INVOKE_DYNAMIC_INSN, mn.getType());
}
@Test
public void testJumpInsnNode() {
JumpInsnNode jn = new JumpInsnNode(GOTO, new LabelNode());
jn.setOpcode(IFEQ);
......@@ -101,6 +112,7 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
assertEquals(AbstractInsnNode.JUMP_INSN, jn.getType());
}
@Test
public void testLabelNode() {
LabelNode ln = new LabelNode();
assertEquals(AbstractInsnNode.LABEL, ln.getType());
......@@ -110,31 +122,37 @@ public class ClassNodeUnitTest extends TestCase implements Opcodes {
ln.getLabel().info = new Object();
}
@Test
public void testIincInsnNode() {
IincInsnNode iincn = new IincInsnNode(1, 1);
assertEquals(AbstractInsnNode.IINC_INSN, iincn.getType());
}
@Test
public void testLdcInsnNode() {
LdcInsnNode ldcn = new LdcInsnNode("s");
assertEquals(AbstractInsnNode.LDC_INSN, ldcn.getType());
}
@Test
public void testLookupSwitchInsnNode() {
LookupSwitchInsnNode lsn = new LookupSwitchInsnNode(null, null, null);