Skip to content

Commit 31cf702

Browse files
author
Tomasz Lelek
committed
BAEL-633 more descriptive code
1 parent 895bcc1 commit 31cf702

5 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎cglib/src/main/java/com/baeldung/cglib/mixin/Class1.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
public class Class1 implements Interface1 {
44
@Override
55
public String first() {
6-
return "first";
6+
return "first behaviour";
77
}
88
}

‎cglib/src/main/java/com/baeldung/cglib/mixin/Class2.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
public class Class2 implements Interface2 {
44
@Override
55
public String second() {
6-
return "second";
6+
return "second behaviour";
77
}
88
}

‎cglib/src/test/java/com/baeldung/cglib/proxy/BeanGeneratorTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public void testBeanGenerator() throws Exception {
1616
BeanGenerator beanGenerator = new BeanGenerator();
1717

1818
//when
19-
beanGenerator.addProperty("value", String.class);
19+
beanGenerator.addProperty("name", String.class);
2020
Object myBean = beanGenerator.create();
21-
Method setter = myBean.getClass().getMethod("setValue", String.class);
21+
Method setter = myBean.getClass().getMethod("setName", String.class);
2222
setter.invoke(myBean, "some string value set by a cglib");
2323

2424
//then
25-
Method getter = myBean.getClass().getMethod("getValue");
25+
Method getter = myBean.getClass().getMethod("getName");
2626
assertEquals("some string value set by a cglib", getter.invoke(myBean));
2727
}
2828
}

‎cglib/src/test/java/com/baeldung/cglib/proxy/MixinTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class MixinTest {
1010

1111
@Test
12-
public void testMixin() throws Exception {
12+
public void testMixinBehaviour() throws Exception {
1313
//when
1414
Mixin mixin = Mixin.create(
1515
new Class[]{Interface1.class, Interface2.class, MixinInterface.class},
@@ -18,7 +18,7 @@ public void testMixin() throws Exception {
1818
MixinInterface mixinDelegate = (MixinInterface) mixin;
1919

2020
//then
21-
assertEquals("first", mixinDelegate.first());
22-
assertEquals("second", mixinDelegate.second());
21+
assertEquals("first behaviour", mixinDelegate.first());
22+
assertEquals("second behaviour", mixinDelegate.second());
2323
}
2424
}

‎cglib/src/test/java/com/baeldung/cglib/proxy/PersonServiceProxyTest.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public void testFixedValue() throws Exception {
2525
//given
2626
Enhancer enhancer = new Enhancer();
2727
enhancer.setSuperclass(PersonService.class);
28-
enhancer.setCallback((FixedValue) () -> "Hello cglib!");
28+
enhancer.setCallback((FixedValue) () -> "Hello Tom!");
2929
PersonService proxy = (PersonService) enhancer.create();
3030

3131
//when
3232
String res = proxy.sayHello(null);
3333

3434
//then
35-
assertEquals("Hello cglib!", res);
35+
assertEquals("Hello Tom!", res);
3636
}
3737

3838
@Test
@@ -42,7 +42,7 @@ public void testMethodInterceptor() throws Exception {
4242
enhancer.setSuperclass(PersonService.class);
4343
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
4444
if (method.getDeclaringClass() != Object.class && method.getReturnType() == String.class) {
45-
return "Hello cglib!";
45+
return "Hello Tom!";
4646
} else {
4747
return proxy.invokeSuper(obj, args);
4848
}
@@ -52,8 +52,7 @@ public void testMethodInterceptor() throws Exception {
5252
PersonService proxy = (PersonService) enhancer.create();
5353

5454
//then
55-
assertEquals("Hello cglib!", proxy.sayHello(null));
56-
55+
assertEquals("Hello Tom!", proxy.sayHello(null));
5756
int lengthOfName = proxy.lengthOfName("Mary");
5857
assertEquals(4, lengthOfName);
5958
}

0 commit comments

Comments
 (0)