You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/12 20:03:33 UTC
svn commit: r1102402 [14/20] - in /commons/sandbox/digester3/trunk/src:
main/java/org/apache/commons/digester3/
main/java/org/apache/commons/digester3/annotations/
main/java/org/apache/commons/digester3/annotations/handlers/
main/java/org/apache/common...
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/DigesterTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/DigesterTestCase.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/DigesterTestCase.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/DigesterTestCase.java Thu May 12 18:03:26 2011
@@ -16,7 +16,6 @@
* limitations under the License.
*/
-
package org.apache.commons.digester3;
import static org.junit.Assert.assertEquals;
@@ -50,249 +49,260 @@ import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.AttributesImpl;
-
/**
- * <p>Test Case for the Digester class. These tests exercise the individual
- * methods of a Digester, but do not attempt to process complete documents.
+ * <p>
+ * Test Case for the Digester class. These tests exercise the individual methods of a Digester, but do not attempt to
+ * process complete documents.
* </p>
- *
+ *
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/
-public class DigesterTestCase {
-
+public class DigesterTestCase
+{
// ----------------------------------------------------- Instance Variables
-
/**
* The digester instance we will be processing.
*/
protected Digester digester = null;
-
/**
- * The set of public identifiers, and corresponding resource names,
- * for the versions of the DTDs that we know about. There
- * <strong>MUST</strong> be an even number of Strings in this array.
- */
- protected static final String registrations[] = {
- "-//Netscape Communications//DTD RSS 0.9//EN",
- "/org/apache/commons/digester3/rss/rss-0.9.dtd",
- "-//Netscape Communications//DTD RSS 0.91//EN",
- "/org/apache/commons/digester3/rss/rss-0.91.dtd",
- };
-
+ * The set of public identifiers, and corresponding resource names, for the versions of the DTDs that we know about.
+ * There <strong>MUST</strong> be an even number of Strings in this array.
+ */
+ protected static final String registrations[] = { "-//Netscape Communications//DTD RSS 0.9//EN",
+ "/org/apache/commons/digester3/rss/rss-0.9.dtd", "-//Netscape Communications//DTD RSS 0.91//EN",
+ "/org/apache/commons/digester3/rss/rss-0.91.dtd", };
// -------------------------------------------------- Overall Test Methods
-
/**
* Set up instance variables required by this test case.
*/
@Before
- public void setUp() {
+ public void setUp()
+ {
digester = new Digester();
- digester.setRules(new RulesBase());
+ digester.setRules( new RulesBase() );
}
-
/**
* Tear down instance variables required by this test case.
*/
@After
- public void tearDown() {
+ public void tearDown()
+ {
digester = null;
}
-
-
// ------------------------------------------------ Individual Test Methods
-
/**
- * Test <code>null</code> parsing.
- * (should lead to <code>IllegalArgumentException</code>s)
+ * Test <code>null</code> parsing. (should lead to <code>IllegalArgumentException</code>s)
*/
@Test
- public void testNullFileParse() throws Exception {
+ public void testNullFileParse()
+ throws Exception
+ {
- try {
- digester.parse((File) null);
- fail("Expected IllegalArgumentException with null argument");
- } catch (IllegalArgumentException e) {
+ try
+ {
+ digester.parse( (File) null );
+ fail( "Expected IllegalArgumentException with null argument" );
+ }
+ catch ( IllegalArgumentException e )
+ {
// expected
}
}
@Test
- public void testNullInputSourceParse() throws Exception {
+ public void testNullInputSourceParse()
+ throws Exception
+ {
- try {
- digester.parse((InputSource) null);
- fail("Expected IllegalArgumentException with null argument");
- } catch (IllegalArgumentException e) {
+ try
+ {
+ digester.parse( (InputSource) null );
+ fail( "Expected IllegalArgumentException with null argument" );
+ }
+ catch ( IllegalArgumentException e )
+ {
// expected
}
}
@Test
- public void testNullInputStreamParse() throws Exception {
+ public void testNullInputStreamParse()
+ throws Exception
+ {
- try {
- digester.parse((InputStream) null);
- fail("Expected IllegalArgumentException with null argument");
- } catch (IllegalArgumentException e) {
+ try
+ {
+ digester.parse( (InputStream) null );
+ fail( "Expected IllegalArgumentException with null argument" );
+ }
+ catch ( IllegalArgumentException e )
+ {
// expected
}
}
@Test
- public void testNullReaderParse() throws Exception {
+ public void testNullReaderParse()
+ throws Exception
+ {
- try {
- digester.parse((Reader) null);
- fail("Expected IllegalArgumentException with null argument");
- } catch (IllegalArgumentException e) {
+ try
+ {
+ digester.parse( (Reader) null );
+ fail( "Expected IllegalArgumentException with null argument" );
+ }
+ catch ( IllegalArgumentException e )
+ {
// expected
}
}
@Test
- public void testNullStringParse() throws Exception {
+ public void testNullStringParse()
+ throws Exception
+ {
- try {
- digester.parse((String) null);
- fail("Expected IllegalArgumentException with null argument");
- } catch (IllegalArgumentException e) {
+ try
+ {
+ digester.parse( (String) null );
+ fail( "Expected IllegalArgumentException with null argument" );
+ }
+ catch ( IllegalArgumentException e )
+ {
// expected
}
}
@Test
- public void testNullURLParse() throws Exception {
+ public void testNullURLParse()
+ throws Exception
+ {
- try {
- digester.parse((URL) null);
- fail("Expected IllegalArgumentException with null argument");
- } catch (IllegalArgumentException e) {
+ try
+ {
+ digester.parse( (URL) null );
+ fail( "Expected IllegalArgumentException with null argument" );
+ }
+ catch ( IllegalArgumentException e )
+ {
// expected
}
}
-
/**
* Test the basic property getters and setters.
*/
@Test
- public void testProperties() {
+ public void testProperties()
+ {
- assertNull("Initial error handler is null",
- digester.getErrorHandler());
- digester.setErrorHandler(digester);
- assertTrue("Set error handler is digester",
- digester.getErrorHandler() == digester);
- digester.setErrorHandler(null);
- assertNull("Reset error handler is null",
- digester.getErrorHandler());
-
- assertTrue("Initial namespace aware is false",
- !digester.getNamespaceAware());
- digester.setNamespaceAware(true);
- assertTrue("Set namespace aware is true",
- digester.getNamespaceAware());
- digester.setNamespaceAware(false);
- assertTrue("Reset namespace aware is false",
- !digester.getNamespaceAware());
-
- assertTrue("Initial validating is false",
- !digester.getValidating());
- digester.setValidating(true);
- assertTrue("Set validating is true",
- digester.getValidating());
- digester.setValidating(false);
- assertTrue("Reset validating is false",
- !digester.getValidating());
+ assertNull( "Initial error handler is null", digester.getErrorHandler() );
+ digester.setErrorHandler( digester );
+ assertTrue( "Set error handler is digester", digester.getErrorHandler() == digester );
+ digester.setErrorHandler( null );
+ assertNull( "Reset error handler is null", digester.getErrorHandler() );
+
+ assertTrue( "Initial namespace aware is false", !digester.getNamespaceAware() );
+ digester.setNamespaceAware( true );
+ assertTrue( "Set namespace aware is true", digester.getNamespaceAware() );
+ digester.setNamespaceAware( false );
+ assertTrue( "Reset namespace aware is false", !digester.getNamespaceAware() );
+
+ assertTrue( "Initial validating is false", !digester.getValidating() );
+ digester.setValidating( true );
+ assertTrue( "Set validating is true", digester.getValidating() );
+ digester.setValidating( false );
+ assertTrue( "Reset validating is false", !digester.getValidating() );
}
-
/**
* Test registration of URLs for specified public identifiers.
*/
@Test
- public void testRegistrations() {
+ public void testRegistrations()
+ {
Map<String, URL> map = digester.getRegistrations();
- assertEquals("Initially zero registrations", 0, map.size());
+ assertEquals( "Initially zero registrations", 0, map.size() );
int n = 0;
- for (int i = 0; i < registrations.length; i += 2) {
- URL url = this.getClass().getResource(registrations[i + 1]);
- if (url != null) {
- digester.register(registrations[i], url);
+ for ( int i = 0; i < registrations.length; i += 2 )
+ {
+ URL url = this.getClass().getResource( registrations[i + 1] );
+ if ( url != null )
+ {
+ digester.register( registrations[i], url );
n++;
}
}
map = digester.getRegistrations();
- assertEquals("Registered two URLs", n, map.size());
+ assertEquals( "Registered two URLs", n, map.size() );
int count[] = new int[n];
- for (int i = 0; i < n; i++)
+ for ( int i = 0; i < n; i++ )
count[i] = 0;
- for (String key : map.keySet()) {
- for (int i = 0; i < n; i++) {
- if (key.equals(registrations[i * 2])) {
+ for ( String key : map.keySet() )
+ {
+ for ( int i = 0; i < n; i++ )
+ {
+ if ( key.equals( registrations[i * 2] ) )
+ {
count[i]++;
break;
}
}
}
- for (int i = 0; i < n; i++)
- assertEquals("Count for key " + registrations[i * 2],
- 1, count[i]);
+ for ( int i = 0; i < n; i++ )
+ assertEquals( "Count for key " + registrations[i * 2], 1, count[i] );
}
-
/**
* Basic test for rule creation and matching.
*/
@Test
- public void testRules() {
+ public void testRules()
+ {
- assertEquals("Initial rules list is empty",
- 0, digester.getRules().match(null, "a").size());
- digester.addSetProperties("a");
- assertEquals("Add a matching rule",
- 1, digester.getRules().match(null, "a").size());
- digester.addSetProperties("b");
- assertEquals("Add a non-matching rule",
- 1, digester.getRules().match(null, "a").size());
- digester.addSetProperties("a/b");
- assertEquals("Add a non-matching nested rule",
- 1, digester.getRules().match(null, "a").size());
- digester.addSetProperties("a/b");
- assertEquals("Add a second matching rule",
- 2, digester.getRules().match(null, "a/b").size());
+ assertEquals( "Initial rules list is empty", 0, digester.getRules().match( null, "a" ).size() );
+ digester.addSetProperties( "a" );
+ assertEquals( "Add a matching rule", 1, digester.getRules().match( null, "a" ).size() );
+ digester.addSetProperties( "b" );
+ assertEquals( "Add a non-matching rule", 1, digester.getRules().match( null, "a" ).size() );
+ digester.addSetProperties( "a/b" );
+ assertEquals( "Add a non-matching nested rule", 1, digester.getRules().match( null, "a" ).size() );
+ digester.addSetProperties( "a/b" );
+ assertEquals( "Add a second matching rule", 2, digester.getRules().match( null, "a/b" ).size() );
}
-
/**
- * <p>Test matching rules in {@link RulesBase}.</p>
- *
- * <p>Tests:</p>
+ * <p>
+ * Test matching rules in {@link RulesBase}.
+ * </p>
+ * <p>
+ * Tests:
+ * </p>
* <ul>
* <li>exact match</li>
* <li>tail match</li>
@@ -300,204 +310,223 @@ public class DigesterTestCase {
* </ul>
*/
@Test
- public void testRulesBase() {
+ public void testRulesBase()
+ {
- assertEquals("Initial rules list is empty",
- 0, digester.getRules().rules().size());
+ assertEquals( "Initial rules list is empty", 0, digester.getRules().rules().size() );
// We're going to set up
- digester.addRule("a/b/c/d", new TestRule("a/b/c/d"));
- digester.addRule("*/d", new TestRule("*/d"));
- digester.addRule("*/c/d", new TestRule("*/c/d"));
+ digester.addRule( "a/b/c/d", new TestRule( "a/b/c/d" ) );
+ digester.addRule( "*/d", new TestRule( "*/d" ) );
+ digester.addRule( "*/c/d", new TestRule( "*/c/d" ) );
// Test exact match
- assertEquals("Exact match takes precedence 1",
- 1, digester.getRules().match(null, "a/b/c/d").size());
- assertEquals("Exact match takes precedence 2",
- "a/b/c/d",
- ((TestRule) digester.getRules().match(null, "a/b/c/d").iterator().next()).getIdentifier());
+ assertEquals( "Exact match takes precedence 1", 1, digester.getRules().match( null, "a/b/c/d" ).size() );
+ assertEquals( "Exact match takes precedence 2", "a/b/c/d",
+ ( (TestRule) digester.getRules().match( null, "a/b/c/d" ).iterator().next() ).getIdentifier() );
// Test wildcard tail matching
- assertEquals("Wildcard tail matching rule 1",
- 1, digester.getRules().match(null, "a/b/d").size());
- assertEquals("Wildcard tail matching rule 2",
- "*/d",
- ((TestRule) digester.getRules().match(null, "a/b/d").iterator().next()).getIdentifier());
+ assertEquals( "Wildcard tail matching rule 1", 1, digester.getRules().match( null, "a/b/d" ).size() );
+ assertEquals( "Wildcard tail matching rule 2", "*/d",
+ ( (TestRule) digester.getRules().match( null, "a/b/d" ).iterator().next() ).getIdentifier() );
// Test the longest matching pattern rule
- assertEquals("Longest tail rule 1",
- 1, digester.getRules().match(null, "x/c/d").size());
- assertEquals("Longest tail rule 2",
- "*/c/d",
- ((TestRule) digester.getRules().match(null, "x/c/d").iterator().next()).getIdentifier());
+ assertEquals( "Longest tail rule 1", 1, digester.getRules().match( null, "x/c/d" ).size() );
+ assertEquals( "Longest tail rule 2", "*/c/d",
+ ( (TestRule) digester.getRules().match( null, "x/c/d" ).iterator().next() ).getIdentifier() );
}
-
/**
* Test the basic stack mechanisms.
*/
@Test
- public void testStackMethods() {
+ public void testStackMethods()
+ {
Object value = null;
// New stack must be empty
- assertEquals("New stack is empty", 0, digester.getCount());
+ assertEquals( "New stack is empty", 0, digester.getCount() );
value = digester.peek();
- assertNull("New stack peek() returns null", value);
+ assertNull( "New stack peek() returns null", value );
value = digester.pop();
- assertNull("New stack pop() returns null", value);
+ assertNull( "New stack pop() returns null", value );
// Test pushing and popping activities
- digester.push("First Item");
- assertEquals("Pushed one item size", 1, digester.getCount());
+ digester.push( "First Item" );
+ assertEquals( "Pushed one item size", 1, digester.getCount() );
value = digester.peek();
- assertNotNull("Peeked first item is not null", value);
- assertEquals("Peeked first item value", "First Item", (String) value);
+ assertNotNull( "Peeked first item is not null", value );
+ assertEquals( "Peeked first item value", "First Item", (String) value );
- digester.push("Second Item");
- assertEquals("Pushed two items size", 2, digester.getCount());
+ digester.push( "Second Item" );
+ assertEquals( "Pushed two items size", 2, digester.getCount() );
value = digester.peek();
- assertNotNull("Peeked second item is not null", value);
- assertEquals("Peeked second item value", "Second Item", (String) value);
+ assertNotNull( "Peeked second item is not null", value );
+ assertEquals( "Peeked second item value", "Second Item", (String) value );
value = digester.pop();
- assertEquals("Popped stack size", 1, digester.getCount());
- assertNotNull("Popped second item is not null", value);
- assertEquals("Popped second item value", "Second Item", (String) value);
+ assertEquals( "Popped stack size", 1, digester.getCount() );
+ assertNotNull( "Popped second item is not null", value );
+ assertEquals( "Popped second item value", "Second Item", (String) value );
value = digester.peek();
- assertNotNull("Remaining item is not null", value);
- assertEquals("Remaining item value", "First Item", (String) value);
- assertEquals("Remaining stack size", 1, digester.getCount());
+ assertNotNull( "Remaining item is not null", value );
+ assertEquals( "Remaining item value", "First Item", (String) value );
+ assertEquals( "Remaining stack size", 1, digester.getCount() );
// Cleared stack is empty
- digester.push("Dummy Item");
+ digester.push( "Dummy Item" );
digester.clear();
- assertEquals("Cleared stack is empty", 0, digester.getCount());
+ assertEquals( "Cleared stack is empty", 0, digester.getCount() );
value = digester.peek();
- assertNull("Cleared stack peek() returns null", value);
+ assertNull( "Cleared stack peek() returns null", value );
value = digester.pop();
- assertNull("Cleared stack pop() returns null", value);
+ assertNull( "Cleared stack pop() returns null", value );
}
@Test
- public void testOnceAndOnceOnly() throws Exception {
-
- class TestConfigureDigester extends Digester {
- public int called=0;
- public TestConfigureDigester() {}
-
+ public void testOnceAndOnceOnly()
+ throws Exception
+ {
+
+ class TestConfigureDigester
+ extends Digester
+ {
+ public int called = 0;
+
+ public TestConfigureDigester()
+ {
+ }
+
@Override
- protected void initialize() {
+ protected void initialize()
+ {
called++;
}
}
-
+
TestConfigureDigester digester = new TestConfigureDigester();
-
+
String xml = "<?xml version='1.0'?><document/>";
- digester.parse(new StringReader(xml));
-
- assertEquals("Initialize should be called once and only once", 1, digester.called);
+ digester.parse( new StringReader( xml ) );
+
+ assertEquals( "Initialize should be called once and only once", 1, digester.called );
}
@Test
- public void testBasicSubstitution() throws Exception {
- class TestSubRule extends Rule {
+ public void testBasicSubstitution()
+ throws Exception
+ {
+ class TestSubRule
+ extends Rule
+ {
public String body;
+
public Attributes attributes;
-
+
@Override
- public void begin(String namespace, String name, Attributes attributes) {
- this.attributes = new AttributesImpl(attributes);
+ public void begin( String namespace, String name, Attributes attributes )
+ {
+ this.attributes = new AttributesImpl( attributes );
}
-
+
@Override
- public void body(String namespace, String name, String text) {
+ public void body( String namespace, String name, String text )
+ {
this.body = text;
}
}
-
+
TestSubRule tsr = new TestSubRule();
Digester digester = new Digester();
- digester.addRule("alpha/beta", tsr);
-
+ digester.addRule( "alpha/beta", tsr );
+
// it's not easy to transform dirty harry into the mighty circus - but let's give it a try
- String xml = "<?xml version='1.0'?><alpha><beta forname='Dirty' surname='Harry'>Do you feel luck punk?</beta></alpha>";
- InputSource in = new InputSource(new StringReader(xml));
-
- digester.parse(in);
-
- assertEquals("Unsubstituted body text", "Do you feel luck punk?", tsr.body);
- assertEquals("Unsubstituted number of attributes", 2, tsr.attributes.getLength());
- assertEquals("Unsubstituted forname attribute value", "Dirty", tsr.attributes.getValue("forname"));
- assertEquals("Unsubstituted surname attribute value", "Harry", tsr.attributes.getValue("surname"));
-
- digester.setSubstitutor(
- new Substitutor() {
- @Override
- public Attributes substitute(Attributes attributes) {
- AttributesImpl results = new AttributesImpl();
- results.addAttribute("", "python", "python", "CDATA", "Cleese");
- return results;
- }
-
- @Override
- public String substitute(String bodyText) {
- return "And now for something completely different...";
- }
- });
-
+ String xml =
+ "<?xml version='1.0'?><alpha><beta forname='Dirty' surname='Harry'>Do you feel luck punk?</beta></alpha>";
+ InputSource in = new InputSource( new StringReader( xml ) );
+
+ digester.parse( in );
+
+ assertEquals( "Unsubstituted body text", "Do you feel luck punk?", tsr.body );
+ assertEquals( "Unsubstituted number of attributes", 2, tsr.attributes.getLength() );
+ assertEquals( "Unsubstituted forname attribute value", "Dirty", tsr.attributes.getValue( "forname" ) );
+ assertEquals( "Unsubstituted surname attribute value", "Harry", tsr.attributes.getValue( "surname" ) );
+
+ digester.setSubstitutor( new Substitutor()
+ {
+ @Override
+ public Attributes substitute( Attributes attributes )
+ {
+ AttributesImpl results = new AttributesImpl();
+ results.addAttribute( "", "python", "python", "CDATA", "Cleese" );
+ return results;
+ }
+
+ @Override
+ public String substitute( String bodyText )
+ {
+ return "And now for something completely different...";
+ }
+ } );
+
// now transform into the full monty
- in = new InputSource(new StringReader(xml));
- digester.parse(in);
-
- assertEquals("Substituted body text", "And now for something completely different...", tsr.body);
- assertEquals("Substituted number of attributes", 1, tsr.attributes.getLength());
- assertEquals("Substituted python attribute value", "Cleese", tsr.attributes.getValue("", "python"));
+ in = new InputSource( new StringReader( xml ) );
+ digester.parse( in );
+
+ assertEquals( "Substituted body text", "And now for something completely different...", tsr.body );
+ assertEquals( "Substituted number of attributes", 1, tsr.attributes.getLength() );
+ assertEquals( "Substituted python attribute value", "Cleese", tsr.attributes.getValue( "", "python" ) );
}
-
+
/** Tests the push-peek-pop cycle for a named stack */
@Test
- public void testNamedStackPushPeekPop() throws Exception
+ public void testNamedStackPushPeekPop()
+ throws Exception
{
- BigDecimal archimedesAveragePi = new BigDecimal("3.1418");
+ BigDecimal archimedesAveragePi = new BigDecimal( "3.1418" );
String testStackName = "org.apache.commons.digester3.tests.testNamedStackPushPeekPop";
Digester digester = new Digester();
- assertTrue("Stack starts empty:", digester.isEmpty(testStackName));
- digester.push(testStackName, archimedesAveragePi);
- assertEquals("Peeked value:", archimedesAveragePi, digester.peek(testStackName));
- assertEquals("Popped value:", archimedesAveragePi, digester.pop(testStackName));
- assertTrue("Stack ends empty:", digester.isEmpty(testStackName));
-
- digester.push(testStackName, "1");
- digester.push(testStackName, "2");
- digester.push(testStackName, "3");
-
- assertEquals("Peek#1", "1", digester.peek(testStackName, 2));
- assertEquals("Peek#2", "2", digester.peek(testStackName, 1));
- assertEquals("Peek#3", "3", digester.peek(testStackName, 0));
- assertEquals("Peek#3a", "3", digester.peek(testStackName));
-
- try {
+ assertTrue( "Stack starts empty:", digester.isEmpty( testStackName ) );
+ digester.push( testStackName, archimedesAveragePi );
+ assertEquals( "Peeked value:", archimedesAveragePi, digester.peek( testStackName ) );
+ assertEquals( "Popped value:", archimedesAveragePi, digester.pop( testStackName ) );
+ assertTrue( "Stack ends empty:", digester.isEmpty( testStackName ) );
+
+ digester.push( testStackName, "1" );
+ digester.push( testStackName, "2" );
+ digester.push( testStackName, "3" );
+
+ assertEquals( "Peek#1", "1", digester.peek( testStackName, 2 ) );
+ assertEquals( "Peek#2", "2", digester.peek( testStackName, 1 ) );
+ assertEquals( "Peek#3", "3", digester.peek( testStackName, 0 ) );
+ assertEquals( "Peek#3a", "3", digester.peek( testStackName ) );
+
+ try
+ {
// peek beyond stack
- digester.peek(testStackName, 3);
- fail("Peek#4 failed to throw an exception.");
- } catch(EmptyStackException ex) {
+ digester.peek( testStackName, 3 );
+ fail( "Peek#4 failed to throw an exception." );
+ }
+ catch ( EmptyStackException ex )
+ {
// ok, expected
}
-
- try {
+
+ try
+ {
// peek a nonexistent named stack
- digester.peek("no.such.stack", 0);
- fail("Peeking a non-existent stack failed to throw an exception.");
- } catch(EmptyStackException ex) {
+ digester.peek( "no.such.stack", 0 );
+ fail( "Peeking a non-existent stack failed to throw an exception." );
+ }
+ catch ( EmptyStackException ex )
+ {
// ok, expected
}
}
-
+
/** Tests that values are stored independently */
@Test
public void testNamedIndependence()
@@ -505,102 +534,116 @@ public class DigesterTestCase {
String testStackOneName = "org.apache.commons.digester3.tests.testNamedIndependenceOne";
String testStackTwoName = "org.apache.commons.digester3.tests.testNamedIndependenceTwo";
Digester digester = new Digester();
- digester.push(testStackOneName, "Tweedledum");
- digester.push(testStackTwoName, "Tweedledee");
- assertEquals("Popped value one:", "Tweedledum", digester.pop(testStackOneName));
- assertEquals("Popped value two:", "Tweedledee", digester.pop(testStackTwoName));
+ digester.push( testStackOneName, "Tweedledum" );
+ digester.push( testStackTwoName, "Tweedledee" );
+ assertEquals( "Popped value one:", "Tweedledum", digester.pop( testStackOneName ) );
+ assertEquals( "Popped value two:", "Tweedledee", digester.pop( testStackTwoName ) );
}
-
+
/** Tests popping named stack not yet pushed */
@Test
- public void testPopNamedStackNotPushed()
+ public void testPopNamedStackNotPushed()
{
String testStackName = "org.apache.commons.digester3.tests.testPopNamedStackNotPushed";
Digester digester = new Digester();
- try {
-
- digester.pop(testStackName);
- fail("Expected an EmptyStackException");
-
- } catch (EmptyStackException e) {
+ try
+ {
+
+ digester.pop( testStackName );
+ fail( "Expected an EmptyStackException" );
+
+ }
+ catch ( EmptyStackException e )
+ {
// expected
}
-
- try {
-
- digester.peek(testStackName);
- fail("Expected an EmptyStackException");
-
- } catch (EmptyStackException e) {
+
+ try
+ {
+
+ digester.peek( testStackName );
+ fail( "Expected an EmptyStackException" );
+
+ }
+ catch ( EmptyStackException e )
+ {
// expected
}
}
-
+
/** Tests for isEmpty */
@Test
public void testNamedStackIsEmpty()
{
String testStackName = "org.apache.commons.digester3.tests.testNamedStackIsEmpty";
Digester digester = new Digester();
- assertTrue(
- "A named stack that has no object pushed onto it yet should be empty",
- digester.isEmpty(testStackName));
-
- digester.push(testStackName, "Some test value");
- assertFalse(
- "A named stack that has an object pushed onto it should be not empty",
- digester.isEmpty(testStackName));
-
- digester.peek(testStackName);
- assertFalse(
- "Peek should not effect whether the stack is empty",
- digester.isEmpty(testStackName));
-
- digester.pop(testStackName);
- assertTrue(
- "A named stack that has it's last object popped is empty",
- digester.isEmpty(testStackName));
+ assertTrue( "A named stack that has no object pushed onto it yet should be empty",
+ digester.isEmpty( testStackName ) );
+
+ digester.push( testStackName, "Some test value" );
+ assertFalse( "A named stack that has an object pushed onto it should be not empty",
+ digester.isEmpty( testStackName ) );
+
+ digester.peek( testStackName );
+ assertFalse( "Peek should not effect whether the stack is empty", digester.isEmpty( testStackName ) );
+
+ digester.pop( testStackName );
+ assertTrue( "A named stack that has it's last object popped is empty", digester.isEmpty( testStackName ) );
}
/**
* Test the Digester.getRoot method.
*/
@Test
- public void testGetRoot() throws Exception {
+ public void testGetRoot()
+ throws Exception
+ {
Digester digester = new Digester();
- digester.addRule("root", new ObjectCreateRule(TestBean.class));
-
+ digester.addRule( "root", new ObjectCreateRule( TestBean.class ) );
+
String xml = "<root/>";
- InputSource in = new InputSource(new StringReader(xml));
-
- digester.parse(in);
-
+ InputSource in = new InputSource( new StringReader( xml ) );
+
+ digester.parse( in );
+
Object root = digester.getRoot();
- assertNotNull("root object not retrieved", root);
- assertTrue("root object not a TestRule instance", (root instanceof TestBean));
+ assertNotNull( "root object not retrieved", root );
+ assertTrue( "root object not a TestRule instance", ( root instanceof TestBean ) );
}
-
+
/** Utility class for method testStackAction */
- private static class TrackingStackAction implements StackAction {
+ private static class TrackingStackAction
+ implements StackAction
+ {
public ArrayList<String> events = new ArrayList<String>();
- public Object onPush(Digester d, String stackName, Object o) {
+
+ public Object onPush( Digester d, String stackName, Object o )
+ {
String msg = "push:" + stackName + ":" + o.toString();
- events.add(msg);
-
+ events.add( msg );
+
String str = o.toString();
- if (str.startsWith("replpush")) {
- return new String(str);
- } else {
+ if ( str.startsWith( "replpush" ) )
+ {
+ return new String( str );
+ }
+ else
+ {
return o;
}
}
- public Object onPop(Digester d, String stackName, Object o) {
+
+ public Object onPop( Digester d, String stackName, Object o )
+ {
String msg = "pop:" + stackName + ":" + o.toString();
- events.add(msg);
+ events.add( msg );
String str = o.toString();
- if (str.startsWith("replpop")) {
- return new String(str);
- } else {
+ if ( str.startsWith( "replpop" ) )
+ {
+ return new String( str );
+ }
+ else
+ {
return o;
}
}
@@ -610,68 +653,69 @@ public class DigesterTestCase {
* Test custom StackAction subclasses.
*/
@Test
- public void testStackAction() {
+ public void testStackAction()
+ {
TrackingStackAction action = new TrackingStackAction();
-
- Object obj1 = new String("obj1");
- Object obj2 = new String("obj2");
- Object obj3 = new String("replpop.obj3");
- Object obj4 = new String("replpush.obj4");
- Object obj8 = new String("obj8");
- Object obj9 = new String("obj9");
+ Object obj1 = new String( "obj1" );
+ Object obj2 = new String( "obj2" );
+ Object obj3 = new String( "replpop.obj3" );
+ Object obj4 = new String( "replpush.obj4" );
+
+ Object obj8 = new String( "obj8" );
+ Object obj9 = new String( "obj9" );
Digester d = new Digester();
- d.setStackAction(action);
+ d.setStackAction( action );
- assertEquals(0, action.events.size());
- d.push(obj1);
- d.push(obj2);
- d.push(obj3);
- d.push(obj4);
+ assertEquals( 0, action.events.size() );
+ d.push( obj1 );
+ d.push( obj2 );
+ d.push( obj3 );
+ d.push( obj4 );
- assertNotNull(d.peek(0));
+ assertNotNull( d.peek( 0 ) );
// for obj4, a copy should have been pushed
- assertFalse(obj4 == d.peek(0));
- assertEquals(obj4, d.peek(0));
+ assertFalse( obj4 == d.peek( 0 ) );
+ assertEquals( obj4, d.peek( 0 ) );
// for obj3, replacement only occurs on pop
- assertSame(obj3, d.peek(1));
- assertSame(obj2, d.peek(2));
- assertSame(obj1, d.peek(3));
+ assertSame( obj3, d.peek( 1 ) );
+ assertSame( obj2, d.peek( 2 ) );
+ assertSame( obj1, d.peek( 3 ) );
Object obj4a = d.pop();
Object obj3a = d.pop();
Object obj2a = d.pop();
Object obj1a = d.pop();
-
- assertFalse(obj4 == obj4a);
- assertEquals(obj4, obj4a);
- assertFalse(obj3 == obj4a);
- assertEquals(obj3, obj3a);
- assertSame(obj2, obj2a);
- assertSame(obj1, obj1a);
-
- d.push("stack1", obj8);
- d.push("stack1", obj9);
- Object obj9a = d.pop("stack1");
- Object obj8a = d.pop("stack1");
-
- assertSame(obj8, obj8a);
- assertSame(obj9, obj9a);
-
- assertEquals(12, action.events.size());
- assertEquals("push:null:obj1", action.events.get(0));
- assertEquals("push:null:obj2", action.events.get(1));
- assertEquals("push:null:replpop.obj3", action.events.get(2));
- assertEquals("push:null:replpush.obj4", action.events.get(3));
- assertEquals("pop:null:replpush.obj4", action.events.get(4));
- assertEquals("pop:null:replpop.obj3", action.events.get(5));
- assertEquals("pop:null:obj2", action.events.get(6));
- assertEquals("pop:null:obj1", action.events.get(7));
-
- assertEquals("push:stack1:obj8", action.events.get(8));
- assertEquals("push:stack1:obj9", action.events.get(9));
- assertEquals("pop:stack1:obj9", action.events.get(10));
- assertEquals("pop:stack1:obj8", action.events.get(11));
+
+ assertFalse( obj4 == obj4a );
+ assertEquals( obj4, obj4a );
+ assertFalse( obj3 == obj4a );
+ assertEquals( obj3, obj3a );
+ assertSame( obj2, obj2a );
+ assertSame( obj1, obj1a );
+
+ d.push( "stack1", obj8 );
+ d.push( "stack1", obj9 );
+ Object obj9a = d.pop( "stack1" );
+ Object obj8a = d.pop( "stack1" );
+
+ assertSame( obj8, obj8a );
+ assertSame( obj9, obj9a );
+
+ assertEquals( 12, action.events.size() );
+ assertEquals( "push:null:obj1", action.events.get( 0 ) );
+ assertEquals( "push:null:obj2", action.events.get( 1 ) );
+ assertEquals( "push:null:replpop.obj3", action.events.get( 2 ) );
+ assertEquals( "push:null:replpush.obj4", action.events.get( 3 ) );
+ assertEquals( "pop:null:replpush.obj4", action.events.get( 4 ) );
+ assertEquals( "pop:null:replpop.obj3", action.events.get( 5 ) );
+ assertEquals( "pop:null:obj2", action.events.get( 6 ) );
+ assertEquals( "pop:null:obj1", action.events.get( 7 ) );
+
+ assertEquals( "push:stack1:obj8", action.events.get( 8 ) );
+ assertEquals( "push:stack1:obj9", action.events.get( 9 ) );
+ assertEquals( "pop:stack1:obj9", action.events.get( 10 ) );
+ assertEquals( "pop:stack1:obj8", action.events.get( 11 ) );
}
}
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/EBRTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/EBRTestCase.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/EBRTestCase.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/EBRTestCase.java Thu May 12 18:03:26 2011
@@ -16,10 +16,8 @@
* limitations under the License.
*/
-
package org.apache.commons.digester3;
-
import static org.junit.Assert.assertEquals;
import java.util.Iterator;
@@ -30,297 +28,279 @@ import org.apache.commons.digester3.Rule
import org.apache.commons.digester3.Rules;
import org.junit.Test;
-
/**
- * <p> Runs standard tests for RulesBase as well as tests of extensions.
- *
+ * <p>
+ * Runs standard tests for RulesBase as well as tests of extensions.
+ *
* @author Robert Burrell Donkin <ro...@mac.com>
* @version $Revision$ $Date$
*/
-
-public class EBRTestCase extends RulesBaseTestCase {
-
+public class EBRTestCase
+ extends RulesBaseTestCase
+{
// -------------------------------------------------- Overall Test Methods
/**
- * <p> This should be overriden by subclasses.
- *
+ * <p>
+ * This should be overriden by subclasses.
+ *
* @return the matching rules to be tested.
*/
@Override
- protected Rules createMatchingRulesForTest() {
+ protected Rules createMatchingRulesForTest()
+ {
return new ExtendedBaseRules();
}
-
/**
- * Basic test of parent matching rules.
- * A parent match matches any child of a particular kind of parent.
- * A wild parent has a wildcard prefix.
- * This method tests non-universal wildcards.
+ * Basic test of parent matching rules. A parent match matches any child of a particular kind of parent. A wild
+ * parent has a wildcard prefix. This method tests non-universal wildcards.
*/
@Test
- public void testBasicParentMatch() {
+ public void testBasicParentMatch()
+ {
// clear any existing rules
digester.getRules().clear();
- assertEquals("Initial rules list is empty",
- 0, digester.getRules().rules().size());
+ assertEquals( "Initial rules list is empty", 0, digester.getRules().rules().size() );
// Set up rules
// since these are all NON-UNIVERSAL matches
// only expect one match at each stage
- digester.addRule("alpha/beta/gamma/delta", new TestRule("exact"));
- digester.addRule("*/beta/gamma/epsilon", new TestRule("wild_child"));
- digester.addRule("alpha/beta/gamma/?", new TestRule("exact_parent"));
- digester.addRule("*/beta/gamma/?", new TestRule("wild_parent"));
-
+ digester.addRule( "alpha/beta/gamma/delta", new TestRule( "exact" ) );
+ digester.addRule( "*/beta/gamma/epsilon", new TestRule( "wild_child" ) );
+ digester.addRule( "alpha/beta/gamma/?", new TestRule( "exact_parent" ) );
+ digester.addRule( "*/beta/gamma/?", new TestRule( "wild_parent" ) );
List<Rule> list = null;
Iterator<Rule> it = null;
// this should match just the exact since this has presidence
- list = digester.getRules().match(null, "alpha/beta/gamma/delta");
+ list = digester.getRules().match( null, "alpha/beta/gamma/delta" );
// all three rules should match
- assertEquals("Testing basic parent mismatch (A)", 1, list.size());
+ assertEquals( "Testing basic parent mismatch (A)", 1, list.size() );
it = list.iterator();
- assertEquals("Testing basic parent mismatch (B)", "exact", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing basic parent mismatch (B)", "exact", ( (TestRule) it.next() ).getIdentifier() );
// we don't have an exact match for this child so we should get the exact parent
- list = digester.getRules().match(null, "alpha/beta/gamma/epsilon");
+ list = digester.getRules().match( null, "alpha/beta/gamma/epsilon" );
// all three rules should match
- assertEquals("Testing basic parent mismatch (C)", 1, list.size());
+ assertEquals( "Testing basic parent mismatch (C)", 1, list.size() );
it = list.iterator();
- assertEquals("Testing basic parent mismatch (D)", "exact_parent", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing basic parent mismatch (D)", "exact_parent", ( (TestRule) it.next() ).getIdentifier() );
// wild child overrides wild parent
- list = digester.getRules().match(null, "alpha/omega/beta/gamma/epsilon");
+ list = digester.getRules().match( null, "alpha/omega/beta/gamma/epsilon" );
// all three rules should match
- assertEquals("Testing basic parent mismatch (E)", 1, list.size());
+ assertEquals( "Testing basic parent mismatch (E)", 1, list.size() );
it = list.iterator();
- assertEquals("Testing basic parent mismatch (F)", "wild_child", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing basic parent mismatch (F)", "wild_child", ( (TestRule) it.next() ).getIdentifier() );
// nothing else matches so return wild parent
- list = digester.getRules().match(null, "alpha/omega/beta/gamma/zeta");
+ list = digester.getRules().match( null, "alpha/omega/beta/gamma/zeta" );
// all three rules should match
- assertEquals("Testing basic parent mismatch (G)", 1, list.size());
+ assertEquals( "Testing basic parent mismatch (G)", 1, list.size() );
it = list.iterator();
- assertEquals("Testing basic parent mismatch (H)", "wild_parent", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing basic parent mismatch (H)", "wild_parent", ( (TestRule) it.next() ).getIdentifier() );
// clean up
digester.getRules().clear();
}
-
/**
- * Basic test of universal matching rules.
- * Universal rules act independent.
+ * Basic test of universal matching rules. Universal rules act independent.
*/
@Test
- public void testBasicUniversal() {
+ public void testBasicUniversal()
+ {
// clear any existing rules
digester.getRules().clear();
- assertEquals("Initial rules list is empty",
- 0, digester.getRules().rules().size());
+ assertEquals( "Initial rules list is empty", 0, digester.getRules().rules().size() );
// Set up rules
// set up universal matches against non-universal ones
- digester.addRule("alpha/beta/gamma", new TestRule("exact"));
- digester.addRule("*/beta/gamma", new TestRule("non_wild_head"));
- digester.addRule("!*/beta/gamma", new TestRule("universal_wild_head"));
- digester.addRule("!alpha/beta/gamma/?", new TestRule("universal_wild_child"));
- digester.addRule("alpha/beta/gamma/?", new TestRule("non_wild_child"));
- digester.addRule("alpha/beta/gamma/epsilon", new TestRule("exact2"));
- digester.addRule("alpha/epsilon/beta/gamma/zeta", new TestRule("exact3"));
- digester.addRule("*/gamma/?", new TestRule("non_wildhead_child"));
- digester.addRule("!*/epsilon/beta/gamma/?", new TestRule("universal_wildhead_child"));
-
+ digester.addRule( "alpha/beta/gamma", new TestRule( "exact" ) );
+ digester.addRule( "*/beta/gamma", new TestRule( "non_wild_head" ) );
+ digester.addRule( "!*/beta/gamma", new TestRule( "universal_wild_head" ) );
+ digester.addRule( "!alpha/beta/gamma/?", new TestRule( "universal_wild_child" ) );
+ digester.addRule( "alpha/beta/gamma/?", new TestRule( "non_wild_child" ) );
+ digester.addRule( "alpha/beta/gamma/epsilon", new TestRule( "exact2" ) );
+ digester.addRule( "alpha/epsilon/beta/gamma/zeta", new TestRule( "exact3" ) );
+ digester.addRule( "*/gamma/?", new TestRule( "non_wildhead_child" ) );
+ digester.addRule( "!*/epsilon/beta/gamma/?", new TestRule( "universal_wildhead_child" ) );
List<Rule> list = null;
Iterator<Rule> it = null;
// test universal wild head
- list = digester.getRules().match(null, "alpha/beta/gamma");
+ list = digester.getRules().match( null, "alpha/beta/gamma" );
- assertEquals("Testing universal wildcard mismatch (A)", 2, list.size());
+ assertEquals( "Testing universal wildcard mismatch (A)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing universal wildcard mismatch (B)", "exact", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing universal wildcard mismatch (C)", "universal_wild_head", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing universal wildcard mismatch (B)", "exact", ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing universal wildcard mismatch (C)", "universal_wild_head",
+ ( (TestRule) it.next() ).getIdentifier() );
// test universal parent
- list = digester.getRules().match(null, "alpha/beta/gamma/epsilon");
+ list = digester.getRules().match( null, "alpha/beta/gamma/epsilon" );
- assertEquals("Testing universal wildcard mismatch (D)", 2, list.size());
+ assertEquals( "Testing universal wildcard mismatch (D)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing universal wildcard mismatch (E)", "universal_wild_child", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing universal wildcard mismatch (F)", "exact2", ((TestRule) it.next()).getIdentifier());
+ assertEquals( "Testing universal wildcard mismatch (E)", "universal_wild_child",
+ ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing universal wildcard mismatch (F)", "exact2", ( (TestRule) it.next() ).getIdentifier() );
// test universal parent
- list = digester.getRules().match(null, "alpha/beta/gamma/zeta");
+ list = digester.getRules().match( null, "alpha/beta/gamma/zeta" );
- assertEquals("Testing universal wildcard mismatch (G)", 2, list.size());
+ assertEquals( "Testing universal wildcard mismatch (G)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing universal wildcard mismatch (H)", "universal_wild_child", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing universal wildcard mismatch (I)", "non_wild_child", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing universal wildcard mismatch (H)", "universal_wild_child",
+ ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing universal wildcard mismatch (I)", "non_wild_child",
+ ( (TestRule) it.next() ).getIdentifier() );
// test wildcard universal parent
- list = digester.getRules().match(null, "alpha/epsilon/beta/gamma/alpha");
+ list = digester.getRules().match( null, "alpha/epsilon/beta/gamma/alpha" );
- assertEquals("Testing universal wildcard mismatch (J)", 2, list.size());
+ assertEquals( "Testing universal wildcard mismatch (J)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing universal wildcard mismatch (K)", "non_wildhead_child", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing universal wildcard mismatch (L)", "universal_wildhead_child", ((TestRule) it.next()).getIdentifier());
+ assertEquals( "Testing universal wildcard mismatch (K)", "non_wildhead_child",
+ ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing universal wildcard mismatch (L)", "universal_wildhead_child",
+ ( (TestRule) it.next() ).getIdentifier() );
// test wildcard universal parent
- list = digester.getRules().match(null, "alpha/epsilon/beta/gamma/zeta");
+ list = digester.getRules().match( null, "alpha/epsilon/beta/gamma/zeta" );
- assertEquals("Testing universal wildcard mismatch (M)", 2, list.size());
+ assertEquals( "Testing universal wildcard mismatch (M)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing universal wildcard mismatch (M)", "exact3", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing universal wildcard mismatch (O)", "universal_wildhead_child", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing universal wildcard mismatch (M)", "exact3", ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing universal wildcard mismatch (O)", "universal_wildhead_child",
+ ( (TestRule) it.next() ).getIdentifier() );
// clean up
digester.getRules().clear();
}
-
/**
- * Basic test of wild matches.
- * A universal will match matches anything!
- * A non-universal will match matches anything not matched by something else.
- * This method tests non-universal and universal wild matches.
+ * Basic test of wild matches. A universal will match matches anything! A non-universal will match matches anything
+ * not matched by something else. This method tests non-universal and universal wild matches.
*/
@Test
- public void testWildMatch() {
+ public void testWildMatch()
+ {
// clear any existing rules
digester.getRules().clear();
- assertEquals("Initial rules list is empty",
- 0, digester.getRules().rules().size());
+ assertEquals( "Initial rules list is empty", 0, digester.getRules().rules().size() );
// Set up rules
// The combinations a little large to test everything but we'll pick a couple and try them.
- digester.addRule("*", new TestRule("basic_wild"));
- digester.addRule("!*", new TestRule("universal_wild"));
- digester.addRule("alpha/beta/gamma/delta", new TestRule("exact"));
- digester.addRule("*/beta/gamma/?", new TestRule("wild_parent"));
-
+ digester.addRule( "*", new TestRule( "basic_wild" ) );
+ digester.addRule( "!*", new TestRule( "universal_wild" ) );
+ digester.addRule( "alpha/beta/gamma/delta", new TestRule( "exact" ) );
+ digester.addRule( "*/beta/gamma/?", new TestRule( "wild_parent" ) );
List<Rule> list = null;
Iterator<Rule> it = null;
// The universal wild will always match whatever else does
- list = digester.getRules().match(null, "alpha/beta/gamma/delta");
+ list = digester.getRules().match( null, "alpha/beta/gamma/delta" );
// all three rules should match
- assertEquals("Testing wild mismatch (A)", 2, list.size());
+ assertEquals( "Testing wild mismatch (A)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing wild mismatch (B)", "universal_wild", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing wild mismatch (C)", "exact", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing wild mismatch (B)", "universal_wild", ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing wild mismatch (C)", "exact", ( (TestRule) it.next() ).getIdentifier() );
// The universal wild will always match whatever else does
- list = digester.getRules().match(null, "alpha/beta/gamma/epsilon");
+ list = digester.getRules().match( null, "alpha/beta/gamma/epsilon" );
- assertEquals("Testing wild mismatch (D)", 2, list.size());
+ assertEquals( "Testing wild mismatch (D)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing wild mismatch (E)", "universal_wild", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing wild mismatch (F)", "wild_parent", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing wild mismatch (E)", "universal_wild", ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing wild mismatch (F)", "wild_parent", ( (TestRule) it.next() ).getIdentifier() );
// The universal wild will always match whatever else does
// we have no other non-universal matching so this will match the non-universal wild as well
- list = digester.getRules().match(null, "alpha/gamma");
+ list = digester.getRules().match( null, "alpha/gamma" );
- assertEquals("Testing wild mismatch (G)", 2, list.size());
+ assertEquals( "Testing wild mismatch (G)", 2, list.size() );
it = list.iterator();
- assertEquals("Testing wild mismatch (H)", "basic_wild", ((TestRule) it.next()).getIdentifier());
- assertEquals("Testing wild mismatch (I)", "universal_wild", ((TestRule) it.next()).getIdentifier());
-
+ assertEquals( "Testing wild mismatch (H)", "basic_wild", ( (TestRule) it.next() ).getIdentifier() );
+ assertEquals( "Testing wild mismatch (I)", "universal_wild", ( (TestRule) it.next() ).getIdentifier() );
// clean up
digester.getRules().clear();
}
-
-
/**
- * Basic test of wild matches.
- * A universal will match matches anything!
- * A non-universal will match matches anything not matched by something else.
- * This method tests non-universal and universal wild matches.
+ * Basic test of wild matches. A universal will match matches anything! A non-universal will match matches anything
+ * not matched by something else. This method tests non-universal and universal wild matches.
*/
@Test
- public void testRootTailMatch() {
+ public void testRootTailMatch()
+ {
// clear any existing rules
digester.getRules().clear();
- assertEquals("Initial rules list is empty",
- 0, digester.getRules().rules().size());
+ assertEquals( "Initial rules list is empty", 0, digester.getRules().rules().size() );
// Set up rules
// The combinations a little large to test everything but we'll pick a couple and try them.
- digester.addRule("*/a", new TestRule("a_tail"));
-
+ digester.addRule( "*/a", new TestRule( "a_tail" ) );
List<Rule> list = null;
- list = digester.getRules().match(null, "a");
+ list = digester.getRules().match( null, "a" );
- assertEquals("Testing tail wrong size (A)", 1, list.size());
- assertEquals("Testing tail mismatch (B)", "a_tail", ((TestRule) list.get(0)).getIdentifier());
+ assertEquals( "Testing tail wrong size (A)", 1, list.size() );
+ assertEquals( "Testing tail mismatch (B)", "a_tail", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ list = digester.getRules().match( null, "beta/a" );
- list = digester.getRules().match(null, "beta/a");
+ assertEquals( "Testing tail wrong size (C)", 1, list.size() );
+ assertEquals( "Testing tail mismatch (D)", "a_tail", ( (TestRule) list.get( 0 ) ).getIdentifier() );
- assertEquals("Testing tail wrong size (C)", 1, list.size());
- assertEquals("Testing tail mismatch (D)", "a_tail", ((TestRule) list.get(0)).getIdentifier());
+ list = digester.getRules().match( null, "be/aaa" );
- list = digester.getRules().match(null, "be/aaa");
+ assertEquals( "Testing tail no matches (E)", 0, list.size() );
- assertEquals("Testing tail no matches (E)", 0, list.size());
-
- list = digester.getRules().match(null, "aaa");
+ list = digester.getRules().match( null, "aaa" );
- assertEquals("Testing tail no matches (F)", 0, list.size());
-
- list = digester.getRules().match(null, "a/beta");
+ assertEquals( "Testing tail no matches (F)", 0, list.size() );
- assertEquals("Testing tail no matches (G)", 0, list.size());
+ list = digester.getRules().match( null, "a/beta" );
+
+ assertEquals( "Testing tail no matches (G)", 0, list.size() );
// clean up
digester.getRules().clear();
@@ -328,110 +308,113 @@ public class EBRTestCase extends RulesBa
}
@Test
- public void testAncesterMatch() throws Exception {
+ public void testAncesterMatch()
+ throws Exception
+ {
// test fixed root ancester
digester.getRules().clear();
-
- digester.addRule("!a/b/*", new TestRule("uni-a-b-star"));
- digester.addRule("a/b/*", new TestRule("a-b-star"));
- digester.addRule("a/b/c", new TestRule("a-b-c"));
- digester.addRule("a/b/?", new TestRule("a-b-child"));
-
- List<Rule> list = digester.getRules().match(null, "a/b/c");
-
- assertEquals("Simple ancester matches (1)", 2, list.size());
- assertEquals("Univeral ancester mismatch (1)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier());
- assertEquals("Parent precedence failure", "a-b-c" , ((TestRule) list.get(1)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/b");
- assertEquals("Simple ancester matches (2)", 2, list.size());
- assertEquals("Univeral ancester mismatch (2)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier());
- assertEquals("Child precedence failure", "a-b-child" , ((TestRule) list.get(1)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/d");
- assertEquals("Simple ancester matches (3)", 2, list.size());
- assertEquals("Univeral ancester mismatch (3)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier());
- assertEquals("Ancester mismatch (1)", "a-b-child" , ((TestRule) list.get(1)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/d/e/f");
- assertEquals("Simple ancester matches (4)", 2, list.size());
- assertEquals("Univeral ancester mismatch (4)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier());
- assertEquals("Ancester mismatch (2)", "a-b-star" , ((TestRule) list.get(1)).getIdentifier());
-
+
+ digester.addRule( "!a/b/*", new TestRule( "uni-a-b-star" ) );
+ digester.addRule( "a/b/*", new TestRule( "a-b-star" ) );
+ digester.addRule( "a/b/c", new TestRule( "a-b-c" ) );
+ digester.addRule( "a/b/?", new TestRule( "a-b-child" ) );
+
+ List<Rule> list = digester.getRules().match( null, "a/b/c" );
+
+ assertEquals( "Simple ancester matches (1)", 2, list.size() );
+ assertEquals( "Univeral ancester mismatch (1)", "uni-a-b-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ assertEquals( "Parent precedence failure", "a-b-c", ( (TestRule) list.get( 1 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/b" );
+ assertEquals( "Simple ancester matches (2)", 2, list.size() );
+ assertEquals( "Univeral ancester mismatch (2)", "uni-a-b-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ assertEquals( "Child precedence failure", "a-b-child", ( (TestRule) list.get( 1 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/d" );
+ assertEquals( "Simple ancester matches (3)", 2, list.size() );
+ assertEquals( "Univeral ancester mismatch (3)", "uni-a-b-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ assertEquals( "Ancester mismatch (1)", "a-b-child", ( (TestRule) list.get( 1 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/d/e/f" );
+ assertEquals( "Simple ancester matches (4)", 2, list.size() );
+ assertEquals( "Univeral ancester mismatch (4)", "uni-a-b-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ assertEquals( "Ancester mismatch (2)", "a-b-star", ( (TestRule) list.get( 1 ) ).getIdentifier() );
+
// test wild root ancester
digester.getRules().clear();
- digester.addRule("!*/a/b/*", new TestRule("uni-star-a-b-star"));
- digester.addRule("*/b/c/*", new TestRule("star-b-c-star"));
- digester.addRule("*/b/c/d", new TestRule("star-b-c-d"));
- digester.addRule("a/b/c", new TestRule("a-b-c"));
-
- list = digester.getRules().match(null, "a/b/c");
- assertEquals("Wild ancester match (1)", 2, list.size());
- assertEquals(
- "Univeral ancester mismatch (5)",
- "uni-star-a-b-star" ,
- ((TestRule) list.get(0)).getIdentifier());
- assertEquals("Match missed (1)", "a-b-c" , ((TestRule) list.get(1)).getIdentifier());
-
- list = digester.getRules().match(null, "b/c");
- assertEquals("Wild ancester match (2)", 1, list.size());
- assertEquals("Match missed (2)", "star-b-c-star" , ((TestRule) list.get(0)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/c/d");
- assertEquals("Wild ancester match (3)", 2, list.size());
- assertEquals("Match missed (3)", "uni-star-a-b-star" , ((TestRule) list.get(0)).getIdentifier());
- assertEquals("Match missed (4)", "star-b-c-d" , ((TestRule) list.get(1)).getIdentifier());
-
- list = digester.getRules().match(null, "b/b/c/e/d");
- assertEquals("Wild ancester match (2)", 1, list.size());
- assertEquals("Match missed (5)", "star-b-c-star" , ((TestRule) list.get(0)).getIdentifier());
+ digester.addRule( "!*/a/b/*", new TestRule( "uni-star-a-b-star" ) );
+ digester.addRule( "*/b/c/*", new TestRule( "star-b-c-star" ) );
+ digester.addRule( "*/b/c/d", new TestRule( "star-b-c-d" ) );
+ digester.addRule( "a/b/c", new TestRule( "a-b-c" ) );
+
+ list = digester.getRules().match( null, "a/b/c" );
+ assertEquals( "Wild ancester match (1)", 2, list.size() );
+ assertEquals( "Univeral ancester mismatch (5)", "uni-star-a-b-star",
+ ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ assertEquals( "Match missed (1)", "a-b-c", ( (TestRule) list.get( 1 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "b/c" );
+ assertEquals( "Wild ancester match (2)", 1, list.size() );
+ assertEquals( "Match missed (2)", "star-b-c-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/c/d" );
+ assertEquals( "Wild ancester match (3)", 2, list.size() );
+ assertEquals( "Match missed (3)", "uni-star-a-b-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+ assertEquals( "Match missed (4)", "star-b-c-d", ( (TestRule) list.get( 1 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "b/b/c/e/d" );
+ assertEquals( "Wild ancester match (2)", 1, list.size() );
+ assertEquals( "Match missed (5)", "star-b-c-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
}
@Test
- public void testLongMatch() {
-
+ public void testLongMatch()
+ {
+
digester.getRules().clear();
- digester.addRule("a/b/c/d/*", new TestRule("a-b-c-d-star"));
-
- List<Rule> list = digester.getRules().match(null, "a/b/c/d/e");
- assertEquals("Long match (1)", 1, list.size());
- assertEquals("Match missed (1)", "a-b-c-d-star" , ((TestRule) list.get(0)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/c/d/e/f");
- assertEquals("Long match (2)", 1, list.size());
- assertEquals("Match missed (2)", "a-b-c-d-star" , ((TestRule) list.get(0)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/c/d/e/f/g");
- assertEquals("Long match (3)", 1, list.size());
- assertEquals("Match missed (3)", "a-b-c-d-star" , ((TestRule) list.get(0)).getIdentifier());
-
- list = digester.getRules().match(null, "a/b/c/d");
- assertEquals("Long match (4)", 0, list.size());
+ digester.addRule( "a/b/c/d/*", new TestRule( "a-b-c-d-star" ) );
+
+ List<Rule> list = digester.getRules().match( null, "a/b/c/d/e" );
+ assertEquals( "Long match (1)", 1, list.size() );
+ assertEquals( "Match missed (1)", "a-b-c-d-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/c/d/e/f" );
+ assertEquals( "Long match (2)", 1, list.size() );
+ assertEquals( "Match missed (2)", "a-b-c-d-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/c/d/e/f/g" );
+ assertEquals( "Long match (3)", 1, list.size() );
+ assertEquals( "Match missed (3)", "a-b-c-d-star", ( (TestRule) list.get( 0 ) ).getIdentifier() );
+
+ list = digester.getRules().match( null, "a/b/c/d" );
+ assertEquals( "Long match (4)", 0, list.size() );
}
@Test
- public void testInstructors() {
+ public void testInstructors()
+ {
digester.getRules().clear();
-
- digester.addRule("!instructors/*", new TestRule("instructors"));
- digester.addRule("!instructor/*", new TestRule("instructor"));
-
- List<Rule> list = digester.getRules().match(null, "instructors");
- assertEquals("Only expect to match instructors", 1, list.size());
- assertEquals("Instructors expected", "instructors" , ((TestRule) list.get(0)).getIdentifier());
+
+ digester.addRule( "!instructors/*", new TestRule( "instructors" ) );
+ digester.addRule( "!instructor/*", new TestRule( "instructor" ) );
+
+ List<Rule> list = digester.getRules().match( null, "instructors" );
+ assertEquals( "Only expect to match instructors", 1, list.size() );
+ assertEquals( "Instructors expected", "instructors", ( (TestRule) list.get( 0 ) ).getIdentifier() );
}
@Test
- public void testMiddleInstructors() {
+ public void testMiddleInstructors()
+ {
digester.getRules().clear();
-
- digester.addRule("!instructors/*", new TestRule("instructors"));
-
- List<Rule> list = digester.getRules().match(null, "/tosh/instructors/fiddlesticks");
- assertEquals("No matches expected", 0, list.size());
+
+ digester.addRule( "!instructors/*", new TestRule( "instructors" ) );
+
+ List<Rule> list = digester.getRules().match( null, "/tosh/instructors/fiddlesticks" );
+ assertEquals( "No matches expected", 0, list.size() );
}
}
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Employee.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Employee.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Employee.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Employee.java Thu May 12 18:03:26 2011
@@ -18,108 +18,120 @@
package org.apache.commons.digester3;
-
import java.util.ArrayList;
-
/**
* Bean for Digester testing.
*/
-public class Employee {
+public class Employee
+{
- public Employee() {
- this("My First Name", "My Last Name");
+ public Employee()
+ {
+ this( "My First Name", "My Last Name" );
}
- public Employee(String firstName, String lastName) {
+ public Employee( String firstName, String lastName )
+ {
super();
- setFirstName(firstName);
- setLastName(lastName);
+ setFirstName( firstName );
+ setLastName( lastName );
}
private ArrayList<Address> addresses = new ArrayList<Address>();
- public void addAddress(Address address) {
- addresses.add(address);
+ public void addAddress( Address address )
+ {
+ addresses.add( address );
}
- public Address getAddress(String type) {
- for (Address address : addresses) {
- if (type.equals(address.getType()))
- return (address);
+ public Address getAddress( String type )
+ {
+ for ( Address address : addresses )
+ {
+ if ( type.equals( address.getType() ) )
+ return ( address );
}
- return (null);
+ return ( null );
}
- public void removeAddress(Address address) {
- addresses.remove(address);
+ public void removeAddress( Address address )
+ {
+ addresses.remove( address );
}
private String firstName = null;
- public String getFirstName() {
- return (this.firstName);
+ public String getFirstName()
+ {
+ return ( this.firstName );
}
- public void setFirstName(String firstName) {
+ public void setFirstName( String firstName )
+ {
this.firstName = firstName;
}
private String lastName = null;
- public String getLastName() {
- return (this.lastName);
+ public String getLastName()
+ {
+ return ( this.lastName );
}
- public void setLastName(String lastName) {
+ public void setLastName( String lastName )
+ {
this.lastName = lastName;
}
- // this is to allow testing of primitive convertion
+ // this is to allow testing of primitive convertion
private int age;
- private boolean active;
+
+ private boolean active;
+
private float salary;
-
+
public int getAge()
{
return age;
}
-
- public void setAge(int age)
+
+ public void setAge( int age )
{
this.age = age;
}
-
+
public boolean isActive()
{
return active;
}
-
- public void setActive(boolean active)
+
+ public void setActive( boolean active )
{
this.active = active;
}
-
+
public float getSalary()
{
return salary;
}
-
- public void setSalary(float salary)
+
+ public void setSalary( float salary )
{
this.salary = salary;
}
@Override
- public String toString() {
- StringBuilder sb = new StringBuilder("Employee[");
- sb.append("firstName=");
- sb.append(firstName);
- sb.append(", lastName=");
- sb.append(lastName);
- sb.append("]");
- return (sb.toString());
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder( "Employee[" );
+ sb.append( "firstName=" );
+ sb.append( firstName );
+ sb.append( ", lastName=" );
+ sb.append( lastName );
+ sb.append( "]" );
+ return ( sb.toString() );
}
}
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/LocationTrackerTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/LocationTrackerTestCase.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/LocationTrackerTestCase.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/LocationTrackerTestCase.java Thu May 12 18:03:26 2011
@@ -16,10 +16,8 @@
* limitations under the License.
*/
-
package org.apache.commons.digester3;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -33,68 +31,70 @@ import org.apache.commons.digester3.Stac
import org.junit.Test;
import org.xml.sax.Locator;
-
/**
- * Tests that StackAction can be used to track the source location
- * of objects created from input xml stream.
+ * Tests that StackAction can be used to track the source location of objects created from input xml stream.
*/
-public class LocationTrackerTestCase {
+public class LocationTrackerTestCase
+{
- private static class LocationTracker implements StackAction {
+ private static class LocationTracker
+ implements StackAction
+ {
public Map<Object, String> locations = new HashMap<Object, String>();
- public Object onPush(Digester d, String stackName, Object o) {
- if (stackName == null) {
+ public Object onPush( Digester d, String stackName, Object o )
+ {
+ if ( stackName == null )
+ {
// we only care about the real object stack
-
- // note that a Locator object can also provide
+
+ // note that a Locator object can also provide
// publicId and systemId info.
Locator l = d.getDocumentLocator();
StringBuilder locn = new StringBuilder();
- locn.append("line=");
- locn.append(l.getLineNumber());
- locations.put(o, locn.toString());
+ locn.append( "line=" );
+ locn.append( l.getLineNumber() );
+ locations.put( o, locn.toString() );
}
return o;
}
- public Object onPop(Digester d, String stackName, Object o) {
+ public Object onPop( Digester d, String stackName, Object o )
+ {
return o;
}
}
@Test
- public void testAll() throws Exception {
+ public void testAll()
+ throws Exception
+ {
final String TEST_XML =
- "<?xml version='1.0'?>\n"
- + "<box id='root'>\n"
- + " <subBox id='box1'/>\n"
- + " <ignoreme/>\n"
- + " <subBox id='box2'/> <subBox id='box3'/>\n"
- + "</box>";
-
+ "<?xml version='1.0'?>\n" + "<box id='root'>\n" + " <subBox id='box1'/>\n" + " <ignoreme/>\n"
+ + " <subBox id='box2'/> <subBox id='box3'/>\n" + "</box>";
+
LocationTracker locnTracker = new LocationTracker();
Digester digester = new Digester();
- digester.setStackAction(locnTracker);
- digester.addObjectCreate("box", Box.class);
- digester.addSetProperties("box");
- digester.addObjectCreate("box/subBox", Box.class);
- digester.addSetProperties("box/subBox");
- digester.addSetNext("box/subBox", "addChild");
+ digester.setStackAction( locnTracker );
+ digester.addObjectCreate( "box", Box.class );
+ digester.addSetProperties( "box" );
+ digester.addObjectCreate( "box/subBox", Box.class );
+ digester.addSetProperties( "box/subBox" );
+ digester.addSetNext( "box/subBox", "addChild" );
- Box root = digester.parse(new StringReader(TEST_XML));
- assertNotNull(root);
+ Box root = digester.parse( new StringReader( TEST_XML ) );
+ assertNotNull( root );
List<Box> children = root.getChildren();
- assertEquals(3, children.size());
- Box box1 = children.get(0);
- Box box2 = children.get(1);
- Box box3 = children.get(2);
-
- assertEquals("line=2", locnTracker.locations.get(root));
- assertEquals("line=3", locnTracker.locations.get(box1));
- assertEquals("line=5", locnTracker.locations.get(box2));
- assertEquals("line=5", locnTracker.locations.get(box3));
+ assertEquals( 3, children.size() );
+ Box box1 = children.get( 0 );
+ Box box2 = children.get( 1 );
+ Box box3 = children.get( 2 );
+
+ assertEquals( "line=2", locnTracker.locations.get( root ) );
+ assertEquals( "line=3", locnTracker.locations.get( box1 ) );
+ assertEquals( "line=5", locnTracker.locations.get( box2 ) );
+ assertEquals( "line=5", locnTracker.locations.get( box3 ) );
}
}
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Nameable.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Nameable.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Nameable.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/Nameable.java Thu May 12 18:03:26 2011
@@ -21,7 +21,9 @@ package org.apache.commons.digester3;
/**
* Interface used for testing.
*/
-public interface Nameable {
- String getName();
- void setName(String name);
+public interface Nameable
+{
+ String getName();
+
+ void setName( String name );
}
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamedBean.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamedBean.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamedBean.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamedBean.java Thu May 12 18:03:26 2011
@@ -16,39 +16,46 @@
* limitations under the License.
*/
-
package org.apache.commons.digester3;
-
/**
* Very simple test bean
- *
+ *
* @author Robert Burrell Donkin
* @version $Revision$ $Date$
*/
-public class NamedBean {
-
+public class NamedBean
+{
+
private String name = "**UNSET**";
-
- public NamedBean() {}
-
- public NamedBean(String name) {}
-
- public String getName() {
+
+ public NamedBean()
+ {
+ }
+
+ public NamedBean( String name )
+ {
+ }
+
+ public String getName()
+ {
return name;
}
-
- public void setName(String name) {
+
+ public void setName( String name )
+ {
this.name = name;
}
-
- public void test(String name, String ignored) {
- setName(name);
+
+ public void test( String name, String ignored )
+ {
+ setName( name );
}
-
+
@Override
- public String toString() {
+ public String toString()
+ {
return "NamedBean[" + getName() + "]";
}
}
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/NamespaceSnapshotTestCase.java Thu May 12 18:03:26 2011
@@ -16,10 +16,8 @@
* limitations under the License.
*/
-
package org.apache.commons.digester3;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -33,26 +31,28 @@ import org.apache.commons.digester3.Rule
import org.junit.Test;
import org.xml.sax.Attributes;
-
/**
* Tests namespace snapshotting.
*/
-public class NamespaceSnapshotTestCase {
+public class NamespaceSnapshotTestCase
+{
/**
* A test case specific helper rule.
*/
- static class NamespaceSnapshotRule extends Rule {
+ static class NamespaceSnapshotRule
+ extends Rule
+ {
/**
* @see Rule#begin(String, String, Attributes)
*/
@Override
- public final void begin(final String namespace, final String name,
- final Attributes attributes) {
+ public final void begin( final String namespace, final String name, final Attributes attributes )
+ {
Digester d = getDigester();
Map<String, String> namespaces = d.getCurrentNamespaces();
- ((NamespacedBox) d.peek()).setNamespaces(namespaces);
+ ( (NamespacedBox) d.peek() ).setNamespaces( namespaces );
}
}
@@ -60,72 +60,71 @@ public class NamespaceSnapshotTestCase {
* Namespace snapshot test case.
*/
@Test
- public void testNamespaceSnapshots() throws Exception {
+ public void testNamespaceSnapshots()
+ throws Exception
+ {
Digester digester = new Digester();
- digester.setNamespaceAware(true);
- digester.addObjectCreate("box", NamespacedBox.class);
- digester.addSetProperties("box");
- digester.addRule("box", new NamespaceSnapshotRule());
- digester.addObjectCreate("box/subBox", NamespacedBox.class);
- digester.addSetProperties("box/subBox");
- digester.addRule("box/subBox", new NamespaceSnapshotRule());
- digester.addSetNext("box/subBox", "addChild");
+ digester.setNamespaceAware( true );
+ digester.addObjectCreate( "box", NamespacedBox.class );
+ digester.addSetProperties( "box" );
+ digester.addRule( "box", new NamespaceSnapshotRule() );
+ digester.addObjectCreate( "box/subBox", NamespacedBox.class );
+ digester.addSetProperties( "box/subBox" );
+ digester.addRule( "box/subBox", new NamespaceSnapshotRule() );
+ digester.addSetNext( "box/subBox", "addChild" );
- NamespacedBox root = digester.parse(getInputStream("Test11.xml"));
+ NamespacedBox root = digester.parse( getInputStream( "Test11.xml" ) );
Map<String, String> nsmap = root.getNamespaces();
- assertEquals(3, nsmap.size());
- assertEquals("", nsmap.get(""));
- assertEquals("http://commons.apache.org/digester/Foo", nsmap.get("foo"));
- assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar"));
+ assertEquals( 3, nsmap.size() );
+ assertEquals( "", nsmap.get( "" ) );
+ assertEquals( "http://commons.apache.org/digester/Foo", nsmap.get( "foo" ) );
+ assertEquals( "http://commons.apache.org/digester/Bar", nsmap.get( "bar" ) );
List<Box> children = root.getChildren();
- assertEquals(3, children.size());
+ assertEquals( 3, children.size() );
- NamespacedBox child1 = (NamespacedBox) children.get(0);
+ NamespacedBox child1 = (NamespacedBox) children.get( 0 );
nsmap = child1.getNamespaces();
- assertEquals(3, nsmap.size());
- assertEquals("", nsmap.get(""));
- assertEquals("http://commons.apache.org/digester/Foo1", nsmap.get("foo"));
- assertEquals("http://commons.apache.org/digester/Bar1", nsmap.get("bar"));
+ assertEquals( 3, nsmap.size() );
+ assertEquals( "", nsmap.get( "" ) );
+ assertEquals( "http://commons.apache.org/digester/Foo1", nsmap.get( "foo" ) );
+ assertEquals( "http://commons.apache.org/digester/Bar1", nsmap.get( "bar" ) );
- NamespacedBox child2 = (NamespacedBox) children.get(1);
+ NamespacedBox child2 = (NamespacedBox) children.get( 1 );
nsmap = child2.getNamespaces();
- assertEquals(5, nsmap.size());
- assertEquals("", nsmap.get(""));
- assertEquals("http://commons.apache.org/digester/Foo", nsmap.get("foo"));
- assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar"));
- assertEquals("http://commons.apache.org/digester/Alpha", nsmap.get("alpha"));
- assertEquals("http://commons.apache.org/digester/Beta", nsmap.get("beta"));
+ assertEquals( 5, nsmap.size() );
+ assertEquals( "", nsmap.get( "" ) );
+ assertEquals( "http://commons.apache.org/digester/Foo", nsmap.get( "foo" ) );
+ assertEquals( "http://commons.apache.org/digester/Bar", nsmap.get( "bar" ) );
+ assertEquals( "http://commons.apache.org/digester/Alpha", nsmap.get( "alpha" ) );
+ assertEquals( "http://commons.apache.org/digester/Beta", nsmap.get( "beta" ) );
- NamespacedBox child3 = (NamespacedBox) children.get(2);
+ NamespacedBox child3 = (NamespacedBox) children.get( 2 );
nsmap = child3.getNamespaces();
- assertEquals(4, nsmap.size());
- assertEquals("", nsmap.get(""));
- assertEquals("http://commons.apache.org/digester/Foo3", nsmap.get("foo"));
- assertEquals("http://commons.apache.org/digester/Alpha", nsmap.get("alpha"));
- assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar"));
+ assertEquals( 4, nsmap.size() );
+ assertEquals( "", nsmap.get( "" ) );
+ assertEquals( "http://commons.apache.org/digester/Foo3", nsmap.get( "foo" ) );
+ assertEquals( "http://commons.apache.org/digester/Alpha", nsmap.get( "alpha" ) );
+ assertEquals( "http://commons.apache.org/digester/Bar", nsmap.get( "bar" ) );
}
// ------------------------------------------------ Utility Support Methods
-
/**
- * Return an appropriate InputStream for the specified test file (which
- * must be inside our current package.
- *
+ * Return an appropriate InputStream for the specified test file (which must be inside our current package.
+ *
* @param name Name of the test file we want
- *
* @exception IOException if an input/output error occurs
*/
- protected InputStream getInputStream(String name) throws IOException {
+ protected InputStream getInputStream( String name )
+ throws IOException
+ {
- return (this.getClass().getResourceAsStream
- ("/org/apache/commons/digester3/" + name));
+ return ( this.getClass().getResourceAsStream( "/org/apache/commons/digester3/" + name ) );
}
}
-