e1d13ae40e1e482a579b23be7091ad3f2d2187c5
[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.NotFoundException;
19 import org.junit.Test;
20
21 public class JavassistUtilsTest {
22
23     @Test
24     public void forClassPool() throws CannotCompileException, NotFoundException {
25         final JavassistUtils javassistUtils = JavassistUtils.forClassPool(ClassPool.getDefault());
26         final ClassGenerator classGenerator = mock(ClassGenerator.class);
27         doNothing().when(classGenerator).process(any());
28
29         final ClassCustomizer classCustomizer = mock(ClassCustomizer.class);
30         doNothing().when(classCustomizer).customizeClass(any());
31         assertNotNull(javassistUtils.instantiatePrototype("javassist.CtNewClass", "leWut", classCustomizer));
32     }
33
34     @Test
35     public void privateConstructTest() throws Exception {
36         assertFalse(JavassistUtils.class.getDeclaredConstructor(ClassPool.class).isAccessible());
37     }
38 }