org.mockito.cglib.core.NamingPolicy Java Examples

The following examples show how to use org.mockito.cglib.core.NamingPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityDefinitionManager.java    From Eagle with Apache License 2.0 5 votes vote down vote up
private static Class<?> createDynamicClassForMetric(final String className, Map<String, Class<?>> dynamicFieldTypes){
	BeanGenerator beanGenerator = new BeanGenerator();
	beanGenerator.setNamingPolicy(new NamingPolicy(){
        @Override 
        public String getClassName(String prefix,String source, Object key, Predicate names){
            return className;
        }});
    BeanGenerator.addProperties(beanGenerator, dynamicFieldTypes);
    beanGenerator.setSuperclass(TaggedLogAPIEntity.class);
    return (Class<?>) beanGenerator.createClass();
}
 
Example #2
Source File: EntityDefinitionManager.java    From eagle with Apache License 2.0 5 votes vote down vote up
private static Class<?> createDynamicClassForMetric(final String className,
                                                    Map<String, Class<?>> dynamicFieldTypes) {
    BeanGenerator beanGenerator = new BeanGenerator();
    beanGenerator.setNamingPolicy(new NamingPolicy() {
        @Override
        public String getClassName(String prefix, String source, Object key, Predicate names) {
            return className;
        }
    });
    BeanGenerator.addProperties(beanGenerator, dynamicFieldTypes);
    beanGenerator.setSuperclass(TaggedLogAPIEntity.class);
    return (Class<?>)beanGenerator.createClass();
}
 
Example #3
Source File: CGLIBHackerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldSetMockitoNamingPolicy() throws Exception {
    //given
    MockitoMethodProxy methodProxy = new MethodProxyBuilder().build();
    
    //when
    new CGLIBHacker().setMockitoNamingPolicy(methodProxy);
    
    //then
    Object realMethodProxy = Whitebox.invokeMethod(methodProxy, "getMethodProxy", new Object[0]);
    Object createInfo = Whitebox.getInternalState(realMethodProxy, "createInfo");
    NamingPolicy namingPolicy = (NamingPolicy) Whitebox.getInternalState(createInfo, "namingPolicy");
    assertEquals(MockitoNamingPolicy.INSTANCE, namingPolicy);
}
 
Example #4
Source File: CGLIBHackerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldSetMockitoNamingPolicyEvenIfMethodProxyIsProxied() throws Exception {
    //given
    MockitoMethodProxy proxiedMethodProxy = spy(new MethodProxyBuilder().build());
    
    //when
    new CGLIBHacker().setMockitoNamingPolicy(proxiedMethodProxy);
    
    //then
    Object realMethodProxy = Whitebox.invokeMethod(proxiedMethodProxy, "getMethodProxy", new Object[0]);
    Object createInfo = Whitebox.getInternalState(realMethodProxy, "createInfo");
    NamingPolicy namingPolicy = (NamingPolicy) Whitebox.getInternalState(createInfo, "namingPolicy");
    assertEquals(MockitoNamingPolicy.INSTANCE, namingPolicy);
}
 
Example #5
Source File: CGLIBHackerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldSetMockitoNamingPolicy() throws Exception {
    //given
    MockitoMethodProxy methodProxy = new MethodProxyBuilder().build();
    
    //when
    new CGLIBHacker().setMockitoNamingPolicy(methodProxy);
    
    //then
    Object realMethodProxy = Whitebox.invokeMethod(methodProxy, "getMethodProxy", new Object[0]);
    Object createInfo = Whitebox.getInternalState(realMethodProxy, "createInfo");
    NamingPolicy namingPolicy = (NamingPolicy) Whitebox.getInternalState(createInfo, "namingPolicy");
    assertEquals(MockitoNamingPolicy.INSTANCE, namingPolicy);
}
 
Example #6
Source File: CGLIBHackerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldSetMockitoNamingPolicyEvenIfMethodProxyIsProxied() throws Exception {
    //given
    MockitoMethodProxy proxiedMethodProxy = spy(new MethodProxyBuilder().build());
    
    //when
    new CGLIBHacker().setMockitoNamingPolicy(proxiedMethodProxy);
    
    //then
    Object realMethodProxy = Whitebox.invokeMethod(proxiedMethodProxy, "getMethodProxy", new Object[0]);
    Object createInfo = Whitebox.getInternalState(realMethodProxy, "createInfo");
    NamingPolicy namingPolicy = (NamingPolicy) Whitebox.getInternalState(createInfo, "namingPolicy");
    assertEquals(MockitoNamingPolicy.INSTANCE, namingPolicy);
}