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 7386351
Showing 1 changed file with 29 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 Down Expand Up @@ -93,6 +95,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 7386351

Please sign in to comment.