<commit_before>package org.sfm.jdbc;

import org.junit.Test;
import org.sfm.beans.DbObject;
import org.sfm.beans.Foo;
import org.sfm.jdbc.impl.JdbcMapperImpl;
import org.sfm.map.MapperBuilderErrorHandler;
import org.sfm.map.MappingException;
import org.sfm.map.FieldMapper;
import org.sfm.map.impl.LogFieldMapperErrorHandler;
import org.sfm.map.impl.MapperImpl;
import org.sfm.map.impl.RethrowRowHandlerErrorHandler;
import org.sfm.reflect.Instantiator;
import org.sfm.utils.RowHandler;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

public class JdbcMapperErrorTest {

	@Test
	public void testHandleMapperErrorSetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
		MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
		JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(DbObject.class);

		builder.addMapping("notthere1", 1);
		
		verify(errorHandler).propertyNotFound(DbObject.class, "notthere1");
		
		
		builder.addMapping("notthere3");
		
		verify(errorHandler).propertyNotFound(DbObject.class, "notthere3");
		
	}
	
	public static class MyClass {
		public Foo prop;
	}
	@Test
	public void testHandleMapperErrorGetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
		MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);

		JdbcMapperBuilder<MyClass> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(MyClass.class);

		builder.addMapping("prop", 1);
		
		builder.mapper();
		
		verify(errorHandler).getterNotFound("Could not find getter for ColumnKey [columnName=prop, columnIndex=1, sqlType=-99999] type class org.sfm.beans.Foo");
	}
	
	@Test
	public void setChangeFieldMapperErrorHandler() throws NoSuchMethodException, SecurityException, IOException {
		JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbObject.class);
		builder.addMapping("id");
		builder.fieldMapperErrorHandler(new LogFieldMapperErrorHandler<JdbcColumnKey>());
	}
	
	@Test
	public void testInstantiatorError() {
		MapperImpl<ResultSet, DbObject> mapper = new MapperImpl<ResultSet, DbObject>(null, null,
				new Instantiator<ResultSet, DbObject>() {
					@Override
					public DbObject newInstance(ResultSet s) throws Exception {
						throw new IOException();
					}
				},  new JdbcMappingContextFactoryBuilder().newFactory());
		
		try {
			mapper.map(null);
			fail("Expected error");
		} catch(Exception e) {
            assertTrue(e instanceof IOException);
        }
	}
	
	
	@SuppressWarnings("unchecked")
    @Test
	public void testHandlerError() throws MappingException, SQLException {
		
		MyJdbcRawHandlerErrorHandler handler = new MyJdbcRawHandlerErrorHandler();
		@SuppressWarnings("unchecked")
		FieldMapper<ResultSet, DbObject>[] fields = new FieldMapper[] {};
		JdbcMapperImpl<DbObject> mapper =
			new JdbcMapperImpl<DbObject>(
				new MapperImpl<>(
					fields,
					new FieldMapper[] {},
                	new Instantiator<ResultSet, DbObject>() {
						@Override
						public DbObject newInstance(ResultSet s) throws Exception {
							return new DbObject();
						}
					},
					new JdbcMappingContextFactoryBuilder().newFactory()),
				handler);
		final Error error = new Error();
		
		ResultSet rs = mock(ResultSet.class);
		when(rs.next()).thenReturn(true, false);
		
		mapper.forEach(rs, new RowHandler<DbObject>() {

			@Override
			public void handle(DbObject t) throws Exception {
				throw error;
			}
		});
		
		assertSame(error, handler.error);
		
		
	}



}
<commit_msg>fix java6 build<commit_after>package org.sfm.jdbc;

import org.junit.Test;
import org.sfm.beans.DbObject;
import org.sfm.beans.Foo;
import org.sfm.jdbc.impl.JdbcMapperImpl;
import org.sfm.map.MapperBuilderErrorHandler;
import org.sfm.map.MappingException;
import org.sfm.map.FieldMapper;
import org.sfm.map.impl.LogFieldMapperErrorHandler;
import org.sfm.map.impl.MapperImpl;
import org.sfm.map.impl.RethrowRowHandlerErrorHandler;
import org.sfm.reflect.Instantiator;
import org.sfm.utils.RowHandler;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

public class JdbcMapperErrorTest {

	@Test
	public void testHandleMapperErrorSetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
		MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
		JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(DbObject.class);

		builder.addMapping("notthere1", 1);
		
		verify(errorHandler).propertyNotFound(DbObject.class, "notthere1");
		
		
		builder.addMapping("notthere3");
		
		verify(errorHandler).propertyNotFound(DbObject.class, "notthere3");
		
	}
	
	public static class MyClass {
		public Foo prop;
	}
	@Test
	public void testHandleMapperErrorGetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
		MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);

		JdbcMapperBuilder<MyClass> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(MyClass.class);

		builder.addMapping("prop", 1);
		
		builder.mapper();
		
		verify(errorHandler).getterNotFound("Could not find getter for ColumnKey [columnName=prop, columnIndex=1, sqlType=-99999] type class org.sfm.beans.Foo");
	}
	
	@Test
	public void setChangeFieldMapperErrorHandler() throws NoSuchMethodException, SecurityException, IOException {
		JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbObject.class);
		builder.addMapping("id");
		builder.fieldMapperErrorHandler(new LogFieldMapperErrorHandler<JdbcColumnKey>());
	}
	
	@Test
	public void testInstantiatorError() {
		MapperImpl<ResultSet, DbObject> mapper = new MapperImpl<ResultSet, DbObject>(null, null,
				new Instantiator<ResultSet, DbObject>() {
					@Override
					public DbObject newInstance(ResultSet s) throws Exception {
						throw new IOException();
					}
				},  new JdbcMappingContextFactoryBuilder().newFactory());
		
		try {
			mapper.map(null);
			fail("Expected error");
		} catch(Exception e) {
            assertTrue(e instanceof IOException);
        }
	}
	
	
	@SuppressWarnings("unchecked")
    @Test
	public void testHandlerError() throws MappingException, SQLException {
		
		MyJdbcRawHandlerErrorHandler handler = new MyJdbcRawHandlerErrorHandler();
		@SuppressWarnings("unchecked")
		FieldMapper<ResultSet, DbObject>[] fields = new FieldMapper[] {};
		JdbcMapperImpl<DbObject> mapper =
			new JdbcMapperImpl<DbObject>(
				new MapperImpl<ResultSet, DbObject>(
					fields,
					new FieldMapper[] {},
                	new Instantiator<ResultSet, DbObject>() {
						@Override
						public DbObject newInstance(ResultSet s) throws Exception {
							return new DbObject();
						}
					},
					new JdbcMappingContextFactoryBuilder().newFactory()),
				handler);
		final Error error = new Error();
		
		ResultSet rs = mock(ResultSet.class);
		when(rs.next()).thenReturn(true, false);
		
		mapper.forEach(rs, new RowHandler<DbObject>() {

			@Override
			public void handle(DbObject t) throws Exception {
				throw error;
			}
		});
		
		assertSame(error, handler.error);
		
		
	}



}

{'fraction_non_alphanumeric': 0.10182965299684543, 'fraction_numerical': 0.0031545741324921135, 'mean_word_length': 4.16015625, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2136191', 'n_tokens_mistral': 2659, 'n_tokens_neox': 2275, 'n_words': 443}