From d116c8733a121855b703b989a2867251bdc633a1 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 24 Dec 2008 22:02:08 +0000 Subject: [PATCH] polishing .beans tests --- .../ConstructorArgumentEntryTests.java | 4 +-- .../CustomProblemReporterTests-context.xml} | 0 .../parsing/CustomProblemReporterTests.java | 32 ++++++++++++------- .../parsing/FailFastProblemReporterTests.java | 2 +- .../parsing/NullSourceExtractorTests.java | 11 +++++-- .../factory/parsing/ParseStateTests.java | 10 ++++-- .../PassThroughSourceExtractorTests.java | 19 ++++++++--- .../factory/parsing/PropertyEntryTests.java | 18 ++++++++++- .../CollectingReaderEventListener.java | 7 +++- .../factory/xml/EventPublicationTests.java | 1 - .../xml/UtilNamespaceHandlerTests.java | 1 - 11 files changed, 75 insertions(+), 30 deletions(-) rename org.springframework.beans/src/test/{resources/org/springframework/beans/factory/parsing/withErrors.xml => java/org/springframework/beans/factory/parsing/CustomProblemReporterTests-context.xml} (100%) rename org.springframework.beans/src/test/java/org/springframework/beans/factory/{parsing => xml}/CollectingReaderEventListener.java (87%) diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java index c578c4ee0cd..b15728e6697 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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. @@ -19,7 +19,7 @@ package org.springframework.beans.factory.parsing; import org.junit.Test; /** - * Unit tests for the {@link ConstructorArgumentEntry} class. + * Unit tests for {@link ConstructorArgumentEntry}. * * @author Rick Evans * @author Chris Beams diff --git a/org.springframework.beans/src/test/resources/org/springframework/beans/factory/parsing/withErrors.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests-context.xml similarity index 100% rename from org.springframework.beans/src/test/resources/org/springframework/beans/factory/parsing/withErrors.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests-context.xml diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java index 61f404c2ade..774fb0b5a83 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 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,22 +16,28 @@ package org.springframework.beans.factory.parsing; +import static org.junit.Assert.*; +import static test.util.TestResourceUtils.qualifiedResource; + import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - +import org.junit.Before; +import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import test.beans.TestBean; /** * @author Rob Harrop + * @author Chris Beams * @since 2.0 */ -public class CustomProblemReporterTests extends TestCase { +public final class CustomProblemReporterTests { + + private static final Resource CONTEXT = qualifiedResource(CustomProblemReporterTests.class, "context.xml"); private CollatingProblemReporter problemReporter; @@ -40,15 +46,17 @@ public class CustomProblemReporterTests extends TestCase { private XmlBeanDefinitionReader reader; - protected void setUp() throws Exception { + @Before + public void setUp() { this.problemReporter = new CollatingProblemReporter(); this.beanFactory = new DefaultListableBeanFactory(); this.reader = new XmlBeanDefinitionReader(this.beanFactory); this.reader.setProblemReporter(this.problemReporter); } - public void testErrorsAreCollated() throws Exception { - this.reader.loadBeanDefinitions(new ClassPathResource("withErrors.xml", getClass())); + @Test + public void testErrorsAreCollated() { + this.reader.loadBeanDefinitions(CONTEXT); assertEquals("Incorrect number of errors collated", 4, this.problemReporter.getErrors().length); TestBean bean = (TestBean) this.beanFactory.getBean("validBean"); @@ -58,9 +66,9 @@ public class CustomProblemReporterTests extends TestCase { private static class CollatingProblemReporter implements ProblemReporter { - private List errors = new ArrayList(); + private List errors = new ArrayList(); - private List warnings = new ArrayList(); + private List warnings = new ArrayList(); public void fatal(Problem problem) { @@ -73,7 +81,7 @@ public class CustomProblemReporterTests extends TestCase { } public Problem[] getErrors() { - return (Problem[]) this.errors.toArray(new Problem[this.errors.size()]); + return this.errors.toArray(new Problem[this.errors.size()]); } public void warning(Problem problem) { @@ -82,7 +90,7 @@ public class CustomProblemReporterTests extends TestCase { } public Problem[] getWarnings() { - return (Problem[]) this.warnings.toArray(new Problem[this.warnings.size()]); + return this.warnings.toArray(new Problem[this.warnings.size()]); } } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java index e111f224f21..3ebe8ec705a 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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. diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java index 708331ed73c..5241e7662f2 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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,19 +16,24 @@ package org.springframework.beans.factory.parsing; -import junit.framework.TestCase; +import static org.junit.Assert.*; + +import org.junit.Test; /** * @author Rick Evans + * @author Chris Beams */ -public final class NullSourceExtractorTests extends TestCase { +public final class NullSourceExtractorTests { + @Test public void testPassThroughContract() throws Exception { Object source = new Object(); Object extractedSource = new NullSourceExtractor().extractSource(source, null); assertNull("The contract of NullSourceExtractor states that the extraction *always* return null", extractedSource); } + @Test public void testPassThroughContractEvenWithNull() throws Exception { Object extractedSource = new NullSourceExtractor().extractSource(null, null); assertNull("The contract of NullSourceExtractor states that the extraction *always* return null", extractedSource); diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java index 8a2b58788c6..746d0c933b0 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java @@ -16,16 +16,18 @@ package org.springframework.beans.factory.parsing; -import junit.framework.TestCase; +import static org.junit.Assert.*; -import org.springframework.beans.factory.parsing.ParseState; +import org.junit.Test; /** * @author Rob Harrop + * @author Chris Beams * @since 2.0 */ -public class ParseStateTests extends TestCase { +public class ParseStateTests { + @Test public void testSimple() throws Exception { MockEntry entry = new MockEntry(); @@ -36,6 +38,7 @@ public class ParseStateTests extends TestCase { assertNull("Should get null on peek()", parseState.peek()); } + @Test public void testNesting() throws Exception { MockEntry one = new MockEntry(); MockEntry two = new MockEntry(); @@ -55,6 +58,7 @@ public class ParseStateTests extends TestCase { assertEquals(one, parseState.peek()); } + @Test public void testSnapshot() throws Exception { MockEntry entry = new MockEntry(); diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java index b65e047b473..c8d5e9c1ec7 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2008 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,22 +16,31 @@ package org.springframework.beans.factory.parsing; -import junit.framework.TestCase; +import static org.junit.Assert.*; + +import org.junit.Test; /** + * Unit tests for {@link PassThroughSourceExtractor}. + * * @author Rick Evans + * @author Chris Beams */ -public final class PassThroughSourceExtractorTests extends TestCase { +public final class PassThroughSourceExtractorTests { + @Test public void testPassThroughContract() throws Exception { Object source = new Object(); Object extractedSource = new PassThroughSourceExtractor().extractSource(source, null); - assertSame("The contract of PassThroughSourceExtractor states that the supplied source object *must* be returned as-is", source, extractedSource); + assertSame("The contract of PassThroughSourceExtractor states that the supplied " + + "source object *must* be returned as-is", source, extractedSource); } + @Test public void testPassThroughContractEvenWithNull() throws Exception { Object extractedSource = new PassThroughSourceExtractor().extractSource(null, null); - assertNull("The contract of PassThroughSourceExtractor states that the supplied source object *must* be returned as-is (even if null)", extractedSource); + assertNull("The contract of PassThroughSourceExtractor states that the supplied " + + "source object *must* be returned as-is (even if null)", extractedSource); } } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java index 7109aafb7e0..6a807d313ab 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java @@ -1,9 +1,25 @@ +/* + * Copyright 2002-2008 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.beans.factory.parsing; import org.junit.Test; /** - * Unit tests for the {@link PropertyEntry} class. + * Unit tests for {@link PropertyEntry}. * * @author Rick Evans * @author Chris Beams diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CollectingReaderEventListener.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/CollectingReaderEventListener.java similarity index 87% rename from org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CollectingReaderEventListener.java rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/CollectingReaderEventListener.java index e2bfda3f1d6..2be0637cf69 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/parsing/CollectingReaderEventListener.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/CollectingReaderEventListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.beans.factory.parsing; +package org.springframework.beans.factory.xml; import java.util.ArrayList; import java.util.Collection; @@ -23,6 +23,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.springframework.beans.factory.parsing.AliasDefinition; +import org.springframework.beans.factory.parsing.ComponentDefinition; +import org.springframework.beans.factory.parsing.DefaultsDefinition; +import org.springframework.beans.factory.parsing.ImportDefinition; +import org.springframework.beans.factory.parsing.ReaderEventListener; import org.springframework.core.CollectionFactory; /** diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java index b2c34a77578..a9e9925d512 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.parsing.AliasDefinition; import org.springframework.beans.factory.parsing.BeanComponentDefinition; -import org.springframework.beans.factory.parsing.CollectingReaderEventListener; import org.springframework.beans.factory.parsing.ComponentDefinition; import org.springframework.beans.factory.parsing.ImportDefinition; import org.springframework.beans.factory.parsing.PassThroughSourceExtractor; diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java index bd0c7c99df2..e1861ee8255 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java @@ -25,7 +25,6 @@ import java.util.TreeMap; import junit.framework.TestCase; -import org.springframework.beans.factory.parsing.CollectingReaderEventListener; import org.springframework.beans.factory.parsing.ComponentDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.DefaultListableBeanFactory;