Suppressing warnings, polishing JavaDoc, etc.
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.core.enums.ShortCodedLabeledEnum;
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
@SuppressWarnings({ "serial", "deprecation" })
|
||||
public class Colour extends ShortCodedLabeledEnum {
|
||||
|
||||
public static final Colour RED = new Colour(0, "RED");
|
||||
@@ -28,6 +29,7 @@ public class Colour extends ShortCodedLabeledEnum {
|
||||
public static final Colour GREEN = new Colour(2, "GREEN");
|
||||
public static final Colour PURPLE = new Colour(3, "PURPLE");
|
||||
|
||||
|
||||
private Colour(int code, String label) {
|
||||
super(code, label);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.TreeSet;
|
||||
* @author Juergen Hoeller
|
||||
* @since 11.11.2003
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class IndexedTestBean {
|
||||
|
||||
private TestBean[] array;
|
||||
@@ -57,6 +58,7 @@ public class IndexedTestBean {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void populate() {
|
||||
TestBean tb0 = new TestBean("name0", 0);
|
||||
TestBean tb1 = new TestBean("name1", 0);
|
||||
@@ -68,7 +70,7 @@ public class IndexedTestBean {
|
||||
TestBean tb7 = new TestBean("name7", 0);
|
||||
TestBean tbX = new TestBean("nameX", 0);
|
||||
TestBean tbY = new TestBean("nameY", 0);
|
||||
this.array = new TestBean[] {tb0, tb1};
|
||||
this.array = new TestBean[] { tb0, tb1 };
|
||||
this.list = new ArrayList();
|
||||
this.list.add(tb2);
|
||||
this.list.add(tb3);
|
||||
@@ -85,7 +87,6 @@ public class IndexedTestBean {
|
||||
this.map.put("key4", list);
|
||||
}
|
||||
|
||||
|
||||
public TestBean[] getArray() {
|
||||
return array;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Simple test bean used for testing bean factories, the AOP framework etc.
|
||||
*
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @since 15 April 2001
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable {
|
||||
|
||||
private String beanName;
|
||||
@@ -107,7 +108,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
|
||||
public TestBean(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouses = new ITestBean[] { spouse };
|
||||
}
|
||||
|
||||
public TestBean(String name, int age) {
|
||||
@@ -116,7 +117,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
|
||||
public TestBean(ITestBean spouse, Properties someProperties) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouses = new ITestBean[] { spouse };
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
@@ -136,7 +137,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
|
||||
public void setSpouse(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouses = new ITestBean[] { spouse };
|
||||
}
|
||||
|
||||
public ITestBean[] getSpouses() {
|
||||
@@ -366,7 +366,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see ITestBean#exceptional(Throwable)
|
||||
*/
|
||||
@@ -379,6 +378,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
public void unreliableFileOperation() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ITestBean#returnsThis()
|
||||
*/
|
||||
@@ -396,7 +396,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
return age++;
|
||||
}
|
||||
|
||||
|
||||
public void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
@@ -405,7 +404,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
||||
String headerName = "Header1";
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader(headerName, "value1");
|
||||
Enumeration requestHeaders = request.getHeaderNames();
|
||||
Enumeration<String> requestHeaders = request.getHeaderNames();
|
||||
assertNotNull(requestHeaders);
|
||||
assertEquals("HTTP header casing not being preserved", headerName, requestHeaders.nextElement());
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setParameter("key1", "value1");
|
||||
request.setParameter("key2", "value2");
|
||||
Map params = new HashMap(2);
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("key1", "newValue1");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.setParameters(params);
|
||||
@@ -59,7 +59,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setParameter("key1", "value1");
|
||||
request.setParameter("key2", "value2");
|
||||
Map params = new HashMap(2);
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("key1", "newValue1");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
@@ -77,7 +77,7 @@ public class MockHttpServletRequestTests extends TestCase {
|
||||
public void testRemoveAllParameters() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setParameter("key1", "value1");
|
||||
Map params = new HashMap(2);
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
params.put("key2", "value2");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
|
||||
@@ -34,8 +34,8 @@ public class MockHttpServletResponseTests extends TestCase {
|
||||
public void testSetContentTypeWithNoEncoding() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setContentType("test/plain");
|
||||
assertEquals("Character encoding should be the default",
|
||||
WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
|
||||
assertEquals("Character encoding should be the default", WebUtils.DEFAULT_CHARACTER_ENCODING,
|
||||
response.getCharacterEncoding());
|
||||
}
|
||||
|
||||
public void testSetContentTypeWithUTF8() {
|
||||
@@ -49,7 +49,7 @@ public class MockHttpServletResponseTests extends TestCase {
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.addHeader(headerName, "value1");
|
||||
Set responseHeaders = response.getHeaderNames();
|
||||
Set<String> responseHeaders = response.getHeaderNames();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(1, responseHeaders.size());
|
||||
assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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.
|
||||
@@ -24,10 +24,11 @@ import org.springframework.context.ApplicationContext;
|
||||
* Abstract JUnit 3.8 based unit test which verifies new functionality requested
|
||||
* in <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-3550"
|
||||
* target="_blank">SPR-3350</a>.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private Pet cat;
|
||||
@@ -48,8 +49,9 @@ public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDe
|
||||
/**
|
||||
* Forcing concrete subclasses to provide a config path appropriate to the
|
||||
* configured
|
||||
* {@link #createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext) BeanDefinitionReader}.
|
||||
*
|
||||
* {@link #createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext)
|
||||
* BeanDefinitionReader}.
|
||||
*
|
||||
* @see org.springframework.test.AbstractSingleSpringContextTests#getConfigPath()
|
||||
*/
|
||||
protected abstract String getConfigPath();
|
||||
@@ -62,12 +64,11 @@ public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDe
|
||||
* {@link AbstractSingleSpringContextTests} always uses an
|
||||
* {@link XmlBeanDefinitionReader} internally when creating the
|
||||
* {@link ApplicationContext} inside
|
||||
* {@link #createApplicationContext(String[])}. It would be nice to have
|
||||
* the bean definition reader creation in a separate method so that
|
||||
* subclasses can choose that individually without having to copy-n-paste
|
||||
* code from createApplicationContext() to do the context creation and
|
||||
* refresh. Consider JavaConfig where an Annotation based reader can be
|
||||
* plugged in.
|
||||
* {@link #createApplicationContext(String[])}. It would be nice to have the
|
||||
* bean definition reader creation in a separate method so that subclasses
|
||||
* can choose that individually without having to copy-n-paste code from
|
||||
* createApplicationContext() to do the context creation and refresh.
|
||||
* Consider JavaConfig where an Annotation based reader can be plugged in.
|
||||
* </p>
|
||||
*/
|
||||
public final void testApplicationContextNotAutoCreated() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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,11 +20,12 @@ package org.springframework.test;
|
||||
* JUnit 3.8 based unit test which verifies new functionality requested in <a
|
||||
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3264"
|
||||
* target="_blank">SPR-3264</a>.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see Spr3264SingleSpringContextTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Spr3264DependencyInjectionSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
public Spr3264DependencyInjectionSpringContextTests() {
|
||||
@@ -50,7 +51,7 @@ public class Spr3264DependencyInjectionSpringContextTests extends AbstractDepend
|
||||
// Re-assert issues covered by Spr3264SingleSpringContextTests as a
|
||||
// safety net.
|
||||
assertNull("The ApplicationContext should NOT be automatically created if no 'locations' are defined.",
|
||||
this.applicationContext);
|
||||
this.applicationContext);
|
||||
assertEquals("Verifying the ApplicationContext load count.", 0, super.getLoadCount());
|
||||
|
||||
// Assert changes to AbstractDependencyInjectionSpringContextTests:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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,11 +20,12 @@ package org.springframework.test;
|
||||
* JUnit 3.8 based unit test which verifies new functionality requested in <a
|
||||
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3264"
|
||||
* target="_blank">SPR-3264</a>.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see Spr3264DependencyInjectionSpringContextTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Spr3264SingleSpringContextTests extends AbstractSingleSpringContextTests {
|
||||
|
||||
public Spr3264SingleSpringContextTests() {
|
||||
@@ -47,7 +48,7 @@ public class Spr3264SingleSpringContextTests extends AbstractSingleSpringContext
|
||||
*/
|
||||
public void testApplicationContextNotAutoCreated() {
|
||||
assertNull("The ApplicationContext should NOT be automatically created if no 'locations' are defined.",
|
||||
super.applicationContext);
|
||||
super.applicationContext);
|
||||
assertEquals("Verifying the ApplicationContext load count.", 0, super.getLoadCount());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import junit.framework.TestResult;
|
||||
* Verifies proper handling of {@link IfProfileValue @IfProfileValue} and
|
||||
* {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration} in
|
||||
* conjunction with {@link AbstractAnnotationAwareTransactionalTests}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@@ -46,11 +46,11 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
|
||||
testCase.setName(testName);
|
||||
TestResult testResult = testCase.run();
|
||||
assertEquals("Verifying number of invocations for test method [" + testName + "].", expectedInvocationCount,
|
||||
testCase.invocationCount);
|
||||
testCase.invocationCount);
|
||||
assertEquals("Verifying number of errors for test method [" + testName + "].", expectedErrorCount,
|
||||
testResult.errorCount());
|
||||
testResult.errorCount());
|
||||
assertEquals("Verifying number of failures for test method [" + testName + "].", expectedFailureCount,
|
||||
testResult.failureCount());
|
||||
testResult.failureCount());
|
||||
}
|
||||
|
||||
private void runTests(Class<? extends DefaultProfileValueSourceTestCase> testCaseType) throws Exception {
|
||||
@@ -64,21 +64,23 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
|
||||
|
||||
public void testDefaultProfileValueSource() throws Exception {
|
||||
assertEquals("Verifying the type of the configured ProfileValueSource.", SystemProfileValueSource.class,
|
||||
new DefaultProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
new DefaultProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
runTests(DefaultProfileValueSourceTestCase.class);
|
||||
}
|
||||
|
||||
public void testHardCodedProfileValueSource() throws Exception {
|
||||
assertEquals("Verifying the type of the configured ProfileValueSource.", HardCodedProfileValueSource.class,
|
||||
new HardCodedProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
new HardCodedProfileValueSourceTestCase().getProfileValueSource().getClass());
|
||||
runTests(HardCodedProfileValueSourceTestCase.class);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected static class DefaultProfileValueSourceTestCase extends AbstractAnnotationAwareTransactionalTests {
|
||||
|
||||
int invocationCount = 0;
|
||||
|
||||
|
||||
public DefaultProfileValueSourceTestCase() {
|
||||
}
|
||||
|
||||
@@ -130,12 +132,10 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ProfileValueSourceConfiguration(HardCodedProfileValueSource.class)
|
||||
protected static class HardCodedProfileValueSourceTestCase extends DefaultProfileValueSourceTestCase {
|
||||
}
|
||||
|
||||
|
||||
public static class HardCodedProfileValueSource implements ProfileValueSource {
|
||||
|
||||
public String get(String key) {
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProfileValueUtils}.
|
||||
@@ -32,7 +30,6 @@ import org.junit.runners.JUnit4;
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class ProfileValueUtilsTests {
|
||||
|
||||
private static final String NON_ANNOTATED_METHOD = "nonAnnotatedMethod";
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.internal.runners.JUnit38ClassRunner;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.Employee;
|
||||
import org.springframework.beans.Pet;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
@@ -42,10 +41,11 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
/**
|
||||
* Combined unit test for {@link AbstractJUnit38SpringContextTests} and
|
||||
* {@link AbstractTransactionalJUnit38SpringContextTests}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@RunWith(JUnit38ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTransactionalJUnit38SpringContextTests
|
||||
@@ -142,13 +142,13 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
||||
@NotTransactional
|
||||
public void testApplicationContextSet() {
|
||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
||||
super.applicationContext);
|
||||
super.applicationContext);
|
||||
}
|
||||
|
||||
@NotTransactional
|
||||
public void testBeanInitialized() {
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||
this.beanInitialized);
|
||||
this.beanInitialized);
|
||||
}
|
||||
|
||||
@NotTransactional
|
||||
@@ -184,7 +184,7 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
||||
public void beforeTransaction() {
|
||||
this.inTransaction = true;
|
||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
assertEquals("Adding yoda", 1, addPerson(super.simpleJdbcTemplate, YODA));
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
||||
assertEquals("Adding jane", 1, addPerson(super.simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(super.simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within transactionalMethod2().", 4,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,7 +211,7 @@ public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTran
|
||||
public void afterTransaction() {
|
||||
assertEquals("Deleting yoda", 1, deletePerson(super.simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Abstract base class for verifying support of Spring's
|
||||
* {@link Transactional @Transactional} and
|
||||
* {@link NotTransactional @NotTransactional} annotations.
|
||||
*
|
||||
* Abstract base class for verifying support of Spring's {@link Transactional
|
||||
* @Transactional} and {@link NotTransactional @NotTransactional}
|
||||
* annotations.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see ClassLevelTransactionalSpringRunnerTests
|
||||
@@ -34,7 +34,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @see Transactional
|
||||
* @see NotTransactional
|
||||
*/
|
||||
@ContextConfiguration(locations = {"transactionalTests-context.xml"})
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration("transactionalTests-context.xml")
|
||||
public abstract class AbstractTransactionalSpringRunnerTests {
|
||||
|
||||
protected static final String BOB = "bob";
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -40,11 +39,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
/**
|
||||
* <p>
|
||||
* JUnit 4 based unit test which verifies support of Spring's
|
||||
* {@link Transactional @Transactional},
|
||||
* {@link NotTransactional @NotTransactional},
|
||||
* {@link TestExecutionListeners @TestExecutionListeners}, and
|
||||
* {@link ContextConfiguration @ContextConfiguration} annotations in conjunction
|
||||
* with the {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link Transactional @Transactional}, {@link NotTransactional
|
||||
* @NotTransactional}, {@link TestExecutionListeners
|
||||
* @TestExecutionListeners}, and {@link ContextConfiguration
|
||||
* @ContextConfiguration} annotations in conjunction with the
|
||||
* {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link TestExecutionListener TestExecutionListeners}:
|
||||
* </p>
|
||||
* <ul>
|
||||
@@ -56,11 +55,12 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* This class specifically tests usage of <code>@Transactional</code>
|
||||
* defined at the <strong>class level</strong>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see MethodLevelTransactionalSpringRunnerTests
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@Transactional
|
||||
@@ -72,7 +72,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
||||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -80,10 +80,9 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
||||
clearPersonTable(simpleJdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
@@ -91,7 +90,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,7 +101,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
||||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import javax.sql.DataSource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.Employee;
|
||||
import org.springframework.beans.Pet;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
@@ -46,10 +45,11 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
/**
|
||||
* Combined unit test for {@link AbstractJUnit4SpringContextTests} and
|
||||
* {@link AbstractTransactionalJUnit4SpringContextTests}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration
|
||||
public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTransactionalJUnit4SpringContextTests
|
||||
implements BeanNameAware, InitializingBean {
|
||||
@@ -61,7 +61,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
protected static final String LEIA = "leia";
|
||||
protected static final String YODA = "yoda";
|
||||
|
||||
|
||||
private boolean beanInitialized = false;
|
||||
|
||||
private String beanName = "replace me with [" + getClass().getName() + "]";
|
||||
@@ -105,7 +104,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
super.setDataSource(dataSource);
|
||||
@@ -129,13 +127,12 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
this.beanInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public final void verifyApplicationContext() {
|
||||
assertInTransaction(false);
|
||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
||||
super.applicationContext);
|
||||
super.applicationContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,7 +140,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
public final void verifyBeanInitialized() {
|
||||
assertInTransaction(false);
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||
this.beanInitialized);
|
||||
this.beanInitialized);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,18 +182,17 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
|
||||
}
|
||||
|
||||
|
||||
@BeforeTransaction
|
||||
public void beforeTransaction() {
|
||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
assertEquals("Adding yoda", 1, addPerson(super.simpleJdbcTemplate, YODA));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
assertEquals("Verifying the number of rows in the person table before a test method.",
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,20 +201,20 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
assertEquals("Adding jane", 1, addPerson(super.simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(super.simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().", 4,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
assertEquals("Verifying the number of rows in the person table after a test method.",
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
public void afterTransaction() {
|
||||
assertEquals("Deleting yoda", 1, deletePerson(super.simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
|
||||
package org.springframework.test.context.junit4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListener;
|
||||
@@ -32,17 +33,15 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* JUnit 4 based unit test which verifies support of Spring's
|
||||
* {@link Transactional @Transactional},
|
||||
* {@link TestExecutionListeners @TestExecutionListeners}, and
|
||||
* {@link ContextConfiguration @ContextConfiguration} annotations in conjunction
|
||||
* with the {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link Transactional @Transactional}, {@link TestExecutionListeners
|
||||
* @TestExecutionListeners}, and {@link ContextConfiguration
|
||||
* @ContextConfiguration} annotations in conjunction with the
|
||||
* {@link SpringJUnit4ClassRunner} and the following
|
||||
* {@link TestExecutionListener TestExecutionListeners}:
|
||||
* </p>
|
||||
* <ul>
|
||||
@@ -56,15 +55,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* {@link ClassLevelTransactionalSpringRunnerTests}, this class omits usage of
|
||||
* <code>@NotTransactional</code>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see ClassLevelTransactionalSpringRunnerTests
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class})
|
||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||
TransactionalTestExecutionListener.class })
|
||||
public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
||||
|
||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
@@ -73,7 +72,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
||||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -81,7 +80,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
||||
clearPersonTable(simpleJdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +91,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,7 +101,7 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
||||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
countRowsInPersonTable(simpleJdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.springframework.test.transaction.TransactionTestUtils.assertIn
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.annotation.Timed;
|
||||
@@ -29,16 +28,17 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* JUnit 4 based unit test which verifies support of Spring's
|
||||
* {@link Transactional @Transactional} and
|
||||
* {@link NotTransactional @NotTransactional} annotations in conjunction with
|
||||
* {@link Timed @Timed} and JUnit 4's {@link Test#timeout() timeout} attribute.
|
||||
*
|
||||
* {@link Transactional @Transactional} and {@link NotTransactional
|
||||
* @NotTransactional} annotations in conjunction with {@link Timed
|
||||
* @Timed} and JUnit 4's {@link Test#timeout() timeout} attribute.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = {"transactionalTests-context.xml"})
|
||||
@ContextConfiguration("transactionalTests-context.xml")
|
||||
@Transactional
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TimedTransactionalSpringRunnerTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.testng.annotations.Test;
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration
|
||||
public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTransactionalTestNGSpringContextTests
|
||||
implements BeanNameAware, InitializingBean {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2011 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,59 +16,62 @@
|
||||
|
||||
package org.springframework.test.jdbc;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JdbcTestUtils}.
|
||||
*
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @since 2.5.4
|
||||
*/
|
||||
public class JdbcTestUtilsTests extends TestCase {
|
||||
public class JdbcTestUtilsTests {
|
||||
|
||||
public void testContainsDelimiters() {
|
||||
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
|
||||
assertTrue("test with delimiter ; is wrong", JdbcTestUtils.containsSqlScriptDelimiters("select 1; select 2", ';'));
|
||||
assertTrue("test with '\\n' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1; select '\\n\n';", '\n'));
|
||||
assertTrue("test with delimiter \\n is wrong", JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select 2", '\n'));
|
||||
@Test
|
||||
public void containsDelimiters() {
|
||||
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
|
||||
assertTrue("test with delimiter ; is wrong",
|
||||
JdbcTestUtils.containsSqlScriptDelimiters("select 1; select 2", ';'));
|
||||
assertTrue("test with '\\n' is wrong",
|
||||
!JdbcTestUtils.containsSqlScriptDelimiters("select 1; select '\\n\n';", '\n'));
|
||||
assertTrue("test with delimiter \\n is wrong",
|
||||
JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select 2", '\n'));
|
||||
}
|
||||
|
||||
public void testSplitSqlScriptDelimitedWithSemicolon() {
|
||||
String statement1 = "insert into customer (id, name) \n" +
|
||||
"values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) \n" +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
@Test
|
||||
public void splitSqlScriptDelimitedWithSemicolon() {
|
||||
String statement1 = "insert into customer (id, name) \n"
|
||||
+ "values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) \n" + "values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
|
||||
char delim = ';';
|
||||
String script = statement1 + delim + statement2 + delim + statement3;
|
||||
List statements = new ArrayList();
|
||||
List<String> statements = new ArrayList<String>();
|
||||
JdbcTestUtils.splitSqlScript(script, delim, statements);
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
|
||||
}
|
||||
|
||||
public void testSplitSqlScriptDelimitedWithNewLine() {
|
||||
String statement1 = "insert into customer (id, name) " +
|
||||
"values (1, 'Rod ; Johnson'), (2, 'Adrian ; Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) " +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " +
|
||||
"values (1, '2008-01-02', 2)";
|
||||
@Test
|
||||
public void splitSqlScriptDelimitedWithNewLine() {
|
||||
String statement1 = "insert into customer (id, name) " + "values (1, 'Rod ; Johnson'), (2, 'Adrian ; Collier')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
|
||||
char delim = '\n';
|
||||
String script = statement1 + delim + statement2 + delim + statement3;
|
||||
List statements = new ArrayList();
|
||||
List<String> statements = new ArrayList<String>();
|
||||
JdbcTestUtils.splitSqlScript(script, delim, statements);
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -23,10 +23,11 @@ import org.springframework.test.util.subpackage.Person;
|
||||
|
||||
/**
|
||||
* JUnit 3.8 based unit tests for {@link ReflectionTestUtils}.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ReflectionTestUtilsTests extends TestCase {
|
||||
|
||||
protected static final Float PI = new Float((float) 22 / 7);
|
||||
@@ -48,11 +49,11 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
assertEquals("Verifying that the person's name (protected field) was set.", "Tom", person.getName());
|
||||
assertEquals("Verifying that the person's age (private field) was set.", 42, person.getAge());
|
||||
assertEquals("Verifying that the person's eye color (package private field) was set.", "blue",
|
||||
person.getEyeColor());
|
||||
person.getEyeColor());
|
||||
assertEquals("Verifying that the person's 'likes pets' flag (package private boolean field) was set.", true,
|
||||
person.likesPets());
|
||||
person.likesPets());
|
||||
assertEquals("Verifying that the person's 'favorite number' (package field) was set.", PI,
|
||||
person.getFavoriteNumber());
|
||||
person.getFavoriteNumber());
|
||||
|
||||
assertEquals(new Long(99), ReflectionTestUtils.getField(person, "id"));
|
||||
assertEquals("Tom", ReflectionTestUtils.getField(person, "name"));
|
||||
@@ -74,7 +75,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
// Null - primitives
|
||||
|
||||
new AssertThrows(IllegalArgumentException.class,
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.setField(person, "id", null, long.class);
|
||||
@@ -82,7 +83,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
}.runTest();
|
||||
|
||||
new AssertThrows(IllegalArgumentException.class,
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.setField(person, "age", null, int.class);
|
||||
@@ -90,7 +91,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
}.runTest();
|
||||
|
||||
new AssertThrows(IllegalArgumentException.class,
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling setField() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.setField(person, "likesPets", null, boolean.class);
|
||||
@@ -114,11 +115,11 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
assertEquals("Verifying that the person's name (private method) was set.", "Tom", person.getName());
|
||||
assertEquals("Verifying that the person's age (protected method) was set.", 42, person.getAge());
|
||||
assertEquals("Verifying that the person's eye color (package private method) was set.", "blue",
|
||||
person.getEyeColor());
|
||||
person.getEyeColor());
|
||||
assertEquals("Verifying that the person's 'likes pets' flag (protected method for a boolean) was set.", true,
|
||||
person.likesPets());
|
||||
person.likesPets());
|
||||
assertEquals("Verifying that the person's 'favorite number' (protected method for a Number) was set.", PI,
|
||||
person.getFavoriteNumber());
|
||||
person.getFavoriteNumber());
|
||||
|
||||
assertEquals(new Long(99), ReflectionTestUtils.invokeGetterMethod(person, "id"));
|
||||
assertEquals("Tom", ReflectionTestUtils.invokeGetterMethod(person, "name"));
|
||||
@@ -140,11 +141,11 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
assertEquals("Verifying that the person's name (private method) was set.", "Jerry", person.getName());
|
||||
assertEquals("Verifying that the person's age (protected method) was set.", 33, person.getAge());
|
||||
assertEquals("Verifying that the person's eye color (package private method) was set.", "green",
|
||||
person.getEyeColor());
|
||||
person.getEyeColor());
|
||||
assertEquals("Verifying that the person's 'likes pets' flag (protected method for a boolean) was set.", false,
|
||||
person.likesPets());
|
||||
person.likesPets());
|
||||
assertEquals("Verifying that the person's 'favorite number' (protected method for a Number) was set.",
|
||||
new Integer(42), person.getFavoriteNumber());
|
||||
new Integer(42), person.getFavoriteNumber());
|
||||
|
||||
assertEquals(new Long(1), ReflectionTestUtils.invokeGetterMethod(person, "getId"));
|
||||
assertEquals("Jerry", ReflectionTestUtils.invokeGetterMethod(person, "getName"));
|
||||
@@ -162,12 +163,12 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
assertNull("Verifying that the person's name (private method) was set.", person.getName());
|
||||
assertNull("Verifying that the person's eye color (package private method) was set.", person.getEyeColor());
|
||||
assertNull("Verifying that the person's 'favorite number' (protected method for a Number) was set.",
|
||||
person.getFavoriteNumber());
|
||||
person.getFavoriteNumber());
|
||||
|
||||
// Null - primitives
|
||||
|
||||
new AssertThrows(RuntimeException.class,
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.invokeSetterMethod(person, "id", null, long.class);
|
||||
@@ -175,7 +176,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
}.runTest();
|
||||
|
||||
new AssertThrows(RuntimeException.class,
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.invokeSetterMethod(person, "age", null, int.class);
|
||||
@@ -183,7 +184,7 @@ public class ReflectionTestUtilsTests extends TestCase {
|
||||
}.runTest();
|
||||
|
||||
new AssertThrows(RuntimeException.class,
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
"Calling invokeSetterMethod() with NULL for a primitive type should throw an IllegalArgumentException.") {
|
||||
|
||||
public void test() throws Exception {
|
||||
ReflectionTestUtils.invokeSetterMethod(person, "likesPets", null, boolean.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2007-2011 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.
|
||||
@@ -21,7 +21,7 @@ import org.springframework.core.style.ToStringCreator;
|
||||
/**
|
||||
* Concrete subclass of {@link PersistentEntity} representing a <em>person</em>
|
||||
* entity; intended for use in unit tests.
|
||||
*
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
@@ -42,6 +42,7 @@ public class Person extends PersistentEntity {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.springframework.web.multipart;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
@@ -25,8 +30,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.mock.web.MockMultipartHttpServletRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -35,9 +39,10 @@ import org.springframework.util.ObjectUtils;
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class MockMultipartHttpServletRequestTests extends TestCase {
|
||||
public class MockMultipartHttpServletRequestTests {
|
||||
|
||||
public void testMockMultipartHttpServletRequestWithByteArray() throws IOException {
|
||||
@Test
|
||||
public void mockMultipartHttpServletRequestWithByteArray() throws IOException {
|
||||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
assertFalse(request.getFileNames().hasNext());
|
||||
assertNull(request.getFile("file1"));
|
||||
@@ -49,16 +54,18 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
|
||||
doTestMultipartHttpServletRequest(request);
|
||||
}
|
||||
|
||||
public void testMockMultipartHttpServletRequestWithInputStream() throws IOException {
|
||||
@Test
|
||||
public void mockMultipartHttpServletRequestWithInputStream() throws IOException {
|
||||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
request.addFile(new MockMultipartFile("file1", new ByteArrayInputStream("myContent1".getBytes())));
|
||||
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream("myContent2".getBytes())));
|
||||
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream(
|
||||
"myContent2".getBytes())));
|
||||
doTestMultipartHttpServletRequest(request);
|
||||
}
|
||||
|
||||
private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
|
||||
Set fileNames = new HashSet();
|
||||
Iterator fileIter = request.getFileNames();
|
||||
Set<String> fileNames = new HashSet<String>();
|
||||
Iterator<String> fileIter = request.getFileNames();
|
||||
while (fileIter.hasNext()) {
|
||||
fileNames.add(fileIter.next());
|
||||
}
|
||||
@@ -67,8 +74,8 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
|
||||
assertTrue(fileNames.contains("file2"));
|
||||
MultipartFile file1 = request.getFile("file1");
|
||||
MultipartFile file2 = request.getFile("file2");
|
||||
Map fileMap = request.getFileMap();
|
||||
List fileMapKeys = new LinkedList(fileMap.keySet());
|
||||
Map<String, MultipartFile> fileMap = request.getFileMap();
|
||||
List<String> fileMapKeys = new LinkedList<String>(fileMap.keySet());
|
||||
assertEquals(2, fileMapKeys.size());
|
||||
assertEquals(file1, fileMap.get("file1"));
|
||||
assertEquals(file2, fileMap.get("file2"));
|
||||
@@ -77,12 +84,14 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
|
||||
assertEquals("", file1.getOriginalFilename());
|
||||
assertNull(file1.getContentType());
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), FileCopyUtils.copyToByteArray(file1.getInputStream())));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file1.getInputStream())));
|
||||
assertEquals("file2", file2.getName());
|
||||
assertEquals("myOrigFilename", file2.getOriginalFilename());
|
||||
assertEquals("text/plain", file2.getContentType());
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), FileCopyUtils.copyToByteArray(file2.getInputStream())));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file2.getInputStream())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user