*/
package org.opendaylight.mdsal.binding.generator.util;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
-import com.google.common.collect.ImmutableList;
+import javassist.CannotCompileException;
import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtField;
-import javassist.bytecode.AccessFlag;
+import javassist.NotFoundException;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.generator.util.ClassCustomizer;
-import org.opendaylight.mdsal.binding.generator.util.ClassGenerator;
-import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
-import org.opendaylight.mdsal.binding.generator.util.MethodGenerator;
+@Deprecated
public class JavassistUtilsTest {
@Test
- public void forClassPool() throws Exception {
+ public void forClassPool() throws CannotCompileException, NotFoundException {
final JavassistUtils javassistUtils = JavassistUtils.forClassPool(ClassPool.getDefault());
final ClassGenerator classGenerator = mock(ClassGenerator.class);
doNothing().when(classGenerator).process(any());
- final CtClass ctInterface = javassistUtils.createClass("TestInterface", classGenerator);
- ctInterface.setModifiers(AccessFlag.INTERFACE);
- final CtClass ctClass = javassistUtils.createClass("TestClass", ctInterface, classGenerator);
- javassistUtils.ensureClassLoader(ctClass.getClass());
- assertNotNull(ctClass);
- assertNotNull(javassistUtils.get(ClassPool.getDefault(), ctClass.getClass()));
-
- CtField ctField = javassistUtils.field(ctClass, "testField", Object.class);
- assertEquals(ctField, ctClass.getField("testField"));
- ctField = javassistUtils.staticField(ctClass, "testStaticField", Object.class);
- assertEquals(ctField, ctClass.getField("testStaticField"));
-
- final MethodGenerator methodGenerator = mock(MethodGenerator.class);
- doNothing().when(methodGenerator).process(any());
- javassistUtils.method(ctClass, Void.class, "testMethod", Object.class, methodGenerator);
- javassistUtils.method(ctInterface, Void.class, "testInterfaceMethod", Object.class, methodGenerator);
- javassistUtils.method(ctClass, Void.class, "testMethod2", ImmutableList.of(Object.class), methodGenerator);
- javassistUtils.staticMethod(ctClass, Void.class, "testStaticMethod", Object.class, methodGenerator);
- javassistUtils.implementMethodsFrom(ctClass, ctInterface, methodGenerator);
- assertNotNull(ctClass.getDeclaredMethod("testMethod"));
- assertNotNull(ctClass.getDeclaredMethod("testMethod2"));
- assertNotNull(ctClass.getDeclaredMethod("testStaticMethod"));
- assertNotNull(ctClass.getDeclaredMethod("testInterfaceMethod"));
final ClassCustomizer classCustomizer = mock(ClassCustomizer.class);
doNothing().when(classCustomizer).customizeClass(any());