Skip to content

Commit 8aa4550

Browse files
committed
Better way to check for CGLIB objects
1 parent 4e1c015 commit 8aa4550

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/test/java/org/apache/ibatis/executor/BaseExecutorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import javax.sql.DataSource;
2828

29+
import net.sf.cglib.proxy.Factory;
30+
2931
import org.apache.ibatis.BaseDataTest;
3032
import org.apache.ibatis.mapping.MappedStatement;
3133
import org.apache.ibatis.session.Configuration;
@@ -339,7 +341,7 @@ public void shouldFetchPostsForBlog() throws Exception {
339341
List<Post> posts = executor.query(selectPosts, 1, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
340342
executor.flushStatements();
341343
assertEquals(2, posts.size());
342-
assertTrue(posts.get(1).getClass().getName().contains("CGLIB"));
344+
assertTrue(posts.get(1) instanceof Factory);
343345
assertNotNull(posts.get(1).getBlog());
344346
assertEquals(1, posts.get(1).getBlog().getId());
345347
executor.rollback(true);

src/test/java/org/apache/ibatis/executor/loader/CglibProxyTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.ArrayList;
2424
import java.util.HashMap;
2525

26+
import net.sf.cglib.proxy.Factory;
27+
2628
import org.apache.ibatis.executor.ExecutorException;
2729
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
2830
import org.apache.ibatis.session.Configuration;
@@ -42,7 +44,7 @@ public void shouldCreateAProxyForAPartiallyLoadedBean() throws Exception {
4244
loader.addLoader("id", null, null);
4345
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
4446
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
45-
assertTrue(author2.getClass().getName().contains("CGLIB"));
47+
assertTrue(author2 instanceof Factory);
4648
}
4749

4850
@Test(expected = ExecutorException.class)

src/test/java/org/apache/ibatis/executor/loader/JavassistProxyTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public void shouldCreateAProxyForAPartiallyLoadedBean() throws Exception {
4444
loader.addLoader("id", null, null);
4545
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
4646
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
47-
// assertTrue(author2.getClass().getName().contains("CGLIB"));
4847
assertTrue(author2 instanceof Proxy);
4948
}
5049

src/test/java/org/apache/ibatis/session/SqlSessionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31+
import net.sf.cglib.proxy.Factory;
32+
3133
import org.apache.ibatis.BaseDataTest;
3234
import org.apache.ibatis.binding.BindingException;
3335
import org.apache.ibatis.cache.impl.PerpetualCache;
@@ -392,7 +394,7 @@ public void shouldSelectBlogWithPostsAndAuthorUsingSubSelectsLazily() throws Exc
392394
SqlSession session = sqlMapper.openSession();
393395
try {
394396
Blog blog = session.selectOne("domain.blog.mappers.BlogMapper.selectBlogWithPostsUsingSubSelectLazily", 1);
395-
Assert.assertTrue(blog.getClass().getName().contains("CGLIB"));
397+
Assert.assertTrue(blog instanceof Factory);
396398
assertEquals("Jim Business", blog.getTitle());
397399
assertEquals(2, blog.getPosts().size());
398400
assertEquals("Corn nuts", blog.getPosts().get(0).getSubject());

0 commit comments

Comments
 (0)