cleanup work

This commit is contained in:
Eugen Paraschiv
2018-03-04 17:39:09 +02:00
parent 14bf9a24d5
commit d2a2a65566
193 changed files with 1504 additions and 2388 deletions
@@ -1,6 +1,5 @@
package com.baeldung.cglib.proxy;
import net.sf.cglib.beans.BeanGenerator;
import org.junit.Test;
@@ -12,21 +11,17 @@ public class BeanGeneratorIntegrationTest {
@Test
public void givenBeanCreator_whenAddProperty_thenClassShouldHaveFieldValue() throws Exception {
//given
// given
BeanGenerator beanGenerator = new BeanGenerator();
//when
// when
beanGenerator.addProperty("name", String.class);
Object myBean = beanGenerator.create();
Method setter = myBean
.getClass()
.getMethod("setName", String.class);
Method setter = myBean.getClass().getMethod("setName", String.class);
setter.invoke(myBean, "some string value set by a cglib");
//then
Method getter = myBean
.getClass()
.getMethod("getName");
// then
Method getter = myBean.getClass().getMethod("getName");
assertEquals("some string value set by a cglib", getter.invoke(myBean));
}
}
@@ -14,14 +14,11 @@ public class MixinUnitTest {
@Test
public void givenTwoClasses_whenMixedIntoOne_thenMixinShouldHaveMethodsFromBothClasses() throws Exception {
//when
Mixin mixin = Mixin.create(
new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
new Object[]{new Class1(), new Class2()}
);
// when
Mixin mixin = Mixin.create(new Class[] { Interface1.class, Interface2.class, MixinInterface.class }, new Object[] { new Class1(), new Class2() });
MixinInterface mixinDelegate = (MixinInterface) mixin;
//then
// then
assertEquals("first behaviour", mixinDelegate.first());
assertEquals("second behaviour", mixinDelegate.second());
}
@@ -10,34 +10,34 @@ import static org.junit.Assert.assertEquals;
public class ProxyIntegrationTest {
@Test
public void givenPersonService_whenSayHello_thenReturnResult() {
//given
// given
PersonService personService = new PersonService();
//when
// when
String res = personService.sayHello("Tom");
//then
// then
assertEquals(res, "Hello Tom");
}
@Test
public void givenEnhancerProxy_whenExtendPersonService_thenInterceptMethod() throws Exception {
//given
// given
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(PersonService.class);
enhancer.setCallback((FixedValue) () -> "Hello Tom!");
PersonService proxy = (PersonService) enhancer.create();
//when
// when
String res = proxy.sayHello(null);
//then
// then
assertEquals("Hello Tom!", res);
}
@Test
public void givenEnhancer_whenExecuteMethodOnProxy_thenInterceptOnlyStringReturnTypeMethod() throws Exception {
//given
// given
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(PersonService.class);
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
@@ -48,10 +48,10 @@ public class ProxyIntegrationTest {
}
});
//when
// when
PersonService proxy = (PersonService) enhancer.create();
//then
// then
assertEquals("Hello Tom!", proxy.sayHello(null));
int lengthOfName = proxy.lengthOfName("Mary");
assertEquals(4, lengthOfName);