Commit 6122072c authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Use more specific assertions about expected exceptions. Also use stricter...

Use more specific assertions about expected exceptions. Also use stricter arrange-act-assert patterns in some places.
parent f4858361
Pipeline #4282 passed with stage
in 11 minutes and 53 seconds
......@@ -88,6 +88,12 @@ public abstract class AsmTest {
*/
public static final String ALL_CLASSES_AND_LATEST_API = "allClassesAndLatestApi";
/**
* The expected pattern (i.e. regular expression) that ASM's UnsupportedOperationException
* messages are supposed to match.
*/
public static final String UNSUPPORTED_OPERATION_MESSAGE_PATTERN = ".* requires ASM[567]";
/**
* A precompiled class, hand-crafted to contain some set of class file structures. These classes
* are not compiled as part of the build. Instead, they have been compiled beforehand, with the
......
......@@ -104,20 +104,44 @@ public class ClassFileTest extends AsmTest {
}
@Test
public void testHashcodeAndToString_validClass() {
public void testHashcode_validClass() {
PrecompiledClass precompiledClass = PrecompiledClass.JDK3_ALL_INSTRUCTIONS;
ClassFile classFile = new ClassFile(precompiledClass.getBytes());
assertNotEquals(0, classFile.hashCode());
assertTrue(classFile.toString().contains(precompiledClass.getInternalName()));
int hashCode = classFile.hashCode();
assertNotEquals(0, hashCode);
}
@Test
public void testHashcode_invalidClass() {
InvalidClass invalidClass = InvalidClass.INVALID_CLASS_VERSION;
ClassFile classFile = new ClassFile(invalidClass.getBytes());
Executable hashCode = () -> classFile.hashCode();
Exception exception = assertThrows(ClassFormatException.class, hashCode);
assertEquals("Unsupported class version", exception.getMessage());
}
@Test
public void testHashcodeAndToString_invalidClass() {
public void testToString_validClass() {
PrecompiledClass precompiledClass = PrecompiledClass.JDK3_ALL_INSTRUCTIONS;
ClassFile classFile = new ClassFile(precompiledClass.getBytes());
String classString = classFile.toString();
assertTrue(classString.contains(precompiledClass.getInternalName()));
}
@Test
public void testToString_invalidClass() {
InvalidClass invalidClass = InvalidClass.INVALID_CLASS_VERSION;
ClassFile classFile = new ClassFile(invalidClass.getBytes());
assertThrows(ClassFormatException.class, () -> classFile.hashCode());
assertThrows(ClassFormatException.class, () -> classFile.toString());
Executable toString = () -> classFile.toString();
Exception exception = assertThrows(ClassFormatException.class, toString);
assertEquals("Unsupported class version", exception.getMessage());
}
}
......@@ -66,7 +66,7 @@ public abstract class AnnotationVisitor {
*/
public AnnotationVisitor(final int api, final AnnotationVisitor annotationVisitor) {
if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Unsupported api " + api);
}
this.api = api;
this.av = annotationVisitor;
......
......@@ -67,7 +67,7 @@ public abstract class ClassVisitor {
*/
public ClassVisitor(final int api, final ClassVisitor classVisitor) {
if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Unsupported api " + api);
}
this.api = api;
this.cv = classVisitor;
......
......@@ -65,7 +65,7 @@ public abstract class FieldVisitor {
*/
public FieldVisitor(final int api, final FieldVisitor fieldVisitor) {
if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Unsupported api " + api);
}
this.api = api;
this.fv = fieldVisitor;
......
......@@ -79,7 +79,7 @@ public abstract class MethodVisitor {
*/
public MethodVisitor(final int api, final MethodVisitor methodVisitor) {
if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Unsupported api " + api);
}
this.api = api;
this.mv = methodVisitor;
......@@ -424,7 +424,7 @@ public abstract class MethodVisitor {
final boolean isInterface) {
if (api < Opcodes.ASM5) {
if (isInterface != (opcode == Opcodes.INVOKEINTERFACE)) {
throw new IllegalArgumentException("INVOKESPECIAL/STATIC on interfaces requires ASM5");
throw new UnsupportedOperationException("INVOKESPECIAL/STATIC on interfaces requires ASM5");
}
visitMethodInsn(opcode, owner, name, descriptor);
return;
......
......@@ -65,7 +65,7 @@ public abstract class ModuleVisitor {
*/
public ModuleVisitor(final int api, final ModuleVisitor moduleVisitor) {
if (api != Opcodes.ASM7 && api != Opcodes.ASM6) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Unsupported api " + api);
}
this.api = api;
this.mv = moduleVisitor;
......
......@@ -72,8 +72,8 @@ public abstract class SignatureVisitor {
* Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
*/
public SignatureVisitor(final int api) {
if (api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4 && api != Opcodes.ASM7) {
throw new IllegalArgumentException();
if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
throw new IllegalArgumentException("Unsupported api " + api);
}
this.api = api;
}
......
......@@ -30,6 +30,7 @@ package org.objectweb.asm;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
......@@ -46,10 +47,18 @@ import org.objectweb.asm.test.ClassFile;
public class AnnotationVisitorTest extends AsmTest {
@Test
public void testConstructor() {
assertDoesNotThrow(() -> new AnnotationVisitor(Opcodes.ASM4) {});
assertThrows(IllegalArgumentException.class, () -> new AnnotationVisitor(0) {});
assertThrows(IllegalArgumentException.class, () -> new AnnotationVisitor(Integer.MAX_VALUE) {});
public void testConstructor_validApi() {
Executable constructor = () -> new AnnotationVisitor(Opcodes.ASM4) {};
assertDoesNotThrow(constructor);
}
@Test
public void testConstructor_invalidApi() {
Executable constructor = () -> new AnnotationVisitor(0) {};
Exception exception = assertThrows(IllegalArgumentException.class, constructor);
assertEquals("Unsupported api 0", exception.getMessage());
}
/**
......@@ -72,8 +81,12 @@ public class AnnotationVisitorTest extends AsmTest {
Executable deleteAnnotations = () -> classReader.accept(deleteAnnotationsAdapter, 0);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, removeAnnotations);
assertThrows(RuntimeException.class, deleteAnnotations);
Exception removeException =
assertThrows(UnsupportedOperationException.class, removeAnnotations);
Exception deleteException =
assertThrows(UnsupportedOperationException.class, deleteAnnotations);
assertTrue(removeException.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
assertTrue(deleteException.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(removeAnnotations);
assertDoesNotThrow(deleteAnnotations);
......
......@@ -136,8 +136,8 @@ public class ByteVectorTest {
Executable putUtf8 = () -> byteVector.putUTF8(new String(charBuffer));
if (size > 65535) {
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, putUtf8);
assertEquals("UTF8 string too large", thrown.getMessage());
Exception exception = assertThrows(IllegalArgumentException.class, putUtf8);
assertEquals("UTF8 string too large", exception.getMessage());
} else {
assertDoesNotThrow(putUtf8);
}
......@@ -161,8 +161,8 @@ public class ByteVectorTest {
Executable putUtf8 = () -> byteVector.putUTF8(new String(charBuffer));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, putUtf8);
assertEquals("UTF8 string too large", thrown.getMessage());
Exception exception = assertThrows(IllegalArgumentException.class, putUtf8);
assertEquals("UTF8 string too large", exception.getMessage());
}
@Test
......
......@@ -228,7 +228,10 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
@Test
public void testStreamConstructor_nullStream() {
assertThrows(IOException.class, () -> new ClassReader((InputStream) null));
Executable constructor = () -> new ClassReader((InputStream) null);
Exception exception = assertThrows(IOException.class, constructor);
assertEquals("Class not found", exception.getMessage());
}
/** Tests {@link ClassReader#ClassReader(java.io.InputStream)} with an empty stream. */
......@@ -251,7 +254,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
Executable streamConstructor = () -> new ClassReader(inputStream);
assertTimeoutPreemptively(
Duration.ofMillis(100), () -> assertThrows(RuntimeException.class, streamConstructor));
Duration.ofMillis(100),
() -> assertThrows(ArrayIndexOutOfBoundsException.class, streamConstructor));
}
/** Tests the ClassReader accept method with an empty visitor. */
......@@ -265,7 +269,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
Executable accept = () -> classReader.accept(classVisitor, 0);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......@@ -282,7 +287,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
Executable accept = () -> classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......@@ -299,7 +305,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
Executable accept = () -> classReader.accept(classVisitor, ClassReader.EXPAND_FRAMES);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......@@ -316,7 +323,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
Executable accept = () -> classReader.accept(classVisitor, ClassReader.SKIP_FRAMES);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......@@ -338,7 +346,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
if (classParameter.isMoreRecentThan(apiParameter)
&& classParameter != PrecompiledClass.JDK8_ARTIFICIAL_STRUCTURES
&& classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......@@ -408,7 +417,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
if (invalidClass == InvalidClass.INVALID_CONSTANT_POOL_INDEX
|| invalidClass == InvalidClass.INVALID_CONSTANT_POOL_REFERENCE
|| invalidClass == InvalidClass.INVALID_BYTECODE_OFFSET) {
assertThrows(ArrayIndexOutOfBoundsException.class, accept);
Exception exception = assertThrows(ArrayIndexOutOfBoundsException.class, accept);
assertTrue(Integer.valueOf(exception.getMessage()) > 0);
} else {
assertThrows(IllegalArgumentException.class, accept);
}
......@@ -432,7 +442,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
if ((hasNestHostOrMembers && apiParameter.value() < ASM7)
|| (hasModules && apiParameter.value() < ASM6)
|| (hasTypeAnnotations && apiParameter.value() < ASM5)) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......@@ -466,6 +477,7 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
@Override
public ModuleVisitor visitModule(
final String name, final int access, final String version) {
super.visitModule(name, access, version);
return new ModuleVisitor(api) {};
}
......@@ -493,7 +505,8 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
Executable accept = () -> classReader.accept(classVisitor, 0);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(UnsupportedOperationException.class, accept);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(accept);
}
......
......@@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -53,10 +54,18 @@ import org.objectweb.asm.test.ClassFile;
public class ClassVisitorTest extends AsmTest {
@Test
public void testConstructor() {
assertDoesNotThrow(() -> new ClassVisitor(Opcodes.ASM4) {});
assertThrows(IllegalArgumentException.class, () -> new ClassVisitor(0) {});
assertThrows(IllegalArgumentException.class, () -> new ClassVisitor(Integer.MAX_VALUE) {});
public void testConstructor_validApi() {
Executable constructor = () -> new ClassVisitor(Opcodes.ASM4) {};
assertDoesNotThrow(constructor);
}
@Test
public void testConstructor_invalidApi() {
Executable constructor = () -> new ClassVisitor(0) {};
Exception exception = assertThrows(IllegalArgumentException.class, constructor);
assertEquals("Unsupported api 0", exception.getMessage());
}
/**
......@@ -76,7 +85,8 @@ public class ClassVisitorTest extends AsmTest {
Executable transform = () -> classReader.accept(classAdapter, attributes(), 0);
if (classParameter.isMoreRecentThan(apiParameter)) {
assertThrows(RuntimeException.class, transform);
Exception exception = assertThrows(UnsupportedOperationException.class, transform);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
} else {
assertDoesNotThrow(transform);
assertEquals(new ClassFile(classFile), new ClassFile(classWriter.toByteArray()));
......
......@@ -131,7 +131,10 @@ public class ClassWriterTest extends AsmTest {
public void testNewConst_illegalArgument() {
ClassWriter classWriter = newEmptyClassWriter();
assertThrows(IllegalArgumentException.class, () -> classWriter.newConst(new Object()));
Executable newConst = () -> classWriter.newConst(new Object());
Exception exception = assertThrows(IllegalArgumentException.class, newConst);
assertTrue(exception.getMessage().matches("value java\\.lang\\.Object@.*"));
}
@Test
......@@ -275,10 +278,10 @@ public class ClassWriterTest extends AsmTest {
Executable toByteArray = () -> classWriter.toByteArray();
if (constantPoolCount > 65535) {
ClassTooLargeException thrown = assertThrows(ClassTooLargeException.class, toByteArray);
assertEquals("C", thrown.getClassName());
assertEquals(constantPoolCount, thrown.getConstantPoolCount());
assertEquals("Class too large: C", thrown.getMessage());
ClassTooLargeException exception = assertThrows(ClassTooLargeException.class, toByteArray);
assertEquals("C", exception.getClassName());
assertEquals(constantPoolCount, exception.getConstantPoolCount());
assertEquals("Class too large: C", exception.getMessage());
} else {
assertDoesNotThrow(toByteArray);
}
......@@ -303,12 +306,12 @@ public class ClassWriterTest extends AsmTest {
Executable toByteArray = () -> classWriter.toByteArray();
if (methodCodeSize > 65535) {
MethodTooLargeException thrown = assertThrows(MethodTooLargeException.class, toByteArray);
assertEquals(methodName, thrown.getMethodName());
assertEquals("C", thrown.getClassName());
assertEquals(descriptor, thrown.getDescriptor());
assertEquals(methodCodeSize, thrown.getCodeSize());
assertEquals("Method too large: C.m ()V", thrown.getMessage());
MethodTooLargeException exception = assertThrows(MethodTooLargeException.class, toByteArray);
assertEquals(methodName, exception.getMethodName());
assertEquals("C", exception.getClassName());
assertEquals(descriptor, exception.getDescriptor());
assertEquals(methodCodeSize, exception.getCodeSize());
assertEquals("Method too large: C.m ()V", exception.getMessage());
} else {
assertDoesNotThrow(toByteArray);
}
......@@ -434,12 +437,16 @@ public class ClassWriterTest extends AsmTest {
"java/lang/Throwable",
classWriter.getCommonSuperClass(
"java/lang/IndexOutOfBoundsException", "java/lang/AssertionError"));
assertThrows(
TypeNotPresentException.class,
() -> classWriter.getCommonSuperClass("-", "java/lang/Object"));
assertThrows(
TypeNotPresentException.class,
() -> classWriter.getCommonSuperClass("java/lang/Object", "-"));
Exception exception =
assertThrows(
TypeNotPresentException.class,
() -> classWriter.getCommonSuperClass("-", "java/lang/Object"));
assertEquals("Type - not present", exception.getMessage());
exception =
assertThrows(
TypeNotPresentException.class,
() -> classWriter.getCommonSuperClass("java/lang/Object", "-"));
assertEquals("Type - not present", exception.getMessage());
}
/** Tests that a ClassReader -> ClassWriter transform leaves classes unchanged. */
......@@ -594,7 +601,8 @@ public class ClassWriterTest extends AsmTest {
Executable accept = () -> classReader.accept(classWriter, attributes(), 0);
assertThrows(RuntimeException.class, accept);
Exception exception = assertThrows(IllegalArgumentException.class, accept);
assertEquals("JSR/RET are not supported with computeFrames option", exception.getMessage());
}
/**
......
......@@ -28,9 +28,11 @@
package org.objectweb.asm;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
/**
* Unit tests for {@link FieldVisitor}.
......@@ -40,9 +42,17 @@ import org.junit.jupiter.api.Test;
public class FieldVisitorTest {
@Test
public void testConstructor() {
assertDoesNotThrow(() -> new FieldVisitor(Opcodes.ASM4) {});
assertThrows(IllegalArgumentException.class, () -> new FieldVisitor(0) {});
assertThrows(IllegalArgumentException.class, () -> new FieldVisitor(Integer.MAX_VALUE) {});
public void testConstructor_validApi() {
Executable constructor = () -> new FieldVisitor(Opcodes.ASM4) {};
assertDoesNotThrow(constructor);
}
@Test
public void testConstructor_invalidApi() {
Executable constructor = () -> new FieldVisitor(0) {};
Exception exception = assertThrows(IllegalArgumentException.class, constructor);
assertEquals("Unsupported api 0", exception.getMessage());
}
}
......@@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
/**
* Unit tests for {@link Label}.
......@@ -56,12 +57,17 @@ public class LabelTest {
/** Tests that {@link Label#getOffset()} throws an exception before the label is visited. */
@Test
public void testGetOffset_illegalState() {
assertThrows(RuntimeException.class, () -> new Label().getOffset());
Executable getOffset = () -> new Label().getOffset();
Exception exception = assertThrows(IllegalStateException.class, getOffset);
assertEquals("Label offset position has not been resolved yet", exception.getMessage());
}
/** Tests that {@link Label#toString()} returns strings starting with "L". */
@Test
public void testToString() {
assertEquals('L', new Label().toString().charAt(0));
String string = new Label().toString();
assertEquals('L', string.charAt(0));
}
}
......@@ -30,74 +30,109 @@ package org.objectweb.asm;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.objectweb.asm.test.AsmTest;
/**
* Unit tests for {@link MethodVisitor}.
*
* @author Eric Bruneton
*/
public class MethodVisitorTest {
public class MethodVisitorTest extends AsmTest {
@Test
public void testConstructor() {
assertDoesNotThrow(() -> new MethodVisitor(Opcodes.ASM4) {});
assertThrows(IllegalArgumentException.class, () -> new MethodVisitor(0) {});
assertThrows(IllegalArgumentException.class, () -> new MethodVisitor(Integer.MAX_VALUE) {});
public void testConstructor_validApi() {
Executable constructor = () -> new MethodVisitor(Opcodes.ASM4) {};
assertDoesNotThrow(constructor);
}
@Test
public void testConstructor_invalidApi() {
Executable constructor = () -> new MethodVisitor(0) {};
Exception exception = assertThrows(IllegalArgumentException.class, constructor);
assertEquals("Unsupported api 0", exception.getMessage());
}
@Test
public void testVisitParameter_asm4Visitor() {
MethodVisitor methodVisitor = new MethodVisitor(Opcodes.ASM4, null) {};
assertThrows(UnsupportedOperationException.class, () -> methodVisitor.visitParameter(null, 0));
Executable visitParameter = () -> methodVisitor.visitParameter(null, 0);
Exception exception = assertThrows(UnsupportedOperationException.class, visitParameter);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
}
@Test
public void testVisitTypeAnnotation_asm4Visitor() {
MethodVisitor methodVisitor = new MethodVisitor(Opcodes.ASM4, null) {};
assertThrows(
UnsupportedOperationException.class,
() -> methodVisitor.visitTypeAnnotation(0, null, null, false));
Executable visitTypeAnnotation = () -> methodVisitor.visitTypeAnnotation(0, null, null, false);
Exception exception = assertThrows(UnsupportedOperationException.class, visitTypeAnnotation);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
}
@Test
public void testVisitInvokeDynamicInsn_asm4Visitor() {
MethodVisitor methodVisitor = new MethodVisitor(Opcodes.ASM4, null) {};
assertThrows(
UnsupportedOperationException.class,
() -> methodVisitor.visitInvokeDynamicInsn(null, null, null));
Executable visitInvokeDynamicInsn =
() -> methodVisitor.visitInvokeDynamicInsn(null, null, null);
Exception exception = assertThrows(UnsupportedOperationException.class, visitInvokeDynamicInsn);
assertTrue(exception.getMessage().matches(UNSUPPORTED_OPERATION_MESSAGE_PATTERN));
}
@Test
public void testVisitInsnAnnotation_asm4Visitor() {
MethodVisitor methodVisitor = new MethodVisitor(Opcodes.ASM4, null) {};
assertThrows(
UnsupportedOperationException.class,
() -> methodVisitor.visitInsnAnnotation(0, null, null, false));
Executable visitInsnAnnotation = () -> methodVisitor.visitInsnAnnotation(0, null, null, false);