diff --git a/src/test/java/org/apache/ibatis/submitted/collection_injection/ImmutableCollectionConstructorTest.java b/src/test/java/org/apache/ibatis/submitted/collection_injection/ImmutableCollectionConstructorTest.java index e3b4c241fd6..d615cd1d44c 100644 --- a/src/test/java/org/apache/ibatis/submitted/collection_injection/ImmutableCollectionConstructorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/collection_injection/ImmutableCollectionConstructorTest.java @@ -55,21 +55,33 @@ void shouldSelectAllHouses() { final StringBuilder builder = new StringBuilder(); for (House house : houses) { - builder.append(house.getName()).append("\n"); + builder.append("\n").append(house.getName()); for (Room room : house.getRooms()) { - builder.append("\t").append(room.getName()).append("\n"); + RoomDetail roomDetail = room.getRoomDetail(); + String detailString = String.format(" (size=%d, height=%d, type=%s)", roomDetail.getRoomSize(), + roomDetail.getWallHeight(), roomDetail.getWallType()); + builder.append("\n").append("\t").append(room.getName()).append(detailString); for (Furniture furniture : room.getFurniture()) { - builder.append("\t\t").append(furniture.getDescription()).append("\n"); + builder.append("\n").append("\t\t").append(furniture.getDescription()); for (Defect defect : furniture.getDefects()) { - builder.append("\t\t\t").append(defect.getDefect()).append("\n"); + builder.append("\n").append("\t\t\t").append(defect.getDefect()); } } } } - String expected = "MyBatis Headquarters\n" + "\tKitchen\n" + "\t\tCoffee machine\n" + "\t\t\tDoes not work\n" - + "\t\tFridge\n" + "\tDining room\n" + "\t\tTable\n" + "\tProgramming room\n" + "\t\tBig screen\n" - + "\t\tLaptop\n" + "\t\t\tCannot run intellij\n"; + String expected = + "\nMyBatis Headquarters" + + "\n\tKitchen (size=25, height=20, type=Brick)" + + "\n\t\tCoffee machine" + + "\n\t\t\tDoes not work" + + "\n\t\tFridge" + + "\n\tDining room (size=100, height=10, type=Wood)" + + "\n\t\tTable" + + "\n\tProgramming room (size=200, height=15, type=Steel)" + + "\n\t\tBig screen" + + "\n\t\tLaptop" + + "\n\t\t\tCannot run intellij"; assertThat(builder.toString()).isNotEmpty().isEqualTo(expected); } diff --git a/src/test/java/org/apache/ibatis/submitted/collection_injection/Room.java b/src/test/java/org/apache/ibatis/submitted/collection_injection/Room.java index 95433128f2b..cc049579a92 100644 --- a/src/test/java/org/apache/ibatis/submitted/collection_injection/Room.java +++ b/src/test/java/org/apache/ibatis/submitted/collection_injection/Room.java @@ -20,13 +20,13 @@ public class Room { private final int id; private final String name; - private final int size; + private final RoomDetail roomDetail; private final List furniture; - public Room(int id, String name, int size, List furniture) { + public Room(int id, String name, RoomDetail roomDetail, List furniture) { this.id = id; this.name = name; - this.size = size; + this.roomDetail = roomDetail; this.furniture = furniture; } @@ -38,8 +38,8 @@ public String getName() { return name; } - public int getSize() { - return size; + public RoomDetail getRoomDetail() { + return roomDetail; } public List getFurniture() { @@ -48,6 +48,6 @@ public List getFurniture() { @Override public String toString() { - return "Room{" + "id=" + id + ", name='" + name + '\'' + ", size=" + size + ", furniture=" + furniture + '}'; + return "Room{" + "id=" + id + ", name='" + name + '\'' + ", roomDetail=" + roomDetail + ", furniture=" + furniture + '}'; } } diff --git a/src/test/java/org/apache/ibatis/submitted/collection_injection/RoomDetail.java b/src/test/java/org/apache/ibatis/submitted/collection_injection/RoomDetail.java new file mode 100644 index 00000000000..867d47010bc --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/collection_injection/RoomDetail.java @@ -0,0 +1,50 @@ +/* + * Copyright 2009-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.submitted.collection_injection; + +public class RoomDetail { + + private final String wallType; + private final int wallHeight; + private final int roomSize; + + public RoomDetail(final String wallType, final int wallHeight, final int roomSize) { + this.wallType = wallType; + this.wallHeight = wallHeight; + this.roomSize = roomSize; + } + + public String getWallType() { + return wallType; + } + + public int getWallHeight() { + return wallHeight; + } + + public int getRoomSize() { + return roomSize; + } + + @Override + public String toString() { + return "RoomDetail{" + + "wallType='" + wallType + '\'' + + ", wallHeight=" + wallHeight + + ", roomSize=" + roomSize + + '}'; + } +} diff --git a/src/test/resources/org/apache/ibatis/submitted/collection_injection/CreateDB.sql b/src/test/resources/org/apache/ibatis/submitted/collection_injection/CreateDB.sql index b9e3659bbf9..4e285387701 100644 --- a/src/test/resources/org/apache/ibatis/submitted/collection_injection/CreateDB.sql +++ b/src/test/resources/org/apache/ibatis/submitted/collection_injection/CreateDB.sql @@ -32,7 +32,9 @@ create table room ( id int, name varchar(20), house_id int, - size_m2 int + size_m2 int, + wall_type varchar(10), + wall_height int ); alter table room add constraint fk_room_house_id @@ -58,9 +60,9 @@ alter table defect add constraint fk_defects_furniture_id insert into house (id, name) values ( 1, 'MyBatis Headquarters' ); -insert into room (id, name, house_id, size_m2) VALUES ( 1, 'Kitchen', 1, 25 ); -insert into room (id, name, house_id, size_m2) VALUES ( 2, 'Dining room', 1, 100 ); -insert into room (id, name, house_id, size_m2) VALUES ( 3, 'Programming room', 1, 200 ); +insert into room (id, name, house_id, size_m2, wall_type, wall_height) VALUES ( 1, 'Kitchen', 1, 25, 'Brick', 20 ); +insert into room (id, name, house_id, size_m2, wall_type, wall_height) VALUES ( 2, 'Dining room', 1, 100, 'Wood', 10 ); +insert into room (id, name, house_id, size_m2, wall_type, wall_height) VALUES ( 3, 'Programming room', 1, 200, 'Steel', 15 ); insert into furniture (id, description, room_id) VALUES ( 1, 'Coffee machine', 1); insert into furniture (id, description, room_id) VALUES ( 2, 'Fridge', 1); diff --git a/src/test/resources/org/apache/ibatis/submitted/collection_injection/HouseMapper.xml b/src/test/resources/org/apache/ibatis/submitted/collection_injection/HouseMapper.xml index 27f22e6f55a..f530400705c 100644 --- a/src/test/resources/org/apache/ibatis/submitted/collection_injection/HouseMapper.xml +++ b/src/test/resources/org/apache/ibatis/submitted/collection_injection/HouseMapper.xml @@ -34,11 +34,19 @@ - + + + + + + + + + @@ -59,7 +67,9 @@ , r.id as room_id , r.name as room_name - , r.size_m2 as room_size + , r.size_m2 as room_size_m2 + , r.wall_type as room_wall_type + , r.wall_height as room_wall_height , f.id as room_furniture_id , f.description as room_furniture_description diff --git a/src/test/resources/org/apache/ibatis/submitted/collection_injection/mybatis-config.xml b/src/test/resources/org/apache/ibatis/submitted/collection_injection/mybatis-config.xml index e969943b004..742739d2fb2 100644 --- a/src/test/resources/org/apache/ibatis/submitted/collection_injection/mybatis-config.xml +++ b/src/test/resources/org/apache/ibatis/submitted/collection_injection/mybatis-config.xml @@ -28,6 +28,7 @@ +