package org.semper.reformanda.syndication.rss;

import org.custommonkey.xmlunit.XpathEngine;
import org.junit.Before;
import org.junit.Test;
import org.semper.reformanda.syndication.util.Rfc822DateFormatAdapter;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import java.util.Date;

import static org.junit.Assert.assertEquals;

public class RssChannelDateFormatTest {

    private Rss rss;
    public final Long DATE_MILLINIUM = 946702800000L;

    @Before
    public void setUp() {
        rss = new Rss();

        final Channel channel = new Channel();
        rss.setChannel(channel);
    }

    @Test
    public void shouldRenderPubDateAsRfc822Format() throws Exception {
        rss.getChannel().setPubDate(new Date(DATE_MILLINIUM));

        final Document document = XmlUtils.getDocument(rss);
        final XpathEngine engine = XmlUtils.getXpathEngine();

        NodeList matchingNodes = engine.getMatchingNodes(String.format("/rss/channel/pubDate[text()='%s']", "Sat, 01 Jan 2000 00:00:00 -0500"), document);
        assertEquals("Improperly formatted publication date", 1, matchingNodes.getLength());
    }

    @Test
    public void shouldRenderBuildDateAsRfc822Format() throws Exception {
        rss.getChannel().setLastBuildDate(new Date(DATE_MILLINIUM));

        final Document document = XmlUtils.getDocument(rss);
        final XpathEngine engine = XmlUtils.getXpathEngine();

        NodeList matchingNodes = engine.getMatchingNodes(String.format("/rss/channel/lastBuildDate[text()='%s']", "Sat, 01 Jan 2000 00:00:00 -0500"), document);
        assertEquals("Improperly formatted last build date", 1, matchingNodes.getLength());
    }
}
@@ -924,38 +924,24 @@
 tchingNodes(
-String.format(
 %22/rss/channe
@@ -953,161 +953,116 @@
 Date
-%5Btext()='%25s'%5D%22, %22Sat, 01 Jan 2000 00:00:00 -0500%22), document);%0A        assertEquals(%22Improperly formatted publication date%22, 1, matchingNodes.getLength()
+%22, document);%0A        assertEquals(matchingNodes.item(0).getTextContent(), %22Sat, 01 Jan 2000 00:00:00 -0500%22
 );%0A 
@@ -1405,22 +1405,8 @@
 des(
-String.format(
 %22/rs
@@ -1432,160 +1432,116 @@
 Date
-%5Btext()='%25s'%5D%22, %22Sat, 01 Jan 2000 00:00:00 -0500%22), document);%0A        assertEquals(%22Improperly formatted last build date%22, 1, matchingNodes.getLength()
+%22, document);%0A        assertEquals(matchingNodes.item(0).getTextContent(), %22Sat, 01 Jan 2000 00:00:00 -0500%22
 );%0A 

Use equality check for date comparison in tests