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/02/09 08:03:42 UTC
svn commit: r1068767 -
/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java
Author: simonetripodi
Date: Wed Feb 9 07:03:41 2011
New Revision: 1068767
URL: http://svn.apache.org/viewvc?rev=1068767&view=rev
Log:
first checkin of ObjectParamRuleTestCase, adapted versions of the proper on /trunk
old testcases continue pass!
Added:
commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java (with props)
Added: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java?rev=1068767&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java (added)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java Wed Feb 9 07:03:41 2011
@@ -0,0 +1,88 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.digester3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Tests for the {@code ObjectParamRuleTestCase}.
+ *
+ * @author Mark Huisman
+ */
+public class ObjectParamRuleTestCase extends AbstractTestCase {
+
+ /**
+ * Test method calls with the ObjectParamRule rule. It should be possible to
+ * pass any subclass of Object as a parameter, provided that either the element
+ * or the element + attribute has been matched.
+ */
+ @Test
+ public void testBasic() throws SAXException, IOException {
+ //Parse it and obtain the ArrayList
+ ArrayList<?> al = (ArrayList<?>) newBasicDigester(new AbstractRulesModule() {
+
+ @Override
+ protected void configure() {
+ forPattern("arraylist").createObject().ofType(ArrayList.class);
+
+ forPattern("arraylist/A")
+ .callMethod("add").withParamCount(1)
+ .then()
+ .objectParam(new Integer(-9));
+
+ forPattern("arraylist/B")
+ .callMethod("add").withParamCount(1)
+ .then()
+ .objectParam(new Float(3.14159));
+
+ forPattern("arraylist/C")
+ .callMethod("add").withParamCount(1)
+ .then()
+ .objectParam(new Long(999999999));
+
+ forPattern("arraylist/D")
+ .callMethod("add").withParamCount(1)
+ .then()
+ .objectParam("foobarbazbing").matchingAttribute("desc");
+
+ forPattern("arraylist/E")
+ .callMethod("add").withParamCount(1)
+ .then()
+ .objectParam("ignore").matchingAttribute("nonexistentattribute");
+ }
+
+ }).parse(new StringReader("<arraylist><A/><B/><C/><D desc=\"the fourth\"/><E/></arraylist>"));
+ assertNotNull(al);
+ assertEquals(al.size(), 4);
+ assertTrue(al.contains(new Integer(-9)));
+ assertTrue(al.contains(new Float(3.14159)));
+ assertTrue(al.contains(new Long(999999999)));
+ assertTrue(al.contains("foobarbazbing"));
+ assertTrue(!(al.contains("ignore")));
+ }
+
+}
Propchange: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/ObjectParamRuleTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain