Class AsmTest


  • public abstract class AsmTest
    extends java.lang.Object
    Base class for the ASM tests. ASM can be used to read, write or transform any Java class, ranging from very old (e.g. JDK 1.3) to very recent classes, containing all possible class file structures. ASM can also be used with different variants of its API (ASM4, ASM5, ASM6, etc). In order to test it thoroughly, it is therefore necessary to run read, write and transform tests, for each API version, and for each class in a set of classes containing all possible class file structures. The purpose of this class is to automate this process. For this it relies on:
    • a small set of hand-crafted classes designed to contain as much class file structures as possible (it is impossible to represent all possible bytecode sequences). These classes are called "precompiled classes" below, because they are not compiled as part of the build. Instead, they have been compiled beforehand with the appropriate JDKs (e.g. with the JDK 1.3, 1.5, etc).
    • the JUnit framework for parameterized tests. Using the allClassesAndAllApis() method, selected test methods can be instantiated for each possible (precompiled class, ASM API) tuple.

    For instance, to run a test on all the precompiled classes, with all the APIs, use a subclass such as the following:

     public class MyParameterizedTest extends AsmTest {
    
       @ParameterizedTest
       @MethodSource(ALL_CLASSES_AND_ALL_APIS)
       public void testSomeFeature(PrecompiledClass classParameter, Api apiParameter) {
         byte[] b = classParameter.getBytes();
         ClassWriter classWriter = new ClassWriter(apiParameter.value(), 0);
         ...
       }
     }
     
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AsmTest.Api
      An ASM API version.
      static class  AsmTest.InvalidClass
      An invalid class, hand-crafted to contain some set of invalid class file structures.
      static class  AsmTest.PrecompiledClass
      A precompiled class, hand-crafted to contain some set of class file structures.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ALL_CLASSES_AND_ALL_APIS
      MethodSource name to be used in parameterized tests that must be instantiated for all possible (precompiled class, api) pairs.
      static java.lang.String ALL_CLASSES_AND_LATEST_API
      MethodSource name to be used in parameterized tests that must be instantiated for all precompiled classes, with the latest api.
      private static int INPUT_STREAM_DATA_CHUNK_SIZE
      The size of the temporary byte array used to read class input streams chunk by chunk.
      static java.lang.String UNSUPPORTED_OPERATION_MESSAGE_PATTERN
      The expected pattern (i.e.
    • Constructor Summary

      Constructors 
      Constructor Description
      AsmTest()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> allClassesAndAllApis()
      Builds a list of test arguments for a parameterized test.
      static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> allClassesAndLatestApi()
      Builds a list of test arguments for a parameterized test.
      private static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> classesAndApis​(AsmTest.Api... apis)  
      private static byte[] getBytes​(java.lang.String name)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INPUT_STREAM_DATA_CHUNK_SIZE

        private static final int INPUT_STREAM_DATA_CHUNK_SIZE
        The size of the temporary byte array used to read class input streams chunk by chunk.
        See Also:
        Constant Field Values
      • ALL_CLASSES_AND_ALL_APIS

        public static final java.lang.String ALL_CLASSES_AND_ALL_APIS
        MethodSource name to be used in parameterized tests that must be instantiated for all possible (precompiled class, api) pairs.
        See Also:
        Constant Field Values
      • ALL_CLASSES_AND_LATEST_API

        public static final java.lang.String ALL_CLASSES_AND_LATEST_API
        MethodSource name to be used in parameterized tests that must be instantiated for all precompiled classes, with the latest api.
        See Also:
        Constant Field Values
      • UNSUPPORTED_OPERATION_MESSAGE_PATTERN

        public static final java.lang.String UNSUPPORTED_OPERATION_MESSAGE_PATTERN
        The expected pattern (i.e. regular expression) that ASM's UnsupportedOperationException messages are supposed to match.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AsmTest

        public AsmTest()
    • Method Detail

      • allClassesAndAllApis

        public static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> allClassesAndAllApis()
        Builds a list of test arguments for a parameterized test. Parameterized test cases annotated with @MethodSource("allClassesAndAllApis") will be executed on all the possible (precompiledClass, api) pairs.
        Returns:
        all the possible (precompiledClass, api) pairs, for all the precompiled classes and all the given ASM API versions.
      • allClassesAndLatestApi

        public static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> allClassesAndLatestApi()
        Builds a list of test arguments for a parameterized test. Parameterized test cases annotated with @MethodSource("allClassesAndLatestApi") will be executed on all the precompiled classes, with the latest api.
        Returns:
        all the possible (precompiledClass, ASM9) pairs, for all the precompiled classes.
      • classesAndApis

        private static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> classesAndApis​(AsmTest.Api... apis)
      • getBytes

        private static byte[] getBytes​(java.lang.String name)