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