polishing .beans tests

This commit is contained in:
Chris Beams 2008-12-24 22:02:08 +00:00
parent 46722fa946
commit d116c8733a
11 changed files with 75 additions and 30 deletions

View File

@ -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

View File

@ -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<Problem> errors = new ArrayList<Problem>();
private List warnings = new ArrayList();
private List<Problem> warnings = new ArrayList<Problem>();
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()]);
}
}

View File

@ -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.

View File

@ -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);

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;