Skip to content

Commit

Permalink
Add test for Configuration#useActualParamName is false
Browse files Browse the repository at this point in the history
Related with mybatisgh-1237
  • Loading branch information
kazuki43zoo committed Mar 19, 2020
1 parent d1346e3 commit d95dc4d
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -16,6 +16,7 @@
package org.apache.ibatis.submitted.param_name_resolve;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
Expand All @@ -30,6 +31,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

class ActualParamNameTest {

Expand All @@ -56,6 +58,7 @@ static void setUp() throws Exception {

@Test
void testSingleListParameterWhenUseActualParamNameIsTrue() {
sqlSessionFactory.getConfiguration().setUseActualParamName(true);
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Mapper mapper = sqlSession.getMapper(Mapper.class);
// use actual name
Expand All @@ -78,6 +81,7 @@ void testSingleListParameterWhenUseActualParamNameIsTrue() {

@Test
void testSingleArrayParameterWhenUseActualParamNameIsTrue() {
sqlSessionFactory.getConfiguration().setUseActualParamName(true);
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Mapper mapper = sqlSession.getMapper(Mapper.class);
// use actual name
Expand All @@ -93,6 +97,33 @@ void testSingleArrayParameterWhenUseActualParamNameIsTrue() {
}
}

@Test
void testSingleListParameterWhenUseActualParamNameIsFalse() {
sqlSessionFactory.getConfiguration().setUseActualParamName(false);
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Mapper mapper = sqlSession.getMapper(Mapper.class);
// use actual name -> no available and index parameter("0") is not available too
{
try {
mapper.getUserCountUsingList(Arrays.asList(1, 2));
fail();
} catch (PersistenceException e) {
assertEquals("Parameter 'ids' not found. Available parameters are [collection, list]", e.getCause().getMessage());
}
}
// use 'collection' as alias
{
long count = mapper.getUserCountUsingListWithAliasIsCollection(Arrays.asList(1, 2));
assertEquals(2, count);
}
// use 'list' as alias
{
long count = mapper.getUserCountUsingListWithAliasIsList(Arrays.asList(1, 2));
assertEquals(2, count);
}
}
}

interface Mapper {
@Select({
"<script>",
Expand Down

0 comments on commit d95dc4d

Please sign in to comment.