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("/rss/channel/pubDate", document);
        assertEquals(matchingNodes.item(0).getTextContent(), "Sat, 01 Jan 2000 00:00:00 -0500");
    }

    @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("/rss/channel/lastBuildDate", document);
        assertEquals(matchingNodes.item(0).getTextContent(), "Sat, 01 Jan 2000 00:00:00 -0500");
    }
}
@@ -138,79 +138,8 @@
 st;%0A
-import org.semper.reformanda.syndication.util.Rfc822DateFormatAdapter;%0A
 impo
@@ -163,16 +163,16 @@
 cument;%0A
+
 import o
@@ -254,22 +254,20 @@
 t.assert
-Equals
+True
 ;%0A%0Apubli
@@ -896,38 +896,36 @@
 ;%0A        assert
-Equals
+True
 (matchingNodes.i
@@ -939,34 +939,44 @@
 getTextContent()
-, 
+.startsWith(
 %22Sat, 01 Jan 200
@@ -976,32 +976,18 @@
 Jan 2000
- 00:00:00 -0500
 %22
+)
 );%0A    %7D
@@ -1381,14 +1381,12 @@
 sert
-Equals
+True
 (mat
@@ -1420,18 +1420,28 @@
 ontent()
-, 
+.startsWith(
 %22Sat, 01
@@ -1453,24 +1453,10 @@
 2000
- 00:00:00 -0500
 %22
+)
 );%0A 

Change date format test to be time zone independent. Differences in locale were causing date issues.