Refactored code

Replaced deprecated SAXBuilder constructor call
This commit is contained in:
Patrick Gotthard 2014-04-12 23:26:02 +02:00
parent f8cc306302
commit c217eca998
2 changed files with 23 additions and 18 deletions

View file

@ -8,6 +8,7 @@ import junit.framework.TestCase;
import org.jdom2.Document; import org.jdom2.Document;
import org.jdom2.input.SAXBuilder; import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaders;
import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeed;
@ -16,20 +17,21 @@ import com.sun.syndication.io.WireFeedInput;
/** /**
* @author pat, tucu * @author pat, tucu
* *
*/ */
public abstract class FeedTest extends TestCase { public abstract class FeedTest extends TestCase {
private final String _feedFileName;
private Document _jDomDoc = null; private final String fileName;
private WireFeed _wireFeed = null; private Document jDomDoc = null;
private SyndFeed _syndFeed = null; private WireFeed wireFeed = null;
private SyndFeed syndFeed = null;
protected FeedTest(final String feedFileName) { protected FeedTest(final String feedFileName) {
_feedFileName = feedFileName; fileName = feedFileName;
} }
protected String getFeedFileName() { protected String getFeedFileName() {
return _feedFileName; return fileName;
} }
protected Reader getFeedReader() throws Exception { protected Reader getFeedReader() throws Exception {
@ -39,7 +41,7 @@ public abstract class FeedTest extends TestCase {
} }
protected Document getJDomDoc() throws Exception { protected Document getJDomDoc() throws Exception {
final SAXBuilder saxBuilder = new SAXBuilder(false); final SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING);
return saxBuilder.build(getFeedReader()); return saxBuilder.build(getFeedReader());
} }
@ -54,24 +56,24 @@ public abstract class FeedTest extends TestCase {
} }
protected Document getCachedJDomDoc() throws Exception { protected Document getCachedJDomDoc() throws Exception {
if (_jDomDoc == null) { if (jDomDoc == null) {
_jDomDoc = getJDomDoc(); jDomDoc = getJDomDoc();
} }
return _jDomDoc; return jDomDoc;
} }
protected WireFeed getCachedWireFeed() throws Exception { protected WireFeed getCachedWireFeed() throws Exception {
if (_wireFeed == null) { if (wireFeed == null) {
_wireFeed = getWireFeed(); wireFeed = getWireFeed();
} }
return _wireFeed; return wireFeed;
} }
protected SyndFeed getCachedSyndFeed() throws Exception { protected SyndFeed getCachedSyndFeed() throws Exception {
if (_syndFeed == null) { if (syndFeed == null) {
_syndFeed = getSyndFeed(); syndFeed = getSyndFeed();
} }
return _syndFeed; return syndFeed;
} }
} }

View file

@ -45,6 +45,8 @@ public class TestXmlReader extends TestCase {
protected void _testRawNoBomValid(final String encoding) throws Exception { protected void _testRawNoBomValid(final String encoding) throws Exception {
// TODO review this test
InputStream is = getXmlStream("no-bom", "xml", encoding, encoding); InputStream is = getXmlStream("no-bom", "xml", encoding, encoding);
XmlReader xmlReader = new XmlReader(is, false); XmlReader xmlReader = new XmlReader(is, false);
assertEquals(xmlReader.getEncoding(), "UTF-8"); assertEquals(xmlReader.getEncoding(), "UTF-8");
@ -170,7 +172,8 @@ public class TestXmlReader extends TestCase {
final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml" : "xml-prolog-encoding", streamEnc, prologEnc); final InputStream is = getXmlStream(bomEnc, prologEnc == null ? "xml" : "xml-prolog-encoding", streamEnc, prologEnc);
final XmlReader xmlReader = new XmlReader(is, cT, false); final XmlReader xmlReader = new XmlReader(is, cT, false);
if (!streamEnc.equals("UTF-16")) { if (!streamEnc.equals("UTF-16")) {
// we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for the chars used for detection // we can not assert things here becuase UTF-8, US-ASCII and ISO-8859-1 look alike for
// the chars used for detection
} else { } else {
assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc); assertEquals(xmlReader.getEncoding().substring(0, streamEnc.length()), streamEnc);
} }