Hi guys,
this patch is an initial refactoring of the Unit tests in core. It
breaks up the CoreTest and moves the Unit Tests to multiple entity
related test classes.
btw it would be really great to have an Eclipse Formatter template.
regards
Christine
Index: core/src/test/java/org/apache/abdera/test/core/CoreTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/test/core/CoreTest.java (Revision 940504)
+++ core/src/test/java/org/apache/abdera/test/core/CoreTest.java (Arbeitskopie)
@@ -18,46 +18,18 @@
package org.apache.abdera.test.core;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.StringReader;
-import java.util.Calendar;
-import java.util.Date;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.i18n.text.io.CompressionUtil;
-import org.apache.abdera.model.AtomDate;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.util.AbderaConfiguration;
-import org.apache.abdera.util.Configuration;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.util.XmlRestrictedCharReader;
-import org.easymock.EasyMock;
import org.junit.Test;
-public class CoreTest implements Constants {
-
- @Test
- public void testDefaultConfigurationProperties() {
- Configuration config = new AbderaConfiguration();
- assertEquals("org.apache.abdera.parser.stax.FOMFactory",
- config.getConfigurationOption(CONFIG_FACTORY, DEFAULT_FACTORY)
- );
- assertEquals("org.apache.abdera.parser.stax.FOMParser",
- config.getConfigurationOption(CONFIG_PARSER, DEFAULT_PARSER)
- );
- assertEquals("org.apache.abdera.parser.stax.FOMXPath",
- config.getConfigurationOption(CONFIG_XPATH, DEFAULT_XPATH)
- );
- }
+public class CoreTest {
@Test
public void testUriNormalization() {
@@ -83,66 +55,8 @@
}
}
- @Test
- public void testAtomDate() {
- Date now = new Date();
- AtomDate atomNow = AtomDate.valueOf(now);
- String rfc3339 = atomNow.getValue();
- atomNow = AtomDate.valueOf(rfc3339);
- Date parsed = atomNow.getDate();
- assertEquals(now, parsed);
- }
@Test
- public void testAtomDate2() {
- String date = "2007-12-13T14:15:16.123Z";
- AtomDate atomDate = new AtomDate(date);
- Calendar calendar = atomDate.getCalendar();
- atomDate = new AtomDate(calendar);
- assertEquals(date,atomDate.toString());
- }
-
- @Test
- public void testAtomDate3() {
- long date = System.currentTimeMillis();
- AtomDate atomDate = new AtomDate(date);
- Calendar calendar = atomDate.getCalendar();
- atomDate = new AtomDate(calendar);
- assertEquals(date,atomDate.getTime());
- }
-
- @Test
- public void testXmlRestrictedCharReader() throws Exception {
- String s = "\u0001abcdefghijklmnop\u0002";
- StringReader r = new StringReader(s);
- XmlRestrictedCharReader x = new XmlRestrictedCharReader(r);
- char[] chars = new char[s.length()+1];
- int n = x.read(chars); // the first and last characters should never show up
- assertEquals(s.length()-2,n);
- assertEquals("abcdefghijklmnop",new String(chars,0,n));
- }
-
- @Test
- public void testMimeTypeHelper() throws Exception {
- assertTrue(MimeTypeHelper.isApp("application/atomsvc+xml"));
- assertFalse(MimeTypeHelper.isApp("application/atomserv+xml"));
- assertTrue(MimeTypeHelper.isAtom("application/atom+xml"));
- assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"entry\""));
- assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"feed\""));
- assertTrue(MimeTypeHelper.isEntry("application/atom+xml;type=\"entry\""));
- assertTrue(MimeTypeHelper.isFeed("application/atom+xml;type=\"feed\""));
- assertTrue(MimeTypeHelper.isText("text/plain"));
- assertTrue(MimeTypeHelper.isXml("application/xml"));
-
- String[] types = MimeTypeHelper.condense("image/png","image/gif","image/png","image/*");
- assertEquals(1, types.length);
- assertEquals("image/*",types[0]);
-
- assertTrue(MimeTypeHelper.isEntry(MimeTypeHelper.getMimeType(EasyMock.createMock(Entry.class))));
- assertTrue(MimeTypeHelper.isFeed(MimeTypeHelper.getMimeType(EasyMock.createMock(Feed.class))));
- }
-
- @Test
public void testCompressionUtil() throws Exception {
String s = "abcdefg";
ByteArrayOutputStream out = new ByteArrayOutputStream();
Index: core/src/test/java/org/apache/abdera/test/core/EntityTagTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/test/core/EntityTagTest.java (Revision 940504)
+++ core/src/test/java/org/apache/abdera/test/core/EntityTagTest.java (Arbeitskopie)
@@ -1,80 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. 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. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-package org.apache.abdera.test.core;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.abdera.util.EntityTag;
-import org.junit.Test;
-
-public class EntityTagTest {
-
- @Test
- public void testEntityTag() throws Exception {
- String[] tags = {
- "hello",
- "\"hello\"",
- "W/\"hello\"",
- "*"
- };
- EntityTag[] etags = new EntityTag[tags.length];
- for (int n = 0; n < tags.length; n++) {
- etags[n] = new EntityTag(tags[n]);
- }
- assertFalse(etags[0].isWeak());
- assertFalse(etags[0].isWild());
- assertFalse(etags[1].isWeak());
- assertFalse(etags[1].isWild());
- assertTrue(etags[2].isWeak());
- assertFalse(etags[2].isWild());
- assertFalse(etags[3].isWeak());
- assertTrue(etags[3].isWild());
- assertEquals("hello", etags[0].getTag());
- assertEquals("hello", etags[1].getTag());
- assertEquals("hello", etags[2].getTag());
- assertEquals("*", etags[3].getTag());
- assertEquals(tags[1], etags[0].toString());
- assertEquals(tags[1], etags[1].toString());
- assertEquals(tags[2], etags[2].toString());
- assertEquals(tags[3], etags[3].toString());
-
- assertTrue(EntityTag.matches(etags[3], etags[0]));
- assertTrue(EntityTag.matches(etags[3], etags[1]));
- assertTrue(EntityTag.matches(etags[3], etags[2]));
- assertTrue(EntityTag.matches(etags[3], etags[3]));
-
- assertTrue(EntityTag.matches(etags[0], etags[1]));
- assertFalse(EntityTag.matches(etags[0], etags[2]));
-
- assertTrue(EntityTag.matchesAny(etags[3], new EntityTag[] {etags[0], etags[1], etags[2]}));
- assertTrue(EntityTag.matchesAny(etags[0], new EntityTag[] {etags[3], etags[1], etags[2]}));
- assertTrue(EntityTag.matchesAny(etags[1], new EntityTag[] {etags[0], etags[3], etags[2]}));
- assertTrue(EntityTag.matchesAny(etags[2], new EntityTag[] {etags[0], etags[1], etags[3]}));
-
- java.util.Arrays.sort(etags);
- assertEquals(tags[3],etags[0].toString());
- assertEquals(tags[1],etags[1].toString());
- assertEquals(tags[1],etags[2].toString());
- assertEquals(tags[2],etags[3].toString());
- EntityTag etag = EntityTag.generate("a","b","c","d");
- assertEquals("\"e2fc714c4727ee9395f324cd2e7f331f\"", etag.toString());
- }
-
-}
Index: core/src/test/java/org/apache/abdera/model/AtomDateTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/model/AtomDateTest.java (Revision 940504)
+++ core/src/test/java/org/apache/abdera/model/AtomDateTest.java (Arbeitskopie)
@@ -5,6 +5,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
+import java.util.Calendar;
import java.util.Date;
import org.junit.Test;
@@ -66,5 +67,40 @@
assertEquals(ad, adClone);
assertNotSame(ad, adClone);
}
-
+
+ @Test
+ public void testAtomDate() {
+ Date now = new Date();
+ AtomDate atomNow = AtomDate.valueOf(now);
+ String rfc3339 = atomNow.getValue();
+ atomNow = AtomDate.valueOf(rfc3339);
+ Date parsed = atomNow.getDate();
+ assertEquals(now, parsed);
+ }
+
+ @Test
+ public void testAtomDate2() {
+ String date = "2007-12-13T14:15:16.123Z";
+ AtomDate atomDate = new AtomDate(date);
+ Calendar calendar = atomDate.getCalendar();
+ atomDate = new AtomDate(calendar);
+ assertEquals(date,atomDate.toString());
+ }
+
+
+ @Test
+ public void testAtomDate3() {
+ long date = System.currentTimeMillis();
+ AtomDate atomDate = new AtomDate(date);
+ Calendar calendar = atomDate.getCalendar();
+ atomDate = new AtomDate(calendar);
+ assertEquals(date,atomDate.getTime());
+ }
+
+ @Test (expected=IllegalArgumentException.class)
+ public void testIllegalDateFormat() {
+ String date = "";
+ AtomDate atomDate = new AtomDate(date);
+ }
+
}
Index: core/src/test/java/org/apache/abdera/util/ConfigurationTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/util/ConfigurationTest.java (Revision 0)
+++ core/src/test/java/org/apache/abdera/util/ConfigurationTest.java (Revision 0)
@@ -0,0 +1,40 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ConfigurationTest {
+
+ @Test
+ public void testDefaultConfigurationProperties() {
+ Configuration config = new AbderaConfiguration();
+ assertEquals("org.apache.abdera.parser.stax.FOMFactory",
+ config.getConfigurationOption(Constants.CONFIG_FACTORY, Constants.DEFAULT_FACTORY)
+ );
+ assertEquals("org.apache.abdera.parser.stax.FOMParser",
+ config.getConfigurationOption(Constants.CONFIG_PARSER, Constants.DEFAULT_PARSER)
+ );
+ assertEquals("org.apache.abdera.parser.stax.FOMXPath",
+ config.getConfigurationOption(Constants.CONFIG_XPATH, Constants.DEFAULT_XPATH)
+ );
+ }
+
+}
Index: core/src/test/java/org/apache/abdera/util/EntityTagTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/util/EntityTagTest.java (Revision 940504)
+++ core/src/test/java/org/apache/abdera/util/EntityTagTest.java (Arbeitskopie)
@@ -15,7 +15,7 @@
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
-package org.apache.abdera.test.core;
+package org.apache.abdera.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Index: core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java (Revision 0)
+++ core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java (Revision 0)
@@ -0,0 +1,51 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class MimeTypeHelperTest {
+
+ @Test
+ public void testMimeTypeHelper() throws Exception {
+ assertTrue(MimeTypeHelper.isApp("application/atomsvc+xml"));
+ assertFalse(MimeTypeHelper.isApp("application/atomserv+xml"));
+ assertTrue(MimeTypeHelper.isAtom("application/atom+xml"));
+ assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"entry\""));
+ assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"feed\""));
+ assertTrue(MimeTypeHelper.isEntry("application/atom+xml;type=\"entry\""));
+ assertTrue(MimeTypeHelper.isFeed("application/atom+xml;type=\"feed\""));
+ assertTrue(MimeTypeHelper.isText("text/plain"));
+ assertTrue(MimeTypeHelper.isXml("application/xml"));
+
+ String[] types = MimeTypeHelper.condense("image/png","image/gif","image/png","image/*");
+ assertEquals(1, types.length);
+ assertEquals("image/*",types[0]);
+
+ assertTrue(MimeTypeHelper.isEntry(MimeTypeHelper.getMimeType(EasyMock.createMock(Entry.class))));
+ assertTrue(MimeTypeHelper.isFeed(MimeTypeHelper.getMimeType(EasyMock.createMock(Feed.class))));
+ }
+
+}
Index: core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java
===================================================================
--- core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java (Revision 0)
+++ core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java (Revision 0)
@@ -0,0 +1,39 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+
+import org.junit.Test;
+
+public class XmlRestrictedCharReaderTest {
+
+ @Test
+ public void testXmlRestrictedCharReader() throws Exception {
+ String s = "\u0001abcdefghijklmnop\u0002";
+ StringReader r = new StringReader(s);
+ XmlRestrictedCharReader x = new XmlRestrictedCharReader(r);
+ char[] chars = new char[s.length()+1];
+ int n = x.read(chars); // the first and last characters should never show up
+ assertEquals(s.length()-2,n);
+ assertEquals("abcdefghijklmnop",new String(chars,0,n));
+ }
+
+}