Remove JavassistUtils.method utils
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / util / JavassistUtilsTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.generator.util;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.mock;
15
16 import javassist.CannotCompileException;
17 import javassist.ClassPool;
18 import javassist.CtClass;
19 import javassist.NotFoundException;
20 import javassist.bytecode.AccessFlag;
21 import org.junit.Test;
22
23 public class JavassistUtilsTest {
24
25     @Test
26     public void forClassPool() throws CannotCompileException, NotFoundException {
27         final JavassistUtils javassistUtils = JavassistUtils.forClassPool(ClassPool.getDefault());
28         final ClassGenerator classGenerator = mock(ClassGenerator.class);
29         doNothing().when(classGenerator).process(any());
30         final CtClass ctInterface = javassistUtils.createClass("TestInterface", classGenerator);
31         ctInterface.setModifiers(AccessFlag.INTERFACE);
32         final CtClass ctClass = javassistUtils.createClass("TestClass", ctInterface, classGenerator);
33         javassistUtils.ensureClassLoader(ctClass.getClass());
34         assertNotNull(ctClass);
35         assertNotNull(javassistUtils.get(ClassPool.getDefault(), ctClass.getClass()));
36
37         final ClassCustomizer classCustomizer = mock(ClassCustomizer.class);
38         doNothing().when(classCustomizer).customizeClass(any());
39         assertNotNull(javassistUtils.instantiatePrototype("javassist.CtNewClass", "leWut", classCustomizer));
40     }
41
42     @Test
43     public void privateConstructTest() throws Exception {
44         assertFalse(JavassistUtils.class.getDeclaredConstructor(ClassPool.class).isAccessible());
45     }
46 }