From b3303dc0cfebe443c1d997900bd8f8cf89d94764 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Tue, 14 Feb 2017 16:17:55 +0100 Subject: [PATCH 1/4] BAEL-633 craete cglib template --- cglib/pom.xml | 47 +++++++++++++++++++ .../com/baeldung/cglib/proxy/SampleClass.java | 7 +++ .../baeldung/cglib/proxy/SampleClassTest.java | 20 ++++++++ pom.xml | 1 + 4 files changed, 75 insertions(+) create mode 100644 cglib/pom.xml create mode 100644 cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java create mode 100644 cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java diff --git a/cglib/pom.xml b/cglib/pom.xml new file mode 100644 index 0000000000..21309cf514 --- /dev/null +++ b/cglib/pom.xml @@ -0,0 +1,47 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + cglib + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + cglib + cglib + ${cglib.version} + + + junit + junit + ${junit.version} + test + + + + + 3.2.4 + 4.12 + + + + \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java b/cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java new file mode 100644 index 0000000000..3e0d098dd1 --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java @@ -0,0 +1,7 @@ +package com.baeldung.cglib.proxy; + +public class SampleClass { + public String test(String input) { + return "Hello world!"; + } +} \ No newline at end of file diff --git a/cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java b/cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java new file mode 100644 index 0000000000..15037b3f1c --- /dev/null +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java @@ -0,0 +1,20 @@ +package com.baeldung.cglib.proxy; + +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.FixedValue; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SampleClassTest { + @Test + public void testFixedValue() throws Exception { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(SampleClass.class); + enhancer.setCallback((FixedValue) () -> "Hello cglib!"); + SampleClass proxy = (SampleClass) enhancer.create(); + assertEquals("Hello cglib!", proxy.test(null)); + + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2392e2c594..5bf0d4ad02 100644 --- a/pom.xml +++ b/pom.xml @@ -191,6 +191,7 @@ xstream struts2 + cglib From 895bcc1921eb716d6f7bd08bbef8c1e124753445 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Fri, 17 Feb 2017 12:19:57 +0100 Subject: [PATCH 2/4] BAEL-633 add mixing and bean creator test --- .../java/com/baeldung/cglib/mixin/Class1.java | 8 +++ .../java/com/baeldung/cglib/mixin/Class2.java | 8 +++ .../com/baeldung/cglib/mixin/Interface1.java | 5 ++ .../com/baeldung/cglib/mixin/Interface2.java | 5 ++ .../baeldung/cglib/mixin/MixinInterface.java | 4 ++ .../baeldung/cglib/proxy/PersonService.java | 11 ++++ .../com/baeldung/cglib/proxy/SampleClass.java | 7 --- .../cglib/proxy/BeanGeneratorTest.java | 28 +++++++++ .../com/baeldung/cglib/proxy/MixinTest.java | 24 ++++++++ .../cglib/proxy/PersonServiceProxyTest.java | 61 +++++++++++++++++++ .../baeldung/cglib/proxy/SampleClassTest.java | 20 ------ 11 files changed, 154 insertions(+), 27 deletions(-) create mode 100644 cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java create mode 100644 cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java create mode 100644 cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java create mode 100644 cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java create mode 100644 cglib/src/main/java/com/baeldung/cglib/mixin/MixinInterface.java create mode 100644 cglib/src/main/java/com/baeldung/cglib/proxy/PersonService.java delete mode 100644 cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java create mode 100644 cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java create mode 100644 cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java create mode 100644 cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java delete mode 100644 cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java new file mode 100644 index 0000000000..2921cda8a6 --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java @@ -0,0 +1,8 @@ +package com.baeldung.cglib.mixin; + +public class Class1 implements Interface1 { + @Override + public String first() { + return "first"; + } +} \ 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 new file mode 100644 index 0000000000..0098c9debd --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java @@ -0,0 +1,8 @@ +package com.baeldung.cglib.mixin; + +public class Class2 implements Interface2 { + @Override + public String second() { + return "second"; + } +} \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java new file mode 100644 index 0000000000..5aab155c1d --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java @@ -0,0 +1,5 @@ +package com.baeldung.cglib.mixin; + +public interface Interface1 { + String first(); +} \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java new file mode 100644 index 0000000000..7fd2e78608 --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java @@ -0,0 +1,5 @@ +package com.baeldung.cglib.mixin; + +public interface Interface2 { + String second(); +} \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/MixinInterface.java b/cglib/src/main/java/com/baeldung/cglib/mixin/MixinInterface.java new file mode 100644 index 0000000000..e7ed362a25 --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/MixinInterface.java @@ -0,0 +1,4 @@ +package com.baeldung.cglib.mixin; + +public interface MixinInterface extends Interface1, Interface2 { +} \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/proxy/PersonService.java b/cglib/src/main/java/com/baeldung/cglib/proxy/PersonService.java new file mode 100644 index 0000000000..9085e6c49a --- /dev/null +++ b/cglib/src/main/java/com/baeldung/cglib/proxy/PersonService.java @@ -0,0 +1,11 @@ +package com.baeldung.cglib.proxy; + +public class PersonService { + public String sayHello(String name) { + return "Hello " + name; + } + + public Integer lengthOfName(String name) { + return name.length(); + } +} \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java b/cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java deleted file mode 100644 index 3e0d098dd1..0000000000 --- a/cglib/src/main/java/com/baeldung/cglib/proxy/SampleClass.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.cglib.proxy; - -public class SampleClass { - public String test(String input) { - return "Hello world!"; - } -} \ 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 new file mode 100644 index 0000000000..4b401ae690 --- /dev/null +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java @@ -0,0 +1,28 @@ +package com.baeldung.cglib.proxy; + + +import net.sf.cglib.beans.BeanGenerator; +import org.junit.Test; + +import java.lang.reflect.Method; + +import static junit.framework.TestCase.assertEquals; + +public class BeanGeneratorTest { + + @Test + public void testBeanGenerator() throws Exception { + //given + BeanGenerator beanGenerator = new BeanGenerator(); + + //when + beanGenerator.addProperty("value", String.class); + Object myBean = beanGenerator.create(); + Method setter = myBean.getClass().getMethod("setValue", String.class); + setter.invoke(myBean, "some string value set by a cglib"); + + //then + Method getter = myBean.getClass().getMethod("getValue"); + 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 new file mode 100644 index 0000000000..31e7b2204f --- /dev/null +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java @@ -0,0 +1,24 @@ +package com.baeldung.cglib.proxy; + +import com.baeldung.cglib.mixin.*; +import net.sf.cglib.proxy.Mixin; +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +public class MixinTest { + + @Test + public void testMixin() throws Exception { + //when + Mixin mixin = Mixin.create( + new Class[]{Interface1.class, Interface2.class, MixinInterface.class}, + new Object[]{new Class1(), new Class2()} + ); + MixinInterface mixinDelegate = (MixinInterface) mixin; + + //then + assertEquals("first", mixinDelegate.first()); + assertEquals("second", 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 new file mode 100644 index 0000000000..2ae6392a05 --- /dev/null +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java @@ -0,0 +1,61 @@ +package com.baeldung.cglib.proxy; + +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.FixedValue; +import net.sf.cglib.proxy.MethodInterceptor; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class PersonServiceProxyTest { + @Test + public void testService() { + //given + PersonService personService = new PersonService(); + + //when + String res = personService.sayHello("Tom"); + + //then + assertEquals(res, "Hello Tom"); + } + + @Test + public void testFixedValue() throws Exception { + //given + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(PersonService.class); + enhancer.setCallback((FixedValue) () -> "Hello cglib!"); + PersonService proxy = (PersonService) enhancer.create(); + + //when + String res = proxy.sayHello(null); + + //then + assertEquals("Hello cglib!", res); + } + + @Test + public void testMethodInterceptor() throws Exception { + //given + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(PersonService.class); + enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> { + if (method.getDeclaringClass() != Object.class && method.getReturnType() == String.class) { + return "Hello cglib!"; + } else { + return proxy.invokeSuper(obj, args); + } + }); + + //when + PersonService proxy = (PersonService) enhancer.create(); + + //then + assertEquals("Hello cglib!", proxy.sayHello(null)); + + int lengthOfName = proxy.lengthOfName("Mary"); + assertEquals(4, lengthOfName); + } + +} \ No newline at end of file diff --git a/cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java b/cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java deleted file mode 100644 index 15037b3f1c..0000000000 --- a/cglib/src/test/java/com/baeldung/cglib/proxy/SampleClassTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.cglib.proxy; - -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.FixedValue; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class SampleClassTest { - @Test - public void testFixedValue() throws Exception { - Enhancer enhancer = new Enhancer(); - enhancer.setSuperclass(SampleClass.class); - enhancer.setCallback((FixedValue) () -> "Hello cglib!"); - SampleClass proxy = (SampleClass) enhancer.create(); - assertEquals("Hello cglib!", proxy.test(null)); - - } - -} \ No newline at end of file From 31cf702160ae3b6a2cfb84fb37340c953a35ff97 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Fri, 17 Feb 2017 15:57:35 +0100 Subject: [PATCH 3/4] 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); } From 12193e96fa8b39a8444ea97586ffa13ee8730e30 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Tue, 21 Feb 2017 17:29:29 +0100 Subject: [PATCH 4/4] BAEL-633 proper formatting and test naming --- .../src/main/java/com/baeldung/cglib/mixin/Class1.java | 8 ++++---- .../src/main/java/com/baeldung/cglib/mixin/Class2.java | 8 ++++---- .../main/java/com/baeldung/cglib/mixin/Interface1.java | 2 +- .../main/java/com/baeldung/cglib/mixin/Interface2.java | 2 +- .../com/baeldung/cglib/proxy/BeanGeneratorTest.java | 10 +++++++--- .../test/java/com/baeldung/cglib/proxy/MixinTest.java | 2 +- .../baeldung/cglib/proxy/PersonServiceProxyTest.java | 6 +++--- pom.xml | 2 +- 8 files changed, 22 insertions(+), 18 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 932951b4cd..fa0cba5b78 100644 --- a/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java @@ -1,8 +1,8 @@ package com.baeldung.cglib.mixin; public class Class1 implements Interface1 { - @Override - public String first() { - return "first behaviour"; - } + @Override + public String 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 b2b922a05d..0db0620ab8 100644 --- a/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java @@ -1,8 +1,8 @@ package com.baeldung.cglib.mixin; public class Class2 implements Interface2 { - @Override - public String second() { - return "second behaviour"; - } + @Override + public String second() { + return "second behaviour"; + } } \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java index 5aab155c1d..56ad679cad 100644 --- a/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface1.java @@ -1,5 +1,5 @@ package com.baeldung.cglib.mixin; public interface Interface1 { - String first(); + String first(); } \ No newline at end of file diff --git a/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java index 7fd2e78608..0dfb8737ab 100644 --- a/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java +++ b/cglib/src/main/java/com/baeldung/cglib/mixin/Interface2.java @@ -1,5 +1,5 @@ package com.baeldung.cglib.mixin; public interface Interface2 { - String second(); + String second(); } \ 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 32706409c5..67214cd32d 100644 --- a/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java @@ -11,18 +11,22 @@ import static junit.framework.TestCase.assertEquals; public class BeanGeneratorTest { @Test - public void testBeanGenerator() throws Exception { + public void givenBeanCreator_whenAddPropery_classShouldHaveFieldValue() throws Exception { //given BeanGenerator beanGenerator = new BeanGenerator(); //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"); + 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 ac4b50af4c..186c66aa42 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 testMixinBehaviour() throws Exception { + public void givenTwoClasses_whenMixtThemIntoOne_mixinShouldHaveMethodsFromBothClasses() throws Exception { //when Mixin mixin = Mixin.create( new Class[]{Interface1.class, Interface2.class, MixinInterface.class}, 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 e0ad017538..6208ed12b8 100644 --- a/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java +++ b/cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java @@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals; public class PersonServiceProxyTest { @Test - public void testService() { + public void givenPersonService_whenSayHello_shouldReturnResult() { //given PersonService personService = new PersonService(); @@ -21,7 +21,7 @@ public class PersonServiceProxyTest { } @Test - public void testFixedValue() throws Exception { + public void givenEnhancerProxy_whenExtendPersonService_shouldInterceptMethod() throws Exception { //given Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(PersonService.class); @@ -36,7 +36,7 @@ public class PersonServiceProxyTest { } @Test - public void testMethodInterceptor() throws Exception { + public void givenEnhancer_whenExecuteMethodOnProxy_shouldInterceptOnlyStringReturnTypeMethod() throws Exception { //given Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(PersonService.class); diff --git a/pom.xml b/pom.xml index a32a204304..52e00edbb4 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ autovalue cdi + cglib core-java couchbase-sdk @@ -192,7 +193,6 @@ xstream struts2 - cglib apache-velocity