1 26 27 29 package de.nava.informa.utils; 30 31 import java.io.File ; 32 import java.util.Arrays ; 33 import java.util.Calendar ; 34 import java.util.TimeZone ; 35 36 import de.nava.informa.core.ChannelIF; 37 import de.nava.informa.core.ItemIF; 38 import de.nava.informa.impl.basic.ChannelBuilder; 39 import de.nava.informa.parsers.FeedParser; 40 41 public class TestItemComparator extends InformaTestCase { 42 43 public TestItemComparator(String name) { 44 super("TestItemComparator", name); 45 } 46 47 public void testSort() throws Exception { 48 49 File inpFile = new File (getDataDir(), "snipsnap-org.rss"); 50 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 51 52 Object [] items = channel.getItems().toArray(); 54 Arrays.sort(items, new ItemComparator(true)); 56 57 Calendar cal = Calendar.getInstance(); 59 60 cal.set(2002, Calendar.OCTOBER, 16, 0, 0, 0); 61 cal.setTimeZone(TimeZone.getTimeZone("GMT")); 62 compareDates(cal, items, 0); 63 64 cal.set(2002, Calendar.OCTOBER, 14, 0, 0, 0); 65 cal.setTimeZone(TimeZone.getTimeZone("GMT")); 66 compareDates(cal, items, 1); 67 68 cal.set(2002, Calendar.OCTOBER, 10, 0, 0, 0); 69 cal.setTimeZone(TimeZone.getTimeZone("GMT")); 70 compareDates(cal, items, 2); 71 72 cal.set(2002, Calendar.OCTOBER, 1, 0, 0, 0); 73 cal.setTimeZone(TimeZone.getTimeZone("GMT")); 74 compareDates(cal, items, 8); 75 76 cal.set(2002, Calendar.SEPTEMBER, 30, 0, 0, 0); 77 cal.setTimeZone(TimeZone.getTimeZone("GMT")); 78 compareDates(cal, items, 9); 79 80 87 } 88 89 private void compareDates(Calendar expectedCal, Object [] actualItems, 90 int index) { 91 ItemIF item = (ItemIF) actualItems[index]; 92 long milliExp = expectedCal.getTime().getTime(); 94 long milliAct = item.getDate().getTime(); 95 96 assertEquals("Wrong date for item " + (index+1), 97 milliExp / 1000, milliAct / 1000); 98 } 99 100 } 101 | Popular Tags |