<commit_before>/**
 *    Copyright 2009-2016 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
 *
 *       http://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.array_result_type;

import static org.junit.Assert.*;

import java.io.Reader;
import java.sql.Connection;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class ArrayResultTypeTest {

  private static SqlSessionFactory sqlSessionFactory;

  @BeforeClass
  public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();

    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
  }

  @Test
  public void shouldGetUserArray() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      User[] users = mapper.getUsers();
      assertEquals("User1", users[0].getName());
      assertEquals("User2", users[1].getName());
    } finally {
      sqlSession.close();
    }
  }

  @Test
  public void shouldGetUserArrayXml() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      User[] users = mapper.getUsersXml();
      assertEquals("User1", users[0].getName());
      assertEquals("User2", users[1].getName());
    } finally {
      sqlSession.close();
    }
  }

  @Test
  public void shouldGetSimpleTypeArray() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      Integer[] ids = mapper.getUserIds();
      assertEquals(Integer.valueOf(1), ids[0]);
    } finally {
      sqlSession.close();
    }
  }

  @Ignore("primitive array return type is not supported. #555")
  @Test
  public void shouldGetPrimitiveArray() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      int[] ids = mapper.getUserIdsPrimitive();
      assertEquals(1, ids[0]);
    } finally {
      sqlSession.close();
    }
  }
}<commit_msg>While #555 is open, throwing ClassCastException is the expected behavior.<commit_after>/**
 *    Copyright 2009-2016 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
 *
 *       http://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.array_result_type;

import static org.junit.Assert.*;

import java.io.Reader;
import java.sql.Connection;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.BeforeClass;
import org.junit.Test;

public class ArrayResultTypeTest {

  private static SqlSessionFactory sqlSessionFactory;

  @BeforeClass
  public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();

    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
  }

  @Test
  public void shouldGetUserArray() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      User[] users = mapper.getUsers();
      assertEquals("User1", users[0].getName());
      assertEquals("User2", users[1].getName());
    } finally {
      sqlSession.close();
    }
  }

  @Test
  public void shouldGetUserArrayXml() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      User[] users = mapper.getUsersXml();
      assertEquals("User1", users[0].getName());
      assertEquals("User2", users[1].getName());
    } finally {
      sqlSession.close();
    }
  }

  @Test
  public void shouldGetSimpleTypeArray() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      Integer[] ids = mapper.getUserIds();
      assertEquals(Integer.valueOf(1), ids[0]);
    } finally {
      sqlSession.close();
    }
  }

  @Test(expected = ClassCastException.class)
  public void shouldGetPrimitiveArray() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      // Throwing an exception is the expected behavior
      // until #555 is fixed
      Mapper mapper = sqlSession.getMapper(Mapper.class);
      int[] ids = mapper.getUserIdsPrimitive();
      assertEquals(1, ids[0]);
    } finally {
      sqlSession.close();
    }
  }
}
{'fraction_non_alphanumeric': 0.10784743533537922, 'fraction_numerical': 0.008329679964927663, 'mean_word_length': 3.6494565217391304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4048740', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1901, 'n_words': 487}