From 31cf702160ae3b6a2cfb84fb37340c953a35ff97 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Fri, 17 Feb 2017 15:57:35 +0100 Subject: [PATCH] BAEL-633 more descriptive code --- cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java | 2 +- cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java | 2 +- .../java/com/baeldung/cglib/proxy/BeanGeneratorTest.java | 6 +++--- .../test/java/com/baeldung/cglib/proxy/MixinTest.java | 6 +++--- .../com/baeldung/cglib/proxy/PersonServiceProxyTest.java | 9 ++++----- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java index 2921cda8a6..932951b4cd 100644 --- a/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java @@ -3,6 +3,6 @@ package com.baeldung.cglib.mixin; public class Class1 implements Interface1 { @Override public String first() { - return "first"; + return "first behaviour"; } } \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java index 0098c9debd..b2b922a05d 100644 --- a/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java @@ -3,6 +3,6 @@ package com.baeldung.cglib.mixin; public class Class2 implements Interface2 { @Override public String second() { - return "second"; + return "second behaviour"; } } \ No newline at end of file diff --git a/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java b/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java index 4b401ae690..32706409c5 100644 --- a/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java @@ -16,13 +16,13 @@ public class BeanGeneratorTest { BeanGenerator beanGenerator = new BeanGenerator(); //when - beanGenerator.addProperty("value", String.class); + beanGenerator.addProperty("name", String.class); Object myBean = beanGenerator.create(); - Method setter = myBean.getClass().getMethod("setValue", 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("getValue"); + Method getter = myBean.getClass().getMethod("getName"); assertEquals("some string value set by a cglib", getter.invoke(myBean)); } } diff --git a/cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java b/cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java index 31e7b2204f..ac4b50af4c 100644 --- a/cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java @@ -9,7 +9,7 @@ import static junit.framework.TestCase.assertEquals; public class MixinTest { @Test - public void testMixin() throws Exception { + public void testMixinBehaviour() throws Exception { //when Mixin mixin = Mixin.create( new Class[]{Interface1.class, Interface2.class, MixinInterface.class}, @@ -18,7 +18,7 @@ public class MixinTest { MixinInterface mixinDelegate = (MixinInterface) mixin; //then - assertEquals("first", mixinDelegate.first()); - assertEquals("second", mixinDelegate.second()); + assertEquals("first behaviour", mixinDelegate.first()); + assertEquals("second behaviour", mixinDelegate.second()); } } diff --git a/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java b/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java index 2ae6392a05..e0ad017538 100644 --- a/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java @@ -25,14 +25,14 @@ public class PersonServiceProxyTest { //given Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(PersonService.class); - enhancer.setCallback((FixedValue) () -> "Hello cglib!"); + enhancer.setCallback((FixedValue) () -> "Hello Tom!"); PersonService proxy = (PersonService) enhancer.create(); //when String res = proxy.sayHello(null); //then - assertEquals("Hello cglib!", res); + assertEquals("Hello Tom!", res); } @Test @@ -42,7 +42,7 @@ public class PersonServiceProxyTest { enhancer.setSuperclass(PersonService.class); enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> { if (method.getDeclaringClass() != Object.class && method.getReturnType() == String.class) { - return "Hello cglib!"; + return "Hello Tom!"; } else { return proxy.invokeSuper(obj, args); } @@ -52,8 +52,7 @@ public class PersonServiceProxyTest { PersonService proxy = (PersonService) enhancer.create(); //then - assertEquals("Hello cglib!", proxy.sayHello(null)); - + assertEquals("Hello Tom!", proxy.sayHello(null)); int lengthOfName = proxy.lengthOfName("Mary"); assertEquals(4, lengthOfName); }