diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Item.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Item.java index 70ca2e55897..4e4a20fc1e9 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Item.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Item.java @@ -1,5 +1,5 @@ -/** - * Copyright 2009-2015 the original author or authors. +/* + * Copyright 2009-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,16 @@ public class Item { private Integer id; private String name; + public String toString(){ + return new StringBuilder() + .append("Item(") + .append(id) + .append(", ") + .append(name) + .append(" )") + .toString(); + } + public Integer getId() { return id; } diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.java index b786e03ff70..bda7b6b3cfe 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.java @@ -1,5 +1,5 @@ -/** - * Copyright 2009-2015 the original author or authors. +/* + * Copyright 2009-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,4 +20,5 @@ public interface Mapper { List getPersons(); List getPersonsWithItemsOrdered(); + List getPersonItemPairs(); } diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.xml b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.xml index 380179c449a..b5eb012ee6b 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.xml +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Mapper.xml @@ -40,4 +40,23 @@ where p.id = i.owner order by i.name + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java index e4b6acb1432..d741592ee57 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java @@ -1,5 +1,5 @@ -/** - * Copyright 2009-2015 the original author or authors. +/* + * Copyright 2009-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; public class NestedResultHandlerTest { @@ -87,7 +88,6 @@ public void testGetPersonWithHandler() { SqlSession sqlSession = sqlSessionFactory.openSession(); try { sqlSession.select("getPersons", new ResultHandler() { - @Override public void handleResult(ResultContext context) { Person person = (Person) context.getResultObject(); if ("grandma".equals(person.getName())) { @@ -105,7 +105,6 @@ public void testUnorderedGetPersonWithHandler() { SqlSession sqlSession = sqlSessionFactory.openSession(); try { sqlSession.select("getPersonsWithItemsOrdered", new ResultHandler() { - @Override public void handleResult(ResultContext context) { Person person = (Person) context.getResultObject(); if ("grandma".equals(person.getName())) { @@ -152,4 +151,25 @@ public void testGetPersonOrderedByItem() { } } + @Ignore + @Test //reopen issue 39? (not a bug?) + public void testGetPersonItemPairs(){ + SqlSession sqlSession = sqlSessionFactory.openSession(); + try{ + Mapper mapper = sqlSession.getMapper(Mapper.class); + List pairs = mapper.getPersonItemPairs(); + + Assert.assertNotNull( pairs ); +// System.out.println( new StringBuilder().append("selected pairs: ").append(pairs) ); + + Assert.assertEquals(5, pairs.size() ); + Assert.assertNotNull(pairs.get(0).getPerson()); + Assert.assertEquals(pairs.get(0).getPerson().getId(), Integer.valueOf(1)); + Assert.assertNotNull(pairs.get(0).getItem()); + Assert.assertEquals( pairs.get(0).getItem().getId(), Integer.valueOf(1)); + } finally{ + sqlSession.close(); + } + } + } diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Person.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Person.java index d76b66cf3a9..401be16db3c 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Person.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/Person.java @@ -1,5 +1,5 @@ -/** - * Copyright 2009-2015 the original author or authors. +/* + * Copyright 2009-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,19 @@ public class Person { private Integer id; private String name; - private List items=new ArrayList(); + private List items=new ArrayList(); + + public String toString(){ + return new StringBuilder() + .append("Person(") + .append(id) + .append(", ") + .append(name) + .append(", ") + .append(items) + .append(" )") + .toString(); + } public Integer getId() { return id;