Skip to content

Commit 8c7bbf3

Browse files
committed
move the test case to org.apache.ibatis.autoconstructor
1 parent 330159a commit 8c7bbf3

File tree

5 files changed

+32
-48
lines changed

5 files changed

+32
-48
lines changed

src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public interface AutoConstructorMapper {
2929
@Select("SELECT * FROM subject")
3030
List<AnnotatedSubject> getAnnotatedSubjects();
3131

32+
@Select("SELECT * FROM subject")
33+
List<BadAnnotatedSubject> getBadAnnotatedSubjects();
34+
3235
@Select("SELECT * FROM subject")
3336
List<BadSubject> getBadSubjects();
3437

src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
*/
1616
package org.apache.ibatis.autoconstructor;
1717

18-
import static org.junit.jupiter.api.Assertions.assertNotNull;
19-
import static org.junit.jupiter.api.Assertions.assertThrows;
20-
2118
import java.io.Reader;
2219
import java.util.List;
2320

2421
import org.apache.ibatis.BaseDataTest;
2522
import org.apache.ibatis.exceptions.PersistenceException;
23+
import org.apache.ibatis.executor.ExecutorException;
2624
import org.apache.ibatis.io.Resources;
2725
import org.apache.ibatis.session.SqlSession;
2826
import org.apache.ibatis.session.SqlSessionFactory;
@@ -31,6 +29,8 @@
3129
import org.junit.jupiter.api.BeforeAll;
3230
import org.junit.jupiter.api.Test;
3331

32+
import static org.junit.jupiter.api.Assertions.*;
33+
3434
class AutoConstructorTest {
3535
private static SqlSessionFactory sqlSessionFactory;
3636

@@ -71,6 +71,16 @@ void annotatedSubject() {
7171
}
7272
}
7373

74+
@Test
75+
void badMultipleAnnotatedSubject() {
76+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
77+
final AutoConstructorMapper mapper = sqlSession.getMapper(AutoConstructorMapper.class);
78+
final PersistenceException ex = assertThrows(PersistenceException.class, mapper::getBadAnnotatedSubjects);
79+
final ExecutorException cause = (ExecutorException) ex.getCause();
80+
assertEquals("@AutomapConstructor should be used in only one constructor.", cause.getMessage());
81+
}
82+
}
83+
7484
@Test
7585
void badSubject() {
7686
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,45 +13,32 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.apache.ibatis.submitted.arg_name_baesd_constructor_automapping;
16+
package org.apache.ibatis.autoconstructor;
1717

1818
import org.apache.ibatis.annotations.AutomapConstructor;
1919

20-
public class User3 {
21-
22-
private Integer id;
23-
private String name;
24-
private Long team;
20+
public class BadAnnotatedSubject {
21+
private final int id;
22+
private final String name;
23+
private final int age;
24+
private final int height;
25+
private final int weight;
2526

2627
@AutomapConstructor
27-
public User3(Integer id, String name, Long team) {
28-
super();
28+
public BadAnnotatedSubject(final int id, final String name, final int age, final int height, final int weight) {
2929
this.id = id;
3030
this.name = name;
31-
this.team = team;
31+
this.age = age;
32+
this.height = height;
33+
this.weight = weight;
3234
}
3335

3436
@AutomapConstructor
35-
public User3(Integer id, String name) {
36-
super();
37+
public BadAnnotatedSubject(final int id, final String name, final int age, final Integer height, final Integer weight) {
3738
this.id = id;
3839
this.name = name;
39-
this.team = 100L;
40-
}
41-
42-
public Integer getId() {
43-
return id;
44-
}
45-
46-
public String getName() {
47-
return name;
48-
}
49-
50-
public void setTeam(Long team) {
51-
this.team = team;
52-
}
53-
54-
public Long getTeam() {
55-
return team;
40+
this.age = age;
41+
this.height = height == null ? 0 : height;
42+
this.weight = weight == null ? 0 : weight;
5643
}
5744
}

src/test/java/org/apache/ibatis/submitted/arg_name_baesd_constructor_automapping/ArgNameBasedConstructorAutoMappingTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,4 @@ void shouldApplyColumnPrefix() {
135135
assertEquals(99, task.getAssignee().getTeam());
136136
}
137137
}
138-
139-
@Test
140-
void shouldBeOnlyOneAutomapConstructorAnnotation() {
141-
// This test requires -parameters compiler option
142-
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
143-
Mapper mapper = sqlSession.getMapper(Mapper.class);
144-
mapper.selectNameAndIdWithAmbiguousConstructor(1);
145-
fail("Exception should be thrown");
146-
} catch (PersistenceException e) {
147-
ExecutorException ex = (ExecutorException) e.getCause();
148-
assertEquals("@AutomapConstructor should be used in only one constructor.", ex.getMessage());
149-
}
150-
}
151138
}

src/test/java/org/apache/ibatis/submitted/arg_name_baesd_constructor_automapping/Mapper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,5 @@ public interface Mapper {
3434
@Select("select name user_name, id user_id from users where id = #{id}")
3535
User2 selectUserIdAndUserNameUnderscore(Integer id);
3636

37-
@Select("select name, id from users where id = #{id}")
38-
User3 selectNameAndIdWithAmbiguousConstructor(Integer id);
39-
4037
Task selectTask(Integer id);
4138
}

0 commit comments

Comments
 (0)