diff --git a/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java b/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java index b467514b8a..31090c94ce 100644 --- a/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java +++ b/spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -22,26 +22,31 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Date; -import junit.framework.TestCase; import org.junit.Ignore; +import org.junit.Test; import org.springframework.tests.sample.objects.TestObject; +import static org.junit.Assert.*; + /** * @author Adrian Colyer */ -public class LocalVariableTableParameterNameDiscovererTests extends TestCase { +public class LocalVariableTableParameterNameDiscovererTests { - private LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); + private final LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); - public void testMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { + + @Test + public void methodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { Method getName = TestObject.class.getMethod("getName", new Class[0]); String[] names = discoverer.getParameterNames(getName); assertNotNull("should find method info", names); assertEquals("no argument names", 0, names.length); } - public void testMethodParameterNameDiscoveryWithArgs() throws NoSuchMethodException { + @Test + public void methodParameterNameDiscoveryWithArgs() throws NoSuchMethodException { Method setName = TestObject.class.getMethod("setName", new Class[] { String.class }); String[] names = discoverer.getParameterNames(setName); assertNotNull("should find method info", names); @@ -49,14 +54,16 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { assertEquals("name", names[0]); } - public void testConsParameterNameDiscoveryNoArgs() throws NoSuchMethodException { + @Test + public void consParameterNameDiscoveryNoArgs() throws NoSuchMethodException { Constructor noArgsCons = TestObject.class.getConstructor(new Class[0]); String[] names = discoverer.getParameterNames(noArgsCons); assertNotNull("should find cons info", names); assertEquals("no argument names", 0, names.length); } - public void testConsParameterNameDiscoveryArgs() throws NoSuchMethodException { + @Test + public void consParameterNameDiscoveryArgs() throws NoSuchMethodException { Constructor twoArgCons = TestObject.class.getConstructor(new Class[] { String.class, int.class }); String[] names = discoverer.getParameterNames(twoArgCons); assertNotNull("should find cons info", names); @@ -65,14 +72,16 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { assertEquals("age", names[1]); } - public void testStaticMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { + @Test + public void staticMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException { Method m = getClass().getMethod("staticMethodNoLocalVars", new Class[0]); String[] names = discoverer.getParameterNames(m); assertNotNull("should find method info", names); assertEquals("no argument names", 0, names.length); } - public void testOverloadedStaticMethod() throws Exception { + @Test + public void overloadedStaticMethod() throws Exception { Class clazz = this.getClass(); Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE, Long.TYPE }); @@ -91,7 +100,8 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { assertEquals("z", names[2]); } - public void testOverloadedStaticMethodInInnerClass() throws Exception { + @Test + public void overloadedStaticMethodInInnerClass() throws Exception { Class clazz = InnerClass.class; Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE }); @@ -108,7 +118,8 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { assertEquals("y", names[1]); } - public void testOverloadedMethod() throws Exception { + @Test + public void overloadedMethod() throws Exception { Class clazz = this.getClass(); Method m1 = clazz.getMethod("instanceMethod", new Class[] { Double.TYPE, Double.TYPE }); @@ -127,7 +138,8 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { assertEquals("z", names[2]); } - public void testOverloadedMethodInInnerClass() throws Exception { + @Test + public void overloadedMethodInInnerClass() throws Exception { Class clazz = InnerClass.class; Method m1 = clazz.getMethod("instanceMethod", new Class[] { String.class }); @@ -144,8 +156,9 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { assertEquals("bb", names[1]); } - public void testGenerifiedClass() throws Exception { - Class clazz = (Class)GenerifiedClass.class; + @Test + public void generifiedClass() throws Exception { + Class clazz = GenerifiedClass.class; Constructor ctor = clazz.getDeclaredConstructor(Object.class); String[] names = discoverer.getParameterNames(ctor); @@ -188,16 +201,11 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { m = clazz.getMethod("getDate"); names = discoverer.getParameterNames(m); assertEquals(0, names.length); - - //System.in.read(); } - /** - * Ignored because Ubuntu packages OpenJDK with debug symbols enabled. - * See SPR-8078. - */ - @Ignore - public void ignore_testClassesWithoutDebugSymbols() throws Exception { + @Ignore("Ignored because Ubuntu packages OpenJDK with debug symbols enabled. See SPR-8078.") + @Test + public void classesWithoutDebugSymbols() throws Exception { // JDK classes don't have debug information (usually) Class clazz = Component.class; String methodName = "list"; @@ -213,8 +221,6 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase { m = clazz.getMethod(methodName, PrintStream.class, int.class); names = discoverer.getParameterNames(m); assertNull(names); - - //System.in.read(); } public static void staticMethodNoLocalVars() { diff --git a/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java b/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java index 19c16d1512..5220945677 100644 --- a/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java +++ b/spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -20,69 +20,72 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.Arrays; -import junit.framework.TestCase; - +import org.junit.Test; import org.springframework.tests.sample.objects.TestObject; -public class PrioritizedParameterNameDiscovererTests extends TestCase { +import static org.junit.Assert.*; + +public class PrioritizedParameterNameDiscovererTests { private static final String[] FOO_BAR = new String[] { "foo", "bar" }; private static final String[] SOMETHING_ELSE = new String[] { "something", "else" }; - ParameterNameDiscoverer returnsFooBar = new ParameterNameDiscoverer() { + private final ParameterNameDiscoverer returnsFooBar = new ParameterNameDiscoverer() { @Override public String[] getParameterNames(Method m) { return FOO_BAR; } @Override - public String[] getParameterNames(Constructor ctor) { + public String[] getParameterNames(Constructor ctor) { return FOO_BAR; } }; - ParameterNameDiscoverer returnsSomethingElse = new ParameterNameDiscoverer() { + private final ParameterNameDiscoverer returnsSomethingElse = new ParameterNameDiscoverer() { @Override public String[] getParameterNames(Method m) { return SOMETHING_ELSE; } @Override - public String[] getParameterNames(Constructor ctor) { + public String[] getParameterNames(Constructor ctor) { return SOMETHING_ELSE; } }; private final Method anyMethod; - private final Class anyClass = Object.class; public PrioritizedParameterNameDiscovererTests() throws SecurityException, NoSuchMethodException { anyMethod = TestObject.class.getMethod("getAge", (Class[]) null); } - public void testNoParametersDiscoverers() { + @Test + public void noParametersDiscoverers() { ParameterNameDiscoverer pnd = new PrioritizedParameterNameDiscoverer(); assertNull(pnd.getParameterNames(anyMethod)); - assertNull(pnd.getParameterNames((Constructor) null)); + assertNull(pnd.getParameterNames((Constructor) null)); } - public void testOrderedParameterDiscoverers1() { + @Test + public void orderedParameterDiscoverers1() { PrioritizedParameterNameDiscoverer pnd = new PrioritizedParameterNameDiscoverer(); pnd.addDiscoverer(returnsFooBar); assertTrue(Arrays.equals(FOO_BAR, pnd.getParameterNames(anyMethod))); - assertTrue(Arrays.equals(FOO_BAR, pnd.getParameterNames((Constructor) null))); + assertTrue(Arrays.equals(FOO_BAR, pnd.getParameterNames((Constructor) null))); pnd.addDiscoverer(returnsSomethingElse); assertTrue(Arrays.equals(FOO_BAR, pnd.getParameterNames(anyMethod))); - assertTrue(Arrays.equals(FOO_BAR, pnd.getParameterNames((Constructor) null))); + assertTrue(Arrays.equals(FOO_BAR, pnd.getParameterNames((Constructor) null))); } - public void testOrderedParameterDiscoverers2() { + @Test + public void orderedParameterDiscoverers2() { PrioritizedParameterNameDiscoverer pnd = new PrioritizedParameterNameDiscoverer(); pnd.addDiscoverer(returnsSomethingElse); assertTrue(Arrays.equals(SOMETHING_ELSE, pnd.getParameterNames(anyMethod))); - assertTrue(Arrays.equals(SOMETHING_ELSE, pnd.getParameterNames((Constructor) null))); + assertTrue(Arrays.equals(SOMETHING_ELSE, pnd.getParameterNames((Constructor) null))); pnd.addDiscoverer(returnsFooBar); assertTrue(Arrays.equals(SOMETHING_ELSE, pnd.getParameterNames(anyMethod))); - assertTrue(Arrays.equals(SOMETHING_ELSE, pnd.getParameterNames((Constructor) null))); + assertTrue(Arrays.equals(SOMETHING_ELSE, pnd.getParameterNames((Constructor) null))); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java index 08010cfb5e..5069806b49 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.test.web.servlet.result; import java.nio.charset.Charset; import org.hamcrest.Matchers; + import org.junit.Test; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.StubMvcResult; import org.springframework.util.StreamUtils; -import org.springframework.util.StringUtils; /** * Tests for {@link XpathResultMatchers}. @@ -33,77 +34,77 @@ import org.springframework.util.StringUtils; public class XpathResultMatchersTests { @Test - public void testNodeMatcher() throws Exception { + public void node() throws Exception { new XpathResultMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testNodeMatcherNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void nodeNoMatch() throws Exception { new XpathResultMatchers("/foo/bar", null).node(Matchers.nullValue()).match(getStubMvcResult()); } @Test - public void testExists() throws Exception { + public void exists() throws Exception { new XpathResultMatchers("/foo/bar", null).exists().match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testExistsNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void existsNoMatch() throws Exception { new XpathResultMatchers("/foo/Bar", null).exists().match(getStubMvcResult()); } @Test - public void testDoesNotExist() throws Exception { + public void doesNotExist() throws Exception { new XpathResultMatchers("/foo/Bar", null).doesNotExist().match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testDoesNotExistNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void doesNotExistNoMatch() throws Exception { new XpathResultMatchers("/foo/bar", null).doesNotExist().match(getStubMvcResult()); } @Test - public void testNodeCount() throws Exception { + public void nodeCount() throws Exception { new XpathResultMatchers("/foo/bar", null).nodeCount(2).match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testNodeCountNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void nodeCountNoMatch() throws Exception { new XpathResultMatchers("/foo/bar", null).nodeCount(1).match(getStubMvcResult()); } @Test - public void testString() throws Exception { + public void string() throws Exception { new XpathResultMatchers("/foo/bar[1]", null).string("111").match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testStringNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void stringNoMatch() throws Exception { new XpathResultMatchers("/foo/bar[1]", null).string("112").match(getStubMvcResult()); } @Test - public void testNumber() throws Exception { + public void number() throws Exception { new XpathResultMatchers("/foo/bar[1]", null).number(111.0).match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testNumberNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void numberNoMatch() throws Exception { new XpathResultMatchers("/foo/bar[1]", null).number(111.1).match(getStubMvcResult()); } @Test - public void testBoolean() throws Exception { + public void booleanValue() throws Exception { new XpathResultMatchers("/foo/bar[2]", null).booleanValue(true).match(getStubMvcResult()); } - @Test(expected=AssertionError.class) - public void testBooleanNoMatch() throws Exception { + @Test(expected = AssertionError.class) + public void booleanValueNoMatch() throws Exception { new XpathResultMatchers("/foo/bar[2]", null).booleanValue(false).match(getStubMvcResult()); } @Test - public void testStringEncodingDetection() throws Exception { + public void stringEncodingDetection() throws Exception { String content = "\n" + "Jürgen"; byte[] bytes = content.getBytes(Charset.forName("UTF-8"));