summaryrefslogtreecommitdiff
path: root/test/java
diff options
context:
space:
mode:
authorluccioman <luccioman@users.noreply.github.com>2017-11-07 19:02:09 +0100
committerluccioman <luccioman@users.noreply.github.com>2017-11-07 19:02:09 +0100
commite0eda84c246c59b28fd4d4d2e40209d4e53dbacd (patch)
treee5d964b2bdbee7bd38ceabff2e08ed0e4649c8f5 /test/java
parentf61260c4c7d663dea4d6cb4d81fdfb237d42d711 (diff)
Remove old hard-coded holiday dates from DateDection class.
Replaced with rules based relative to current year as already done for a part of the supported dates.
Diffstat (limited to 'test/java')
-rw-r--r--test/java/net/yacy/document/DateDetectionTest.java61
1 files changed, 60 insertions, 1 deletions
diff --git a/test/java/net/yacy/document/DateDetectionTest.java b/test/java/net/yacy/document/DateDetectionTest.java
index d2c908105..08ee7d7e8 100644
--- a/test/java/net/yacy/document/DateDetectionTest.java
+++ b/test/java/net/yacy/document/DateDetectionTest.java
@@ -1,12 +1,20 @@
package net.yacy.document;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashSet;
+import java.util.Locale;
import java.util.Set;
import java.util.TimeZone;
+
import org.junit.Test;
-import static org.junit.Assert.*;
+
+import net.yacy.document.DateDetection.HolidayMap;
public class DateDetectionTest {
@@ -104,4 +112,55 @@ public class DateDetectionTest {
assertNull("not a date: " + text, d);
}
}
+
+ /**
+ * Compare the dates associated to the holiday name in the map with the expected result
+ * @param holidays holidays map for a given year
+ * @param holidayName the holiday name (key in the map) to check
+ * @param expected the expected formatted dates
+ */
+ private void checkFormattedDates(final HolidayMap holidays, final String holidayName, final String[] expected) {
+ /* Simple format for easier assertions reading */
+ final SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
+ format.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+ final Date[] actual = holidays.get(holidayName);
+
+ String[] actualFormatted = new String[actual.length];
+ for (int i = 0; i < actual.length; i++) {
+ actualFormatted[i] = format.format(actual[i]);
+ }
+ assertArrayEquals(holidayName, expected, actualFormatted);
+ }
+
+ /**
+ * Check generated holidays dates with some references dates
+ */
+ @Test
+ public void testGetHolidays() {
+ HolidayMap holidays = DateDetection.getHolidays(2015);
+
+ /* Dates initially hardcoded in DateDetection class */
+ checkFormattedDates(holidays, "Ostersonntag", new String[] { "2014/04/20", "2015/04/05", "2016/03/27" });
+ checkFormattedDates(holidays, "Weiberfastnacht", new String[] { "2014/02/27", "2015/02/12", "2016/02/04" });
+ checkFormattedDates(holidays, "Rosenmontag", new String[] { "2014/03/03", "2015/02/16", "2016/02/08" });
+ checkFormattedDates(holidays, "Karsamstag", new String[] { "2014/04/19", "2015/04/04", "2016/03/26" });
+ checkFormattedDates(holidays, "Ostern",
+ new String[] { "2014/04/20", "2015/04/05", "2016/03/27", "2014/04/21", "2015/04/06", "2016/03/28" });
+ checkFormattedDates(holidays, "Muttertag", new String[] { "2014/05/11", "2015/05/10", "2016/05/08" });
+ checkFormattedDates(holidays, "Volkstrauertag", new String[] { "2014/11/16", "2015/11/15", "2016/11/13" });
+ checkFormattedDates(holidays, "Totensonntag", new String[] { "2014/11/23", "2015/11/22", "2016/11/20" });
+ checkFormattedDates(holidays, "1. Advent", new String[] { "2014/11/30", "2015/11/29", "2016/11/27" });
+ checkFormattedDates(holidays, "2. Advent", new String[] { "2014/12/07", "2015/12/06", "2016/12/04" });
+ checkFormattedDates(holidays, "3. Advent", new String[] { "2014/12/14", "2015/12/13", "2016/12/11" });
+ checkFormattedDates(holidays, "4. Advent", new String[] { "2014/12/21", "2015/12/20", "2016/12/18" });
+
+ /* Some more recent examples */
+ holidays = DateDetection.getHolidays(2018);
+ checkFormattedDates(holidays, "Ostersonntag", new String[] { "2017/04/16", "2018/04/01", "2019/04/21"});
+ checkFormattedDates(holidays, "Weiberfastnacht", new String[] { "2017/02/23", "2018/02/08", "2019/02/28" });
+ checkFormattedDates(holidays, "Rosenmontag", new String[] { "2017/02/27", "2018/02/12", "2019/03/04" });
+ checkFormattedDates(holidays, "Muttertag", new String[] { "2017/05/14", "2018/05/13", "2019/05/12" });
+ checkFormattedDates(holidays, "1. Advent", new String[] { "2017/12/03", "2018/12/02", "2019/12/01" });
+ }
}