Merge branch '3.2.x' into master

* 3.2.x:
  Exclude spring-build-src from maven publish
  Move spring-build-junit into spring-core
  Relocate MergePlugin package
  Develop a gradle plugin to add test dependencies
  Expose Gradle buildSrc for IDE support
  Fix [deprecation] compiler warnings
  Upgrade to xmlunit version 1.3
  Improve 'build' folder ignores
  Fix regression in static setter method support
  Fix SpEL JavaBean compliance for setters

Conflicts:
	spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java
This commit is contained in:
Chris Beams
2013-01-02 10:36:57 +01:00
184 changed files with 1893 additions and 1282 deletions

View File

@@ -33,21 +33,25 @@ import org.springframework.util.MultiValueMap;
*/
public class CollectionFactoryTests extends TestCase {
@SuppressWarnings("deprecation")
public void testLinkedSet() {
Set set = CollectionFactory.createLinkedSetIfPossible(16);
assertTrue(set instanceof LinkedHashSet);
}
@SuppressWarnings("deprecation")
public void testLinkedMap() {
Map map = CollectionFactory.createLinkedMapIfPossible(16);
assertTrue(map instanceof LinkedHashMap);
}
@SuppressWarnings("deprecation")
public void testIdentityMap() {
Map map = CollectionFactory.createIdentityMapIfPossible(16);
assertTrue(map instanceof IdentityHashMap);
}
@SuppressWarnings("deprecation")
public void testConcurrentMap() {
Map map = CollectionFactory.createConcurrentMapIfPossible(16);
assertTrue(map.getClass().getName().endsWith("ConcurrentHashMap"));
@@ -58,6 +62,7 @@ public class CollectionFactoryTests extends TestCase {
assertTrue(map.getClass().getName().endsWith("MultiValueMap"));
}
@SuppressWarnings("deprecation")
public void testConcurrentMapWithExplicitInterface() {
ConcurrentMap map = CollectionFactory.createConcurrentMap(16);
assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap"));

View File

@@ -25,8 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import junit.framework.Assert;
import org.springframework.beans.GenericBean;
import org.springframework.core.io.Resource;
@@ -96,11 +94,11 @@ public class GenericCollectionTypeResolverTests extends AbstractGenericsTests {
public void testProgrammaticListIntrospection() throws Exception {
Method setter = GenericBean.class.getMethod("setResourceList", List.class);
Assert.assertEquals(Resource.class,
assertEquals(Resource.class,
GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0)));
Method getter = GenericBean.class.getMethod("getResourceList");
Assert.assertEquals(Resource.class,
assertEquals(Resource.class,
GenericCollectionTypeResolver.getCollectionReturnType(getter));
}

View File

@@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import junit.framework.TestCase;
import junit.framework.Assert;
/**
* @author Rod Johnson
@@ -52,7 +51,7 @@ public class NestedExceptionTests extends TestCase {
Exception rootCause = new Exception(rootCauseMesg);
// Making a class abstract doesn't _really_ prevent instantiation :-)
NestedRuntimeException nex = new NestedRuntimeException(myMessage, rootCause) {};
Assert.assertEquals(nex.getCause(), rootCause);
assertEquals(nex.getCause(), rootCause);
assertTrue(nex.getMessage().indexOf(myMessage) != -1);
assertTrue(nex.getMessage().indexOf(rootCauseMesg) != -1);
@@ -90,7 +89,7 @@ public class NestedExceptionTests extends TestCase {
Exception rootCause = new Exception(rootCauseMesg);
// Making a class abstract doesn't _really_ prevent instantiation :-)
NestedCheckedException nex = new NestedCheckedException(myMessage, rootCause) {};
Assert.assertEquals(nex.getCause(), rootCause);
assertEquals(nex.getCause(), rootCause);
assertTrue(nex.getMessage().indexOf(myMessage) != -1);
assertTrue(nex.getMessage().indexOf(rootCauseMesg) != -1);

View File

@@ -401,7 +401,7 @@ public class DefaultConversionTests {
public void convertArrayToObjectAssignableTargetType() {
Long[] array = new Long[] { 3L };
Long[] result = (Long[]) conversionService.convert(array, Object.class);
assertEquals(array, result);
assertArrayEquals(array, result);
}
@Test

View File

@@ -35,8 +35,6 @@ import java.util.UUID;
import org.junit.Test;
import org.springframework.build.junit.Assume;
import org.springframework.build.junit.TestGroup;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
@@ -46,6 +44,8 @@ import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;

View File

@@ -29,6 +29,7 @@ import junit.framework.TestCase;
* @author Juergen Hoeller
* @author Sam Brannen
*/
@Deprecated
public class LabeledEnumTests extends TestCase {
private byte[] serializeObject(final Object obj) throws IOException {

View File

@@ -21,6 +21,7 @@ import java.beans.PropertyEditor;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.Resource;
/**
@@ -67,7 +68,9 @@ public class ResourceArrayPropertyEditorTests {
@Test(expected=IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
PropertyEditor editor = new ResourceArrayPropertyEditor(new PathMatchingResourcePatternResolver(), false);
PropertyEditor editor = new ResourceArrayPropertyEditor(
new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
false);
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");

View File

@@ -17,13 +17,14 @@
package org.springframework.core.style;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.springframework.core.CollectionFactory;
import org.springframework.util.ObjectUtils;
/**
@@ -65,7 +66,7 @@ public class ToStringCreatorTests extends TestCase {
}
private Map getMap() {
Map map = CollectionFactory.createLinkedMapIfPossible(3);
Map map = new LinkedHashMap(3);
map.put("Keri", "Softball");
map.put("Scot", "Fishing");
map.put("Keith", "Flag Football");
@@ -96,7 +97,7 @@ public class ToStringCreatorTests extends TestCase {
}
public void testSet() {
Set set = CollectionFactory.createLinkedSetIfPossible(3);
Set set = new LinkedHashSet<>(3);
set.add(s1);
set.add(s2);
set.add(s3);

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2002-2013 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.tests;
import static org.junit.Assume.assumeFalse;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.junit.internal.AssumptionViolatedException;
/**
* Provides utility methods that allow JUnit tests to {@link org.junit.Assume} certain
* conditions hold {@code true}. If the assumption fails, it means the test should be
* skipped.
*
* <p>For example, if a set of tests require at least JDK 1.7 it can use
* {@code Assume#atLeast(JdkVersion.JAVA_17)} as shown below:
*
* <pre class="code">
* public void MyTests {
*
* &#064;BeforeClass
* public static assumptions() {
* Assume.atLeast(JdkVersion.JAVA_17);
* }
*
* // ... all the test methods that require at least JDK 1.7
* }
* </pre>
*
* If only a single test requires at least JDK 1.7 it can use the
* {@code Assume#atLeast(JdkVersion.JAVA_17)} as shown below:
*
* <pre class="code">
* public void MyTests {
*
* &#064;Test
* public void requiresJdk17 {
* Assume.atLeast(JdkVersion.JAVA_17);
* // ... perform the actual test
* }
* }
* </pre>
*
* In addition to assumptions based on the JDK version, tests can be categorized into
* {@link TestGroup}s. Active groups are enabled using the 'testGroups' system property,
* usually activated from the gradle command line:
* <pre>
* gradle test -PtestGroups="performance"
* </pre>
*
* Groups can be specified as a comma separated list of values, or using the pseudo group
* 'all'. See {@link TestGroup} for a list of valid groups.
*
* @author Rob Winch
* @author Phillip Webb
* @since 3.2
* @see #atLeast(JavaVersion)
* @see #group(TestGroup)
*/
public abstract class Assume {
private static final Set<TestGroup> GROUPS = TestGroup.parse(System.getProperty("testGroups"));
/**
* Assume a minimum {@link JavaVersion} is running.
* @param version the minimum version for the test to run
*/
public static void atLeast(JavaVersion version) {
if (!JavaVersion.runningVersion().isAtLeast(version)) {
throw new AssumptionViolatedException("Requires JDK " + version + " but running "
+ JavaVersion.runningVersion());
}
}
/**
* Assume that a particular {@link TestGroup} has been specified.
* @param group the group that must be specified.
*/
public static void group(TestGroup group) {
if (!GROUPS.contains(group)) {
throw new AssumptionViolatedException("Requires unspecified group " + group
+ " from " + GROUPS);
}
}
/**
* Assume that the specified log is not set to Trace or Debug.
* @param log the log to test
*/
public static void notLogging(Log log) {
assumeFalse(log.isTraceEnabled());
assumeFalse(log.isDebugEnabled());
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright 2002-2013 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.tests;
/**
* Enumeration of known JDK versions.
*
* @author Phillip Webb
* @see #runningVersion()
*/
public enum JavaVersion {
/**
* Java 1.5
*/
JAVA_15("1.5", 15),
/**
* Java 1.6
*/
JAVA_16("1.6", 16),
/**
* Java 1.7
*/
JAVA_17("1.7", 17),
/**
* Java 1.8
*/
JAVA_18("1.8", 18);
private static final JavaVersion runningVersion = findRunningVersion();
private static JavaVersion findRunningVersion() {
String version = System.getProperty("java.version");
for (JavaVersion candidate : values()) {
if (version.startsWith(candidate.version)) {
return candidate;
}
}
return JavaVersion.JAVA_15;
}
private String version;
private int value;
private JavaVersion(String version, int value) {
this.version = version;
this.value = value;
}
@Override
public String toString() {
return version;
}
/**
* Determines if the specified version is the same as or greater than this version.
* @param version the version to check
* @return {@code true} if the specified version is at least this version
*/
public boolean isAtLeast(JavaVersion version) {
return this.value >= version.value;
}
/**
* Returns the current running JDK version. If the current version cannot be
* determined {@link #JAVA_15} will be returned.
* @return the JDK version
*/
public static JavaVersion runningVersion() {
return runningVersion;
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2002-2013 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.tests;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Tests for {@link JavaVersion}.
*
* @author Phillip Webb
*/
public class JavaVersionTests {
@Test
public void runningVersion() {
assertNotNull(JavaVersion.runningVersion());
assertThat(System.getProperty("java.version"), startsWith(JavaVersion.runningVersion().toString()));
}
@Test
public void isAtLeast() throws Exception {
assertTrue(JavaVersion.JAVA_16.isAtLeast(JavaVersion.JAVA_15));
assertTrue(JavaVersion.JAVA_16.isAtLeast(JavaVersion.JAVA_16));
assertFalse(JavaVersion.JAVA_16.isAtLeast(JavaVersion.JAVA_17));
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright 2002-2012 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.tests;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
/**
* Additional hamcrest matchers.
*
* @author Phillip Webb
*/
public class Matchers {
/**
* Create a matcher that wrapps the specified matcher and tests against the
* {@link Throwable#getCause() cause} of an exception. If the item tested
* is {@code null} not a {@link Throwable} the wrapped matcher will be called
* with a {@code null} item.
*
* <p>Often useful when working with JUnit {@link ExpectedException}
* {@link Rule @Rule}s, for example:
* <pre>
* thrown.expect(DataAccessException.class);
* thrown.except(exceptionCause(isA(SQLException.class)));
* </pre>
*
* @param matcher the matcher to wrap (must not be null)
* @return a matcher that tests using the exception cause
*/
@SuppressWarnings("unchecked")
public static <T> Matcher<T> exceptionCause(final Matcher<T> matcher) {
return (Matcher<T>) new BaseMatcher<Object>() {
@Override
public boolean matches(Object item) {
Throwable cause = null;
if(item != null && item instanceof Throwable) {
cause = ((Throwable)item).getCause();
}
return matcher.matches(cause);
}
@Override
public void describeTo(Description description) {
description.appendText("exception cause ").appendDescriptionOf(matcher);
}
};
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.build.test.mockito;
package org.springframework.tests;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2002-2013 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.tests;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
/**
* A test group used to limit when certain tests are run.
*
* @see Assume#group(TestGroup)
* @author Phillip Webb
*/
public enum TestGroup {
/**
* Performance related tests that may take a considerable time to run.
*/
PERFORMANCE;
/**
* Parse the specified comma separates string of groups.
* @param value the comma separated string of groups
* @return a set of groups
*/
public static Set<TestGroup> parse(String value) {
if (value == null || "".equals(value)) {
return Collections.emptySet();
}
if("ALL".equalsIgnoreCase(value)) {
return EnumSet.allOf(TestGroup.class);
}
Set<TestGroup> groups = new HashSet<TestGroup>();
for (String group : value.split(",")) {
try {
groups.add(valueOf(group.trim().toUpperCase()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unable to find test group '" + group.trim()
+ "' when parsing '" + value + "'");
}
}
return groups;
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2002-2013 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.tests;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Tests for {@link TestGroup}.
*
* @author Phillip Webb
*/
public class TestGroupTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void parseNull() throws Exception {
assertThat(TestGroup.parse(null), is(Collections.<TestGroup> emptySet()));
}
@Test
public void parseEmptyString() throws Exception {
assertThat(TestGroup.parse(""), is(Collections.<TestGroup> emptySet()));
}
@Test
public void parseWithSpaces() throws Exception {
assertThat(TestGroup.parse("PERFORMANCE, PERFORMANCE"),
is((Set<TestGroup>) EnumSet.of(TestGroup.PERFORMANCE)));
}
@Test
public void parseInMixedCase() throws Exception {
assertThat(TestGroup.parse("performance, PERFormaNCE"),
is((Set<TestGroup>) EnumSet.of(TestGroup.PERFORMANCE)));
}
@Test
public void parseMissing() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unable to find test group 'missing' when parsing 'performance, missing'");
TestGroup.parse("performance, missing");
}
@Test
public void parseAll() throws Exception {
assertThat(TestGroup.parse("all"), is((Set<TestGroup>)EnumSet.allOf(TestGroup.class)));
}
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2002-2013 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.
*/
/**
* Shared utilities that are used internally throughout the test suite but are not
* published. This package should not be confused with {@code org.springframework.test}
* which contains published code from the 'spring-test' module.
*/
package org.springframework.tests;

View File

@@ -19,7 +19,6 @@ package org.springframework.util;
import java.util.LinkedList;
import junit.framework.*;
import junit.framework.Assert;
import org.springframework.beans.TestBean;
@@ -72,14 +71,14 @@ public class AutoPopulatingListTests extends TestCase {
for(int x = 0; x < list.size(); x++) {
Object element = list.get(x);
if(element instanceof TestBean) {
junit.framework.Assert.assertEquals(x, ((TestBean) element).getAge());
assertEquals(x, ((TestBean) element).getAge());
}
}
}
public void testSerialization() throws Exception {
AutoPopulatingList<?> list = new AutoPopulatingList<Object>(TestBean.class);
Assert.assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list));
assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list));
}

View File

@@ -27,6 +27,7 @@ import junit.framework.TestCase;
* @author Keith Donald
* @author Juergen Hoeller
*/
@Deprecated
public class CachingMapDecoratorTests extends TestCase {
public void testValidCache() {

View File

@@ -41,6 +41,8 @@ import org.springframework.beans.TestBean;
*/
public class ClassUtilsTests extends TestCase {
private ClassLoader classLoader = getClass().getClassLoader();
@Override
public void setUp() {
InnerClass.noArgCalled = false;
@@ -49,56 +51,56 @@ public class ClassUtilsTests extends TestCase {
}
public void testIsPresent() throws Exception {
assertTrue(ClassUtils.isPresent("java.lang.String"));
assertFalse(ClassUtils.isPresent("java.lang.MySpecialString"));
assertTrue(ClassUtils.isPresent("java.lang.String", classLoader));
assertFalse(ClassUtils.isPresent("java.lang.MySpecialString", classLoader));
}
public void testForName() throws ClassNotFoundException {
assertEquals(String.class, ClassUtils.forName("java.lang.String"));
assertEquals(String[].class, ClassUtils.forName("java.lang.String[]"));
assertEquals(String[].class, ClassUtils.forName(String[].class.getName()));
assertEquals(String[][].class, ClassUtils.forName(String[][].class.getName()));
assertEquals(String[][][].class, ClassUtils.forName(String[][][].class.getName()));
assertEquals(TestBean.class, ClassUtils.forName("org.springframework.beans.TestBean"));
assertEquals(TestBean[].class, ClassUtils.forName("org.springframework.beans.TestBean[]"));
assertEquals(TestBean[].class, ClassUtils.forName(TestBean[].class.getName()));
assertEquals(TestBean[][].class, ClassUtils.forName("org.springframework.beans.TestBean[][]"));
assertEquals(TestBean[][].class, ClassUtils.forName(TestBean[][].class.getName()));
assertEquals(short[][][].class, ClassUtils.forName("[[[S"));
assertEquals(String.class, ClassUtils.forName("java.lang.String", classLoader));
assertEquals(String[].class, ClassUtils.forName("java.lang.String[]", classLoader));
assertEquals(String[].class, ClassUtils.forName(String[].class.getName(), classLoader));
assertEquals(String[][].class, ClassUtils.forName(String[][].class.getName(), classLoader));
assertEquals(String[][][].class, ClassUtils.forName(String[][][].class.getName(), classLoader));
assertEquals(TestBean.class, ClassUtils.forName("org.springframework.beans.TestBean", classLoader));
assertEquals(TestBean[].class, ClassUtils.forName("org.springframework.beans.TestBean[]", classLoader));
assertEquals(TestBean[].class, ClassUtils.forName(TestBean[].class.getName(), classLoader));
assertEquals(TestBean[][].class, ClassUtils.forName("org.springframework.beans.TestBean[][]", classLoader));
assertEquals(TestBean[][].class, ClassUtils.forName(TestBean[][].class.getName(), classLoader));
assertEquals(short[][][].class, ClassUtils.forName("[[[S", classLoader));
}
public void testForNameWithPrimitiveClasses() throws ClassNotFoundException {
assertEquals(boolean.class, ClassUtils.forName("boolean"));
assertEquals(byte.class, ClassUtils.forName("byte"));
assertEquals(char.class, ClassUtils.forName("char"));
assertEquals(short.class, ClassUtils.forName("short"));
assertEquals(int.class, ClassUtils.forName("int"));
assertEquals(long.class, ClassUtils.forName("long"));
assertEquals(float.class, ClassUtils.forName("float"));
assertEquals(double.class, ClassUtils.forName("double"));
assertEquals(void.class, ClassUtils.forName("void"));
assertEquals(boolean.class, ClassUtils.forName("boolean", classLoader));
assertEquals(byte.class, ClassUtils.forName("byte", classLoader));
assertEquals(char.class, ClassUtils.forName("char", classLoader));
assertEquals(short.class, ClassUtils.forName("short", classLoader));
assertEquals(int.class, ClassUtils.forName("int", classLoader));
assertEquals(long.class, ClassUtils.forName("long", classLoader));
assertEquals(float.class, ClassUtils.forName("float", classLoader));
assertEquals(double.class, ClassUtils.forName("double", classLoader));
assertEquals(void.class, ClassUtils.forName("void", classLoader));
}
public void testForNameWithPrimitiveArrays() throws ClassNotFoundException {
assertEquals(boolean[].class, ClassUtils.forName("boolean[]"));
assertEquals(byte[].class, ClassUtils.forName("byte[]"));
assertEquals(char[].class, ClassUtils.forName("char[]"));
assertEquals(short[].class, ClassUtils.forName("short[]"));
assertEquals(int[].class, ClassUtils.forName("int[]"));
assertEquals(long[].class, ClassUtils.forName("long[]"));
assertEquals(float[].class, ClassUtils.forName("float[]"));
assertEquals(double[].class, ClassUtils.forName("double[]"));
assertEquals(boolean[].class, ClassUtils.forName("boolean[]", classLoader));
assertEquals(byte[].class, ClassUtils.forName("byte[]", classLoader));
assertEquals(char[].class, ClassUtils.forName("char[]", classLoader));
assertEquals(short[].class, ClassUtils.forName("short[]", classLoader));
assertEquals(int[].class, ClassUtils.forName("int[]", classLoader));
assertEquals(long[].class, ClassUtils.forName("long[]", classLoader));
assertEquals(float[].class, ClassUtils.forName("float[]", classLoader));
assertEquals(double[].class, ClassUtils.forName("double[]", classLoader));
}
public void testForNameWithPrimitiveArraysInternalName() throws ClassNotFoundException {
assertEquals(boolean[].class, ClassUtils.forName(boolean[].class.getName()));
assertEquals(byte[].class, ClassUtils.forName(byte[].class.getName()));
assertEquals(char[].class, ClassUtils.forName(char[].class.getName()));
assertEquals(short[].class, ClassUtils.forName(short[].class.getName()));
assertEquals(int[].class, ClassUtils.forName(int[].class.getName()));
assertEquals(long[].class, ClassUtils.forName(long[].class.getName()));
assertEquals(float[].class, ClassUtils.forName(float[].class.getName()));
assertEquals(double[].class, ClassUtils.forName(double[].class.getName()));
assertEquals(boolean[].class, ClassUtils.forName(boolean[].class.getName(), classLoader));
assertEquals(byte[].class, ClassUtils.forName(byte[].class.getName(), classLoader));
assertEquals(char[].class, ClassUtils.forName(char[].class.getName(), classLoader));
assertEquals(short[].class, ClassUtils.forName(short[].class.getName(), classLoader));
assertEquals(int[].class, ClassUtils.forName(int[].class.getName(), classLoader));
assertEquals(long[].class, ClassUtils.forName(long[].class.getName(), classLoader));
assertEquals(float[].class, ClassUtils.forName(float[].class.getName(), classLoader));
assertEquals(double[].class, ClassUtils.forName(double[].class.getName(), classLoader));
}
public void testGetShortName() {

View File

@@ -31,10 +31,10 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.build.test.mockito.MockitoUtils;
import org.springframework.build.test.mockito.MockitoUtils.InvocationArgumentsAdapter;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.tests.MockitoUtils;
import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -16,8 +16,13 @@
package org.springframework.util.xml;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLEventReader;
@@ -28,7 +33,6 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamResult;
import static org.custommonkey.xmlunit.XMLAssert.*;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
@@ -101,4 +105,4 @@ public class StaxSourceTests {
transformer.transform(source, new DOMResult(result));
assertXMLEqual("Invalid result", expected, result);
}
}
}