<commit_before>package org.simpleflatmapper.reflect.asm;

import org.junit.Assert;
import org.junit.Test;
import org.simpleflatmapper.ow2asm.MethodVisitor;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.util.TypeHelper;

import java.io.File;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import static org.simpleflatmapper.ow2asm.Opcodes.*;

public class AsmUtilsTest {

	@Test
	public void testToClass() throws  Exception {
		assertEquals(int.class, AsmUtils.toGenericType("I", null, null));
		assertEquals(String.class, AsmUtils.toGenericType("java/lang/String", null, null));
		assertEquals(String.class, AsmUtils.toGenericType("Ljava/lang/String;", null, null));
	}

	@Test
	public void testToGenericType() throws ClassNotFoundException {

		ParameterizedType pt = (ParameterizedType) AsmUtils.toGenericType("java/util/List<Ljava/util/List<Ljava/lang/String;>;>", null, null);
		ParameterizedType pt2 = (ParameterizedType) pt.getActualTypeArguments()[0];
		assertEquals(List.class, pt.getRawType());
		assertEquals(List.class, pt2.getRawType());
		assertEquals(String.class, pt2.getActualTypeArguments()[0]);

		assertEquals(pt, pt);
		assertEquals(pt.hashCode(), pt.hashCode());
		assertNotEquals(pt, pt2);
		assertEquals("ParameterizedTypeImpl{rawType=interface java.util.List, types=[ParameterizedTypeImpl{rawType=interface java.util.List, types=[class java.lang.String]}]}", pt.toString());
	}

	@Test
	public void testToAsmType() {
		assertEquals("java/lang/String", AsmUtils.toAsmType(String.class));
		assertEquals("java/lang/String", AsmUtils.toGenericAsmType(String.class));
		assertEquals("java/util/HashMap", AsmUtils.toAsmType(new HashMap<String, Long>() {}.getClass().getGenericSuperclass()));
		assertEquals("java/util/HashMap<Ljava/lang/String;Ljava/lang/Long;>", AsmUtils.toGenericAsmType(new HashMap<String, Long>() {}.getClass().getGenericSuperclass()));
	}


	@Test
	public void testToTargetTypeDeclaration() {
		assertEquals("I", AsmUtils.toTargetTypeDeclaration(int.class));
		assertEquals("Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration(String.class));
		assertEquals("[Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration(String[].class));


		assertEquals("Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration("java/lang/String"));
		assertEquals("[Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration("[Ljava/lang/String;"));
	}

	@Test
	public void testGetClosestPublicImpl() {
		assertEquals(HashMap.class, TypeHelper.toClass(AsmUtils.findClosestPublicTypeExposing(new HashMap<Object, Object>() {}.getClass(), Map.class)));
		assertNull(AsmUtils.findClosestPublicTypeExposing(new HashMap<Object, Object>() {}.getClass(), Getter.class));
	}

	@Test
	public void testToGenericTypeArray() throws ClassNotFoundException {
		assertEquals(String[].class, AsmUtils.toGenericType("[Ljava/lang/String;", Collections.emptyList(), Object.class));
	}

    @Test
    public void testToGenericTypeTuples() throws ClassNotFoundException {

        ParameterizedType pt = (ParameterizedType) AsmUtils.toGenericType("Lorg/simpleflatmapper/tuple/Tuple2<TT1;TT2;>;", Arrays.asList("T1", "T2"), new ParameterizedType() {
            @Override
            public Type[] getActualTypeArguments() {<commit_msg>fix java6<commit_after>package org.simpleflatmapper.reflect.asm;

import org.junit.Assert;
import org.junit.Test;
import org.simpleflatmapper.ow2asm.MethodVisitor;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.util.TypeHelper;

import java.io.File;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import static org.simpleflatmapper.ow2asm.Opcodes.*;

public class AsmUtilsTest {

	@Test
	public void testToClass() throws  Exception {
		assertEquals(int.class, AsmUtils.toGenericType("I", null, null));
		assertEquals(String.class, AsmUtils.toGenericType("java/lang/String", null, null));
		assertEquals(String.class, AsmUtils.toGenericType("Ljava/lang/String;", null, null));
	}

	@Test
	public void testToGenericType() throws ClassNotFoundException {

		ParameterizedType pt = (ParameterizedType) AsmUtils.toGenericType("java/util/List<Ljava/util/List<Ljava/lang/String;>;>", null, null);
		ParameterizedType pt2 = (ParameterizedType) pt.getActualTypeArguments()[0];
		assertEquals(List.class, pt.getRawType());
		assertEquals(List.class, pt2.getRawType());
		assertEquals(String.class, pt2.getActualTypeArguments()[0]);

		assertEquals(pt, pt);
		assertEquals(pt.hashCode(), pt.hashCode());
		assertNotEquals(pt, pt2);
		assertEquals("ParameterizedTypeImpl{rawType=interface java.util.List, types=[ParameterizedTypeImpl{rawType=interface java.util.List, types=[class java.lang.String]}]}", pt.toString());
	}

	@Test
	public void testToAsmType() {
		assertEquals("java/lang/String", AsmUtils.toAsmType(String.class));
		assertEquals("java/lang/String", AsmUtils.toGenericAsmType(String.class));
		assertEquals("java/util/HashMap", AsmUtils.toAsmType(new HashMap<String, Long>() {}.getClass().getGenericSuperclass()));
		assertEquals("java/util/HashMap<Ljava/lang/String;Ljava/lang/Long;>", AsmUtils.toGenericAsmType(new HashMap<String, Long>() {}.getClass().getGenericSuperclass()));
	}


	@Test
	public void testToTargetTypeDeclaration() {
		assertEquals("I", AsmUtils.toTargetTypeDeclaration(int.class));
		assertEquals("Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration(String.class));
		assertEquals("[Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration(String[].class));


		assertEquals("Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration("java/lang/String"));
		assertEquals("[Ljava/lang/String;", AsmUtils.toTargetTypeDeclaration("[Ljava/lang/String;"));
	}

	@Test
	public void testGetClosestPublicImpl() {
		assertEquals(HashMap.class, TypeHelper.toClass(AsmUtils.findClosestPublicTypeExposing(new HashMap<Object, Object>() {}.getClass(), Map.class)));
		assertNull(AsmUtils.findClosestPublicTypeExposing(new HashMap<Object, Object>() {}.getClass(), Getter.class));
	}

	@Test
	public void testToGenericTypeArray() throws ClassNotFoundException {
		assertEquals(String[].class, AsmUtils.toGenericType("[Ljava/lang/String;", Collections.<String>emptyList(), Object.class));
	}

    @Test
    public void testToGenericTypeTuples() throws ClassNotFoundException {

        ParameterizedType pt = (ParameterizedType) AsmUtils.toGenericType("Lorg/simpleflatmapper/tuple/Tuple2<TT1;TT2;>;", Arrays.asList("T1", "T2"), new ParameterizedType() {
            @Override
            public Type[] getActualTypeArguments() {
{'fraction_non_alphanumeric': 0.14088778604907637, 'fraction_numerical': 0.0037220843672456576, 'mean_word_length': 6.767665952890792, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '7153211', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2230, 'n_words': 355}