<commit_before>/*
 * Copyright 2004-2008 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.springframework.core.convert.support;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.fail;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.junit.Ignore;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.converter.Converter;

public class GenericTypeConverterTests {

	private GenericTypeConverter converter = new GenericTypeConverter();

	@Test
	public void executeConversion() {
		converter.add(new StringToInteger());
		assertEquals(new Integer(3), converter.convert("3", Integer.class));
	}

	@Test
	public void executeConversionNullSource() {
		assertEquals(null, converter.convert(null, Integer.class));
	}
	
	@Test
	public void executeCompatibleSource() {
		assertEquals(Boolean.FALSE, converter.convert(false, boolean.class));
	}

	@Test
	public void converterNotFound() {
		try {
			converter.convert("3", Integer.class);
			fail("Should have thrown an exception");
		} catch (ConverterNotFoundException e) {
		}
	}

	@Test
	public void addConverterNoSourceTargetClassInfoAvailable() {
		try {
			converter.add(new Converter() {
				public Object convert(Object source) throws Exception {
					return source;
				}
			});
			fail("Should have failed");
		} catch (IllegalArgumentException e) {

		}
	}

	@Test
	public void convertNull() {
		assertNull(converter.convert(null, Integer.class));
	}
	
	@Test
	public void convertNullTargetClass() {
		assertEquals("3", converter.convert("3", (Class<?>)null));
	}

	@Test
	public void convertNullConversionPointType() {
		assertEquals("3", converter.convert("3", TypeDescriptor.NULL));
	}

	
	@Test
	public void convertWrongTypeArgument() {
		converter.add(new StringToInteger());
		try {
			converter.convert("BOGUS", Integer.class);
			fail("Should have failed");
		} catch (ConversionFailedException e) {

		}
	}

	@Test
	public void convertSuperSourceType() {
		converter.add(new Converter<CharSequence, Integer>() {
			public Integer convert(CharSequence source) throws Exception {
				return Integer.valueOf(source.toString());
			}
		});
		Integer result = converter.convert("3", Integer.class);
		assertEquals(new Integer(3), result);
	}

	@Test
	@Ignore
	public void convertNoSuperTargetType() {
		converter.add(new Converter<CharSequence, Number>() {
			public Integer convert(CharSequence source) throws Exception {
				return Integer.valueOf(source.toString());
			}
		});
		try {
			converter.convert("3", Integer.class);
			fail("Should have failed");
		} catch (ConverterNotFoundException e) {

		}
	}

	@Test
	public void convertObjectToPrimitive() {
		converter.add(new StringToInteger());
		Integer three = converter.convert("3", int.class);
		assertEquals(3, three.intValue());
	}

	@Test
	public void convertArrayToArray() {
		converter.add(new StringToInteger());
		Integer[] result = converter.convert(new String[] { "1", "2", "3" }, Integer[].class);
		assertEquals(new Integer(1), result[0]);
		assertEquals(new Integer(2), result[1]);
		assertEquals(new Integer(3), result[2]);
	}
<commit_msg>removed last ignore<commit_after>/*
 * Copyright 2004-2008 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.springframework.core.convert.support;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.fail;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;

public class GenericTypeConverterTests {

	private GenericTypeConverter converter = new GenericTypeConverter();

	@Test
	public void executeConversion() {
		converter.add(new StringToInteger());
		assertEquals(new Integer(3), converter.convert("3", Integer.class));
	}

	@Test
	public void executeConversionNullSource() {
		assertEquals(null, converter.convert(null, Integer.class));
	}
	
	@Test
	public void executeCompatibleSource() {
		assertEquals(Boolean.FALSE, converter.convert(false, boolean.class));
	}

	@Test
	public void converterNotFound() {
		try {
			converter.convert("3", Integer.class);
			fail("Should have thrown an exception");
		} catch (ConverterNotFoundException e) {
		}
	}

	@Test
	public void addConverterNoSourceTargetClassInfoAvailable() {
		try {
			converter.add(new Converter() {
				public Object convert(Object source) throws Exception {
					return source;
				}
			});
			fail("Should have failed");
		} catch (IllegalArgumentException e) {

		}
	}

	@Test
	public void convertNull() {
		assertNull(converter.convert(null, Integer.class));
	}
	
	@Test
	public void convertNullTargetClass() {
		assertEquals("3", converter.convert("3", (Class<?>)null));
	}

	@Test
	public void convertNullConversionPointType() {
		assertEquals("3", converter.convert("3", TypeDescriptor.NULL));
	}

	
	@Test
	public void convertWrongTypeArgument() {
		converter.add(new StringToInteger());
		try {
			converter.convert("BOGUS", Integer.class);
			fail("Should have failed");
		} catch (ConversionFailedException e) {

		}
	}

	@Test
	public void convertSuperSourceType() {
		converter.add(new Converter<CharSequence, Integer>() {
			public Integer convert(CharSequence source) throws Exception {
				return Integer.valueOf(source.toString());
			}
		});
		Integer result = converter.convert("3", Integer.class);
		assertEquals(new Integer(3), result);
	}

	@Test
	public void convertObjectToPrimitive() {
		converter.add(new StringToInteger());
		Integer three = converter.convert("3", int.class);
		assertEquals(3, three.intValue());
	}

	@Test
	public void convertArrayToArray() {
		converter.add(new StringToInteger());
		Integer[] result = converter.convert(new String[] { "1", "2", "3" }, Integer[].class);
		assertEquals(new Integer(1), result[0]);
		assertEquals(new Integer(2), result[1]);
		assertEquals(new Integer(3), result[2]);
	}

{'fraction_non_alphanumeric': 0.11735623211033047, 'fraction_numerical': 0.008456934686442883, 'mean_word_length': 4.863463005339436, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5457583', 'n_tokens_mistral': 2361, 'n_tokens_neox': 2153, 'n_words': 587}