org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind Java Examples

The following examples show how to use org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Used to validate the match returned from a compareArguments call.
 */
private void checkMatch2(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
	ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
	if (expectedMatchKind == null) {
		assertNull("Did not expect them to match in any way: " + matchInfo, matchInfo);
	}
	else {
		assertNotNull("Should not be a null match", matchInfo);
	}

	if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
		assertTrue(matchInfo.isExactMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
		assertTrue(matchInfo.isCloseMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
		assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
	}
}
 
Example #2
Source File: ReflectionHelperTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_RequiresConversionMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
	checkMatch(new Class<?>[] {String.class, Integer.TYPE}, new Class<?>[] {String.class,Integer.class},tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
	checkMatch(new Class<?>[] {Integer.TYPE, String.class}, new Class<?>[] {Integer.class, String.class},tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
	checkMatch(new Class<?>[] {Integer.TYPE, Sub.class}, new Class<?>[] {Integer.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
	// TODO checkMatch(new Class<?>[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class<?>[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION);
}
 
Example #3
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Used to validate the match returned from a compareArguments call.
 */
private void checkMatch(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
	ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
	if (expectedMatchKind == null) {
		assertNull("Did not expect them to match in any way", matchInfo);
	}
	else {
		assertNotNull("Should not be a null match", matchInfo);
	}

	if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
		assertTrue(matchInfo.isExactMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
		assertTrue(matchInfo.isCloseMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
		assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
	}
}
 
Example #4
Source File: ReflectionHelperTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Used to validate the match returned from a compareArguments call.
 */
private void checkMatch(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
	ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
	if (expectedMatchKind == null) {
		assertNull("Did not expect them to match in any way", matchInfo);
	}
	else {
		assertNotNull("Should not be a null match", matchInfo);
	}

	if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
		assertTrue(matchInfo.isExactMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
		assertTrue(matchInfo.isCloseMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
		assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
	}
}
 
Example #5
Source File: ReflectionHelperTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Used to validate the match returned from a compareArguments call.
 */
private void checkMatch2(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
	ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
	if (expectedMatchKind == null) {
		assertNull("Did not expect them to match in any way: " + matchInfo, matchInfo);
	}
	else {
		assertNotNull("Should not be a null match", matchInfo);
	}

	if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
		assertTrue(matchInfo.isExactMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
		assertTrue(matchInfo.isCloseMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
		assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
	}
}
 
Example #6
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_RequiresConversionMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
	checkMatch(new Class[] {String.class, Integer.TYPE}, new Class[] {String.class,Integer.class},tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
	checkMatch(new Class[] {Integer.TYPE, String.class}, new Class[] {Integer.class, String.class},tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
	checkMatch(new Class[] {Integer.TYPE, Sub.class}, new Class[] {Integer.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
	// TODO checkMatch(new Class[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION);
}
 
Example #7
Source File: ReflectionHelperTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_RequiresConversionMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
	checkMatch(new Class<?>[] {String.class, Integer.TYPE}, new Class<?>[] {String.class,Integer.class},tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
	checkMatch(new Class<?>[] {Integer.TYPE, String.class}, new Class<?>[] {Integer.class, String.class},tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
	checkMatch(new Class<?>[] {Integer.TYPE, Sub.class}, new Class<?>[] {Integer.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
	// TODO checkMatch(new Class<?>[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class<?>[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION);
}
 
Example #8
Source File: ReflectionHelperTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Used to validate the match returned from a compareArguments call.
 */
private void checkMatch(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
	ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
	if (expectedMatchKind == null) {
		assertNull("Did not expect them to match in any way", matchInfo);
	}
	else {
		assertNotNull("Should not be a null match", matchInfo);
	}

	if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
		assertTrue(matchInfo.isExactMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
		assertTrue(matchInfo.isCloseMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
		assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
	}
}
 
Example #9
Source File: ReflectionHelperTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Used to validate the match returned from a compareArguments call.
 */
private void checkMatch2(Class<?>[] inputTypes, Class<?>[] expectedTypes, StandardTypeConverter typeConverter, ArgumentsMatchKind expectedMatchKind) {
	ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
	if (expectedMatchKind == null) {
		assertNull("Did not expect them to match in any way: " + matchInfo, matchInfo);
	}
	else {
		assertNotNull("Should not be a null match", matchInfo);
	}

	if (expectedMatchKind == ArgumentsMatchKind.EXACT) {
		assertTrue(matchInfo.isExactMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.CLOSE) {
		assertTrue(matchInfo.isCloseMatch());
	}
	else if (expectedMatchKind == ArgumentsMatchKind.REQUIRES_CONVERSION) {
		assertTrue("expected to be a match requiring conversion, but was " + matchInfo, matchInfo.isMatchRequiringConversion());
	}
}
 
Example #10
Source File: ReflectionHelperTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_CloseMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(List) with (ArrayList) is close match (no conversion required)
	checkMatch(new Class<?>[] {ArrayList.class}, new Class<?>[] {List.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Sub,String) on call to foo(Super,String) is close match
	checkMatch(new Class<?>[] {Sub.class, String.class}, new Class<?>[] {Super.class, String.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (String,Sub) on call to foo(String,Super) is close match
	checkMatch(new Class<?>[] {String.class, Sub.class}, new Class<?>[] {String.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);
}
 
Example #11
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_CloseMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(List) with (ArrayList) is close match (no conversion required)
	checkMatch(new Class[] {ArrayList.class}, new Class[] {List.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Sub,String) on call to foo(Super,String) is close match
	checkMatch(new Class[] {Sub.class, String.class}, new Class[] {Super.class, String.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (String,Sub) on call to foo(String,Super) is close match
	checkMatch(new Class[] {String.class, Sub.class}, new Class[] {String.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);
}
 
Example #12
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_ExactMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(String) with (String) is exact match
	checkMatch(new Class[] {String.class}, new Class[] {String.class}, tc, ReflectionHelper.ArgumentsMatchKind.EXACT);

	// Calling foo(String,Integer) with (String,Integer) is exact match
	checkMatch(new Class[] {String.class, Integer.class}, new Class[] {String.class, Integer.class}, tc, ArgumentsMatchKind.EXACT);
}
 
Example #13
Source File: ReflectionHelperTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_CloseMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(List) with (ArrayList) is close match (no conversion required)
	checkMatch(new Class<?>[] {ArrayList.class}, new Class<?>[] {List.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Sub,String) on call to foo(Super,String) is close match
	checkMatch(new Class<?>[] {Sub.class, String.class}, new Class<?>[] {Super.class, String.class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (String,Sub) on call to foo(String,Super) is close match
	checkMatch(new Class<?>[] {String.class, Sub.class}, new Class<?>[] {String.class, Super.class}, tc, ArgumentsMatchKind.CLOSE);
}
 
Example #14
Source File: ReflectionHelperTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_ExactMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(String) with (String) is exact match
	checkMatch(new Class<?>[] {String.class}, new Class<?>[] {String.class}, tc, ReflectionHelper.ArgumentsMatchKind.EXACT);

	// Calling foo(String,Integer) with (String,Integer) is exact match
	checkMatch(new Class<?>[] {String.class, Integer.class}, new Class<?>[] {String.class, Integer.class}, tc, ArgumentsMatchKind.EXACT);
}
 
Example #15
Source File: ReflectionHelperTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_ExactMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Calling foo(String) with (String) is exact match
	checkMatch(new Class<?>[] {String.class}, new Class<?>[] {String.class}, tc, ReflectionHelper.ArgumentsMatchKind.EXACT);

	// Calling foo(String,Integer) with (String,Integer) is exact match
	checkMatch(new Class<?>[] {String.class, Integer.class}, new Class<?>[] {String.class, Integer.class}, tc, ArgumentsMatchKind.EXACT);
}
 
Example #16
Source File: ReflectionHelperTests.java    From java-technology-stack with MIT License 2 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_Varargs_ExactMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Passing (String[]) on call to (String[]) is exact match
	checkMatch2(new Class<?>[] {String[].class}, new Class<?>[] {String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Integer, String[]) on call to (Integer, String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, String[].class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
	checkMatch2(new Class<?>[] {String.class, Integer.class, String[].class}, new Class<?>[] {String.class,Integer.class, String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Sub, String[]) on call to (Super, String[]) is exact match
	checkMatch2(new Class<?>[] {Sub.class, String[].class}, new Class<?>[] {Super.class,String[].class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Integer, String[]) on call to (String, String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, String[].class}, new Class<?>[] {String.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, Sub.class, String[].class}, new Class<?>[] {String.class,Super .class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (String) on call to (String[]) is exact match
	checkMatch2(new Class<?>[] {String.class}, new Class<?>[] {String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Integer,String) on call to (Integer,String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, String.class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (String) on call to (Integer[]) is conversion match (String to Integer)
	checkMatch2(new Class<?>[] {String.class}, new Class<?>[] {Integer[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (Sub) on call to (Super[]) is close match
	checkMatch2(new Class<?>[] {Sub.class}, new Class<?>[] {Super[].class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Super) on call to (Sub[]) is not a match
	checkMatch2(new Class<?>[] {Super.class}, new Class<?>[] {Sub[].class}, tc, null);

	checkMatch2(new Class<?>[] {Unconvertable.class, String.class}, new Class<?>[] {Sub.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, String.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Unconvertable.class, String.class}, new Class<?>[] {Sub.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, String.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, Sub.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, Integer.class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
	// what happens on (Integer,String) passed to (Integer[]) ?
}
 
Example #17
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_Varargs_ExactMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();
	Class<?> stringArrayClass = new String[0].getClass();
	Class<?> integerArrayClass = new Integer[0].getClass();

	// Passing (String[]) on call to (String[]) is exact match
	checkMatch2(new Class[] {stringArrayClass}, new Class[] {stringArrayClass}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Integer, String[]) on call to (Integer, String[]) is exact match
	checkMatch2(new Class[] {Integer.class, stringArrayClass}, new Class[] {Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT);

	// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
	checkMatch2(new Class[] {String.class, Integer.class, stringArrayClass}, new Class[] {String.class,Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Sub, String[]) on call to (Super, String[]) is exact match
	checkMatch2(new Class[] {Sub.class, stringArrayClass}, new Class[] {Super.class,stringArrayClass}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Integer, String[]) on call to (String, String[]) is exact match
	checkMatch2(new Class[] {Integer.class, stringArrayClass}, new Class[] {String.class, stringArrayClass}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
	checkMatch2(new Class[] {Integer.class, Sub.class, String[].class}, new Class[] {String.class,Super .class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (String) on call to (String[]) is exact match
	checkMatch2(new Class[] {String.class}, new Class[] {stringArrayClass}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Integer,String) on call to (Integer,String[]) is exact match
	checkMatch2(new Class[] {Integer.class, String.class}, new Class[] {Integer.class, stringArrayClass}, tc, ArgumentsMatchKind.EXACT);

	// Passing (String) on call to (Integer[]) is conversion match (String to Integer)
	checkMatch2(new Class[] {String.class}, new Class[] {integerArrayClass}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (Sub) on call to (Super[]) is close match
	checkMatch2(new Class[] {Sub.class}, new Class[] {new Super[0].getClass()}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Super) on call to (Sub[]) is not a match
	checkMatch2(new Class[] {Super.class}, new Class[] {new Sub[0].getClass()}, tc, null);

	checkMatch2(new Class[] {Unconvertable.class, String.class}, new Class[] {Sub.class, Super[].class}, tc, null);

	checkMatch2(new Class[] {Integer.class, Integer.class, String.class}, new Class[] {String.class, String.class, Super[].class}, tc, null);

	checkMatch2(new Class[] {Unconvertable.class, String.class}, new Class[] {Sub.class, Super[].class}, tc, null);

	checkMatch2(new Class[] {Integer.class, Integer.class, String.class}, new Class[] {String.class, String.class, Super[].class}, tc, null);

	checkMatch2(new Class[] {Integer.class, Integer.class, Sub.class}, new Class[] {String.class, String.class, Super[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	checkMatch2(new Class[] {Integer.class, Integer.class, Integer.class}, new Class[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
	// what happens on (Integer,String) passed to (Integer[]) ?
}
 
Example #18
Source File: ReflectionHelperTests.java    From spring-analysis-note with MIT License 2 votes vote down vote up
@Test
public void testReflectionHelperCompareArguments_Varargs_ExactMatching() {
	StandardTypeConverter tc = new StandardTypeConverter();

	// Passing (String[]) on call to (String[]) is exact match
	checkMatch2(new Class<?>[] {String[].class}, new Class<?>[] {String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Integer, String[]) on call to (Integer, String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, String[].class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
	checkMatch2(new Class<?>[] {String.class, Integer.class, String[].class}, new Class<?>[] {String.class,Integer.class, String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Sub, String[]) on call to (Super, String[]) is exact match
	checkMatch2(new Class<?>[] {Sub.class, String[].class}, new Class<?>[] {Super.class,String[].class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Integer, String[]) on call to (String, String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, String[].class}, new Class<?>[] {String.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, Sub.class, String[].class}, new Class<?>[] {String.class,Super .class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (String) on call to (String[]) is exact match
	checkMatch2(new Class<?>[] {String.class}, new Class<?>[] {String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (Integer,String) on call to (Integer,String[]) is exact match
	checkMatch2(new Class<?>[] {Integer.class, String.class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.EXACT);

	// Passing (String) on call to (Integer[]) is conversion match (String to Integer)
	checkMatch2(new Class<?>[] {String.class}, new Class<?>[] {Integer[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	// Passing (Sub) on call to (Super[]) is close match
	checkMatch2(new Class<?>[] {Sub.class}, new Class<?>[] {Super[].class}, tc, ArgumentsMatchKind.CLOSE);

	// Passing (Super) on call to (Sub[]) is not a match
	checkMatch2(new Class<?>[] {Super.class}, new Class<?>[] {Sub[].class}, tc, null);

	checkMatch2(new Class<?>[] {Unconvertable.class, String.class}, new Class<?>[] {Sub.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, String.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Unconvertable.class, String.class}, new Class<?>[] {Sub.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, String.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, null);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, Sub.class}, new Class<?>[] {String.class, String.class, Super[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);

	checkMatch2(new Class<?>[] {Integer.class, Integer.class, Integer.class}, new Class<?>[] {Integer.class, String[].class}, tc, ArgumentsMatchKind.REQUIRES_CONVERSION);
	// what happens on (Integer,String) passed to (Integer[]) ?
}