diff --git a/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java b/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java index c9bfe0a5..95756e38 100644 --- a/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java +++ b/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java @@ -143,6 +143,19 @@ public class JewishDate implements Comparable, Cloneable { */ public static final int ADAR_II = 13; + private static final int MONTH_JANUARY = 1; + private static final int MONTH_FEBRUARY = MONTH_JANUARY + 1; + private static final int MONTH_MARCH = MONTH_FEBRUARY + 1; + private static final int MONTH_APRIL = MONTH_MARCH + 1; + private static final int MONTH_MAY = MONTH_APRIL + 1; + private static final int MONTH_JUNE = MONTH_MAY + 1; + private static final int MONTH_JULY = MONTH_JUNE + 1; + private static final int MONTH_AUGUST = MONTH_JULY + 1; + private static final int MONTH_SEPTEMBER = MONTH_AUGUST + 1; + private static final int MONTH_OCTOBER = MONTH_SEPTEMBER + 1; + private static final int MONTH_NOVEMBER = MONTH_OCTOBER + 1; + private static final int MONTH_DECEMBER = MONTH_NOVEMBER + 1; + /** * the Jewish epoch using the RD (Rata Die/Fixed Date or Reingold Dershowitz) day used in Calendrical Calculations. * Day 1 is January 1, 0001 of the Gregorian calendar @@ -320,11 +333,11 @@ private static int getLastDayOfGregorianMonth(int year, int month) { */ private static LocalDate absDateToDate(int absDate) { int year = absDate / 366; // Search forward year by year from approximate year - while (absDate >= gregorianDateToAbsDate(year + 1, 1, 1)) { + while (absDate >= gregorianDateToAbsDate(year + 1, MONTH_JANUARY, 1)) { year++; } - int month = 1; // Search forward month by month from January + int month = MONTH_JANUARY; // Search forward month by month from January while (absDate > gregorianDateToAbsDate(year, month, getLastDayOfGregorianMonth(year, month))) { month++; } @@ -356,7 +369,7 @@ public int getAbsDate() { */ private static int gregorianDateToAbsDate(int year, int month, int dayOfMonth) { int absDate = dayOfMonth; - for (int m = month - 1; m > 0; m--) { + for (int m = month - 1; m >= MONTH_JANUARY; m--) { absDate += getLastDayOfGregorianMonth(year, m); // days in prior months of the year } @@ -1030,7 +1043,7 @@ public void resetDate() { /** * Subtracts the number of days passed in from the currently set date. * @param days the number of days to subtract. - * @see plusDays(int) + * @see #plusDays(int) */ public void minusDays(int days){ if (days < 1) { @@ -1044,7 +1057,7 @@ public void minusDays(int days){ * Add the number of days passed in to the currently set date. * @param days the number of days to add. * - * @see minusDays(int) + * @see #minusDays(int) */ public void plusDays(int days){ if (days < 1) { @@ -1057,7 +1070,7 @@ public void plusDays(int days){ * Add the number of months passed in to the currently set date. If the day of the month prior to addition is the 30th, and * the target month only has 29 days, the date will be clamped to the 29th. * @param months the number of months to add. - * @see minusMonths(int) + * @see #plusMonths(int) */ public void plusMonths(int months){ if (months < 1) { @@ -1084,7 +1097,7 @@ public void plusMonths(int months){ * Subtracts the number of months passed in to the currently set date. If the day of the month prior to subtraction * is the 30th, and the target month only has 29 days, the date will be clamped to the 29th. * @param months the number of months to add. - * @see plusMonths(int) + * @see #plusMonths(int) */ public void minusMonths(int months){ if (months < 1) { @@ -1121,7 +1134,7 @@ public void minusMonths(int months){ * @param useAdarAlephForLeapYear if set to true and the current month is Adar on a non-leap year and it is being moved * forward to a leap year, it will be set to Adar I, and if set to false it will set to Adar II. This will be * ignored if the month is not set to Adar. - * @see minusYears(int, boolean) + * @see #minusYears(int, boolean) */ public void plusYears(int years, boolean useAdarAlephForLeapYear){ if (years < 1) { @@ -1158,7 +1171,7 @@ public void plusYears(int years, boolean useAdarAlephForLeapYear){ * @param useAdarAlephForLeapYear if set to true and the current month is Adar on a non-leap year and it is being * subtracted to a leap year, it will be set to Adar I, and if set to false it will set to Adar II. This will * be ignored if the month is not set to Adar. - * @see plusYears(int, boolean) + * @see #plusYears(int, boolean) */ public void minusYears(int years, boolean useAdarAlephForLeapYear){ if (years < 1) { diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java index 2e549b98..359f4d8e 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_DaysInJewishMonth.java @@ -4,7 +4,10 @@ package com.kosherjava.zmanim.hebrewcalendar; -import org.junit.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; /** * Validate the days in a Hebrew month (in various types of years) are correct. @@ -62,8 +65,8 @@ private void assertHaser(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertFalse(jewishDate.isCheshvanLong()); - Assert.assertTrue(jewishDate.isKislevShort()); + assertFalse(jewishDate.isCheshvanLong()); + assertTrue(jewishDate.isKislevShort()); } @@ -72,7 +75,7 @@ private void assertHaserLeap(int year) { jewishDate.setJewishYear(year); assertHaser(year); - Assert.assertTrue(jewishDate.isJewishLeapYear()); + assertTrue(jewishDate.isJewishLeapYear()); } @@ -80,8 +83,8 @@ private void assertQesidrah(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertFalse(jewishDate.isCheshvanLong( )); - Assert.assertFalse(jewishDate.isKislevShort( )); + assertFalse(jewishDate.isCheshvanLong()); + assertFalse(jewishDate.isKislevShort()); } @@ -90,7 +93,7 @@ private void assertQesidrahLeap(int year) { jewishDate.setJewishYear(year); assertQesidrah(year); - Assert.assertTrue(jewishDate.isJewishLeapYear( )); + assertTrue(jewishDate.isJewishLeapYear()); } @@ -98,8 +101,8 @@ private void assertShalem(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertTrue(jewishDate.isCheshvanLong( )); - Assert.assertFalse(jewishDate.isKislevShort( )); + assertTrue(jewishDate.isCheshvanLong()); + assertFalse(jewishDate.isKislevShort()); } @@ -108,7 +111,7 @@ private void assertShalemLeap(int year) { jewishDate.setJewishYear(year); assertShalem(year); - Assert.assertTrue(jewishDate.isJewishLeapYear( )); + assertTrue(jewishDate.isJewishLeapYear()); } } // End of UT_DaysInJewishMonth class diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java index 9a5a2bfb..92091d83 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_GregorianDateNavigation.java @@ -4,7 +4,9 @@ package com.kosherjava.zmanim.hebrewcalendar; -import org.junit.*; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; import java.time.LocalDate; import java.time.Month; @@ -18,113 +20,113 @@ public class UT_GregorianDateNavigation { @Test public void gregorianForwardMonthToMonth() { - LocalDate localDate = LocalDate.of(2011, Month.JANUARY,31); + LocalDate localDate = LocalDate.of(2011, Month.JANUARY, 31); JewishDate hebrewDate = new JewishDate(localDate); - Assert.assertEquals(5771, hebrewDate.getJewishYear()); - Assert.assertEquals(11, hebrewDate.getJewishMonth()); - Assert.assertEquals(26, hebrewDate.getJewishDayOfMonth()); + assertEquals(5771, hebrewDate.getJewishYear()); + assertEquals(JewishDate.SHEVAT, hebrewDate.getJewishMonth()); + assertEquals(26, hebrewDate.getJewishDayOfMonth()); hebrewDate.plusDays(1); - Assert.assertEquals(2, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(11, hebrewDate.getJewishMonth()); - Assert.assertEquals(27, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.FEBRUARY, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.SHEVAT, hebrewDate.getJewishMonth()); + assertEquals(27, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.FEBRUARY,28); + localDate = LocalDate.of(2011, Month.FEBRUARY, 28); hebrewDate = new JewishDate(localDate); - Assert.assertEquals(2, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(28, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(12, hebrewDate.getJewishMonth()); - Assert.assertEquals(24, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.FEBRUARY, hebrewDate.getLocalDate().getMonth()); + assertEquals(28, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.ADAR, hebrewDate.getJewishMonth()); + assertEquals(24, hebrewDate.getJewishDayOfMonth()); hebrewDate.plusDays(1); - Assert.assertEquals(3, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(12, hebrewDate.getJewishMonth()); - Assert.assertEquals(25, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.MARCH, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.ADAR, hebrewDate.getJewishMonth()); + assertEquals(25, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.MARCH,31); + localDate = LocalDate.of(2011, Month.MARCH, 31); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(4, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(13, hebrewDate.getJewishMonth()); - Assert.assertEquals(26, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.APRIL, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.ADAR_II, hebrewDate.getJewishMonth()); + assertEquals(26, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.APRIL,30); + localDate = LocalDate.of(2011, Month.APRIL, 30); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(5, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(1, hebrewDate.getJewishMonth()); - Assert.assertEquals(27, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.MAY, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.NISSAN, hebrewDate.getJewishMonth()); + assertEquals(27, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.MAY,31); + localDate = LocalDate.of(2011, Month.MAY, 31); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(6, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(2, hebrewDate.getJewishMonth()); - Assert.assertEquals(28, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.JUNE, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.IYAR, hebrewDate.getJewishMonth()); + assertEquals(28, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.JUNE,30); + localDate = LocalDate.of(2011, Month.JUNE, 30); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(7, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(3, hebrewDate.getJewishMonth()); - Assert.assertEquals(29, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.JULY, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.SIVAN, hebrewDate.getJewishMonth()); + assertEquals(29, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.JULY,31); + localDate = LocalDate.of(2011, Month.JULY, 31); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(8, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(5, hebrewDate.getJewishMonth()); - Assert.assertEquals(1, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.AUGUST, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.AV, hebrewDate.getJewishMonth()); + assertEquals(1, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.AUGUST,31); + localDate = LocalDate.of(2011, Month.AUGUST, 31); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(9, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(6, hebrewDate.getJewishMonth()); - Assert.assertEquals(2, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.SEPTEMBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.ELUL, hebrewDate.getJewishMonth()); + assertEquals(2, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.SEPTEMBER,30); + localDate = LocalDate.of(2011, Month.SEPTEMBER, 30); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(10, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(7, hebrewDate.getJewishMonth()); - Assert.assertEquals(3, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.OCTOBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.TISHREI, hebrewDate.getJewishMonth()); + assertEquals(3, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.OCTOBER,31); + localDate = LocalDate.of(2011, Month.OCTOBER, 31); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(11, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(5772, hebrewDate.getJewishYear()); - Assert.assertEquals(8, hebrewDate.getJewishMonth()); - Assert.assertEquals(4, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.NOVEMBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(5772, hebrewDate.getJewishYear()); + assertEquals(JewishDate.CHESHVAN, hebrewDate.getJewishMonth()); + assertEquals(4, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.NOVEMBER,30); + localDate = LocalDate.of(2011, Month.NOVEMBER, 30); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(12, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(9, hebrewDate.getJewishMonth()); - Assert.assertEquals(5, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.DECEMBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.KISLEV, hebrewDate.getJewishMonth()); + assertEquals(5, hebrewDate.getJewishDayOfMonth()); - localDate = LocalDate.of(2011, Month.DECEMBER,31); + localDate = LocalDate.of(2011, Month.DECEMBER, 31); hebrewDate = new JewishDate(localDate); hebrewDate.plusDays(1); - Assert.assertEquals(2012, hebrewDate.getLocalDate().getYear()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(10, hebrewDate.getJewishMonth()); - Assert.assertEquals(6, hebrewDate.getJewishDayOfMonth()); + assertEquals(2012, hebrewDate.getLocalDate().getYear()); + assertEquals(Month.JANUARY, hebrewDate.getLocalDate().getMonth()); + assertEquals(1, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.TEVES, hebrewDate.getJewishMonth()); + assertEquals(6, hebrewDate.getJewishDayOfMonth()); } @@ -134,100 +136,100 @@ public void gregorianBackwardMonthToMonth() { LocalDate localDate = LocalDate.of(2011, Month.JANUARY, 1); JewishDate hebrewDate = new JewishDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(2010, hebrewDate.getLocalDate().getYear()); - Assert.assertEquals(12, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(10, hebrewDate.getJewishMonth()); - Assert.assertEquals(24, hebrewDate.getJewishDayOfMonth()); + assertEquals(2010, hebrewDate.getLocalDate().getYear()); + assertEquals(Month.DECEMBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.TEVES, hebrewDate.getJewishMonth()); + assertEquals(24, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.DECEMBER, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(11, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(9, hebrewDate.getJewishMonth()); - Assert.assertEquals(23, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.NOVEMBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.KISLEV, hebrewDate.getJewishMonth()); + assertEquals(23, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.NOVEMBER, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(10, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(8, hebrewDate.getJewishMonth()); - Assert.assertEquals(23, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.OCTOBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.CHESHVAN, hebrewDate.getJewishMonth()); + assertEquals(23, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.OCTOBER, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(9, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(7, hebrewDate.getJewishMonth()); - Assert.assertEquals(22, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.SEPTEMBER, hebrewDate.getLocalDate().getMonth()); + assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.TISHREI, hebrewDate.getJewishMonth()); + assertEquals(22, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.SEPTEMBER, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(8, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(5770, hebrewDate.getJewishYear()); - Assert.assertEquals(6, hebrewDate.getJewishMonth()); - Assert.assertEquals(21, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.AUGUST, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(5770, hebrewDate.getJewishYear()); + assertEquals(JewishDate.ELUL, hebrewDate.getJewishMonth()); + assertEquals(21, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.AUGUST, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(7, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(5, hebrewDate.getJewishMonth()); - Assert.assertEquals(20, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.JULY, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.AV, hebrewDate.getJewishMonth()); + assertEquals(20, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.JULY, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(6, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(4, hebrewDate.getJewishMonth()); - Assert.assertEquals(18, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.JUNE, hebrewDate.getLocalDate().getMonth()); + assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.TAMMUZ, hebrewDate.getJewishMonth()); + assertEquals(18, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.JUNE, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(5, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(3, hebrewDate.getJewishMonth()); - Assert.assertEquals(18, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.MAY, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.SIVAN, hebrewDate.getJewishMonth()); + assertEquals(18, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.MAY, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(4, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(2, hebrewDate.getJewishMonth()); - Assert.assertEquals(16, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.APRIL, hebrewDate.getLocalDate().getMonth()); + assertEquals(30, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.IYAR, hebrewDate.getJewishMonth()); + assertEquals(16, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.APRIL, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(3, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(1, hebrewDate.getJewishMonth()); - Assert.assertEquals(16, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.MARCH, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.NISSAN, hebrewDate.getJewishMonth()); + assertEquals(16, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.MARCH, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(2, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(28, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(12, hebrewDate.getJewishMonth()); - Assert.assertEquals(14, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.FEBRUARY, hebrewDate.getLocalDate().getMonth()); + assertEquals(28, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.ADAR, hebrewDate.getJewishMonth()); + assertEquals(14, hebrewDate.getJewishDayOfMonth()); localDate = LocalDate.of(2010, Month.FEBRUARY, 1); hebrewDate.setGregorianDate(localDate); hebrewDate.minusDays(1); - Assert.assertEquals(1, hebrewDate.getLocalDate().getMonthValue()); - Assert.assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); - Assert.assertEquals(11, hebrewDate.getJewishMonth()); - Assert.assertEquals(16, hebrewDate.getJewishDayOfMonth()); + assertEquals(Month.JANUARY, hebrewDate.getLocalDate().getMonth()); + assertEquals(31, hebrewDate.getLocalDate().getDayOfMonth()); + assertEquals(JewishDate.SHEVAT, hebrewDate.getJewishMonth()); + assertEquals(16, hebrewDate.getJewishDayOfMonth()); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java index aad45602..d9311df5 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishDateNavigation.java @@ -4,11 +4,13 @@ package com.kosherjava.zmanim.hebrewcalendar; -import org.junit.*; +import static org.junit.Assert.assertEquals; + + +import org.junit.Test; import java.time.LocalDate; import java.time.Month; -import java.util.Calendar; /** * @@ -21,11 +23,11 @@ public class UT_JewishDateNavigation { public void jewishForwardMonthToMonth() { JewishDate jewishDate = new JewishDate(); - jewishDate.setJewishDate(5771, 1, 1); + jewishDate.setJewishDate(5771, JewishDate.NISSAN, 1); LocalDate localDate = jewishDate.getLocalDate(); - Assert.assertEquals(5, localDate.getDayOfMonth()); - Assert.assertEquals(Month.APRIL, localDate.getMonth()); - Assert.assertEquals(2011, localDate.getYear()); + assertEquals(5, localDate.getDayOfMonth()); + assertEquals(Month.APRIL, localDate.getMonth()); + assertEquals(2011, localDate.getYear()); } @@ -35,11 +37,11 @@ public void computeRoshHashana5771() { // At one point, this test was failing as the JewishDate class spun through a never-ending loop... JewishDate jewishDate = new JewishDate(); - jewishDate.setJewishDate(5771, 7, 1); + jewishDate.setJewishDate(5771, JewishDate.TISHREI, 1); LocalDate localDate = jewishDate.getLocalDate(); - Assert.assertEquals(9, localDate.getDayOfMonth()); - Assert.assertEquals(Month.SEPTEMBER, localDate.getMonth()); - Assert.assertEquals(2010, localDate.getYear()); + assertEquals(9, localDate.getDayOfMonth()); + assertEquals(Month.SEPTEMBER, localDate.getMonth()); + assertEquals(2010, localDate.getYear()); } @Test @@ -48,16 +50,16 @@ public void addYearsUsesConfiguredAdarMonthWhenMovingToLeapYear() { JewishDate adarAlephDate = new JewishDate(); adarAlephDate.setJewishDate(5783, JewishDate.ADAR, 10); adarAlephDate.plusYears(1, true); - Assert.assertEquals(5784, adarAlephDate.getJewishYear()); - Assert.assertEquals(JewishDate.ADAR, adarAlephDate.getJewishMonth()); - Assert.assertEquals(10, adarAlephDate.getJewishDayOfMonth()); + assertEquals(5784, adarAlephDate.getJewishYear()); + assertEquals(JewishDate.ADAR, adarAlephDate.getJewishMonth()); + assertEquals(10, adarAlephDate.getJewishDayOfMonth()); JewishDate adarBeisDate = new JewishDate(); adarBeisDate.setJewishDate(5783, JewishDate.ADAR, 10); adarBeisDate.plusYears(1, false); - Assert.assertEquals(5784, adarBeisDate.getJewishYear()); - Assert.assertEquals(JewishDate.ADAR_II, adarBeisDate.getJewishMonth()); - Assert.assertEquals(10, adarBeisDate.getJewishDayOfMonth()); + assertEquals(5784, adarBeisDate.getJewishYear()); + assertEquals(JewishDate.ADAR_II, adarBeisDate.getJewishMonth()); + assertEquals(10, adarBeisDate.getJewishDayOfMonth()); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java index 96c582e3..c97fa76d 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_JewishLeapYear.java @@ -4,6 +4,9 @@ package com.kosherjava.zmanim.hebrewcalendar; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.junit.*; /** @@ -52,7 +55,7 @@ private void shouldBeLeapYear(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertTrue(jewishDate.isJewishLeapYear( )); + assertTrue(jewishDate.isJewishLeapYear()); } @@ -60,7 +63,7 @@ private void shouldNotBeLeapYear(int year) { JewishDate jewishDate = new JewishDate(); jewishDate.setJewishYear(year); - Assert.assertFalse(jewishDate.isJewishLeapYear( )); + assertFalse(jewishDate.isJewishLeapYear()); } } // End of UT_JewishLeapYear class diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java index 60b9d8b7..b0e5858f 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/UT_YerushalmiTest.java @@ -1,10 +1,10 @@ package com.kosherjava.zmanim.hebrewcalendar; -import java.util.Calendar; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -import org.junit.*; +import org.junit.Test; -import junit.framework.TestCase; public class UT_YerushalmiTest { private static HebrewDateFormatter hdf = new HebrewDateFormatter(); static { @@ -13,40 +13,40 @@ public class UT_YerushalmiTest { @Test public void testCorrectDaf1() { - JewishCalendar jewishCalendar = new JewishCalendar(5777,JewishCalendar.ELUL,10); - Assert.assertEquals(8, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(29, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + JewishCalendar jewishCalendar = new JewishCalendar(5777, JewishDate.ELUL, 10); + assertEquals(8, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(29, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } @Test public void testCorrectDaf2() { - JewishCalendar jewishCalendar = new JewishCalendar(5744,JewishCalendar.KISLEV,1); - Assert.assertEquals(26, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(32, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + JewishCalendar jewishCalendar = new JewishCalendar(5744, JewishDate.KISLEV, 1); + assertEquals(26, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(32, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } @Test public void testCorrectDaf3() { - JewishCalendar jewishCalendar = new JewishCalendar(5782,JewishCalendar.SIVAN,1); - Assert.assertEquals(15, jewishCalendar.getDafYomiYerushalmi().getDaf()); - Assert.assertEquals(33, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); + JewishCalendar jewishCalendar = new JewishCalendar(5782, JewishDate.SIVAN, 1); + assertEquals(15, jewishCalendar.getDafYomiYerushalmi().getDaf()); + assertEquals(33, jewishCalendar.getDafYomiYerushalmi().getMasechtaNumber()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } @Test public void testCorrectSpecialDate() { - JewishCalendar jewishCalendar = new JewishCalendar(5775,JewishCalendar.TISHREI,10); - Assert.assertNull(jewishCalendar.getDafYomiYerushalmi()); + JewishCalendar jewishCalendar = new JewishCalendar(5775, JewishDate.TISHREI, 10); + assertNull(jewishCalendar.getDafYomiYerushalmi()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); - jewishCalendar = new JewishCalendar(5783,JewishCalendar.AV,9); - Assert.assertNull(jewishCalendar.getDafYomiYerushalmi()); + jewishCalendar = new JewishCalendar(5783, JewishDate.AV, 9); + assertNull(jewishCalendar.getDafYomiYerushalmi()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); - jewishCalendar = new JewishCalendar(5775,JewishCalendar.AV,10);// 9 Av delayed to Sunday 10 Av - Assert.assertNull(jewishCalendar.getDafYomiYerushalmi()); + jewishCalendar = new JewishCalendar(5775, JewishDate.AV, 10);// 9 Av delayed to Sunday 10 Av + assertNull(jewishCalendar.getDafYomiYerushalmi()); System.out.println(hdf.formatDafYomiYerushalmi(jewishCalendar.getDafYomiYerushalmi())); } diff --git a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java index 5b24bd7c..159d71d5 100644 --- a/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java +++ b/src/test/java/com/kosherjava/zmanim/hebrewcalendar/YomiCalculatorTest.java @@ -1,6 +1,7 @@ package com.kosherjava.zmanim.hebrewcalendar; -import org.junit.Assert; +import static org.junit.Assert.assertEquals; + import org.junit.Test; public class YomiCalculatorTest { @@ -13,8 +14,8 @@ public class YomiCalculatorTest { public void testCorrectDaf1() { JewishCalendar jewishCalendar = new JewishCalendar(5685, JewishDate.KISLEV, 12); Daf daf = YomiCalculator.getDafYomiBavli(jewishCalendar); - Assert.assertEquals(5, daf.getMasechtaNumber()); - Assert.assertEquals(2, daf.getDaf()); + assertEquals(5, daf.getMasechtaNumber()); + assertEquals(2, daf.getDaf()); System.out.println(hdf.formatDafYomiBavli(jewishCalendar.getDafYomiBavli())); } @@ -22,8 +23,8 @@ public void testCorrectDaf1() { public void testCorrectDaf2() { JewishCalendar jewishCalendar = new JewishCalendar(5736, JewishDate.ELUL, 26); Daf daf = YomiCalculator.getDafYomiBavli(jewishCalendar); - Assert.assertEquals(4, daf.getMasechtaNumber()); - Assert.assertEquals(14, daf.getDaf()); + assertEquals(4, daf.getMasechtaNumber()); + assertEquals(14, daf.getDaf()); System.out.println(hdf.formatDafYomiBavli(jewishCalendar.getDafYomiBavli())); } @@ -31,8 +32,8 @@ public void testCorrectDaf2() { public void testCorrectDaf3() { JewishCalendar jewishCalendar = new JewishCalendar(5777, JewishDate.ELUL, 10); Daf daf = YomiCalculator.getDafYomiBavli(jewishCalendar); - Assert.assertEquals(23, daf.getMasechtaNumber()); - Assert.assertEquals(47, daf.getDaf()); + assertEquals(23, daf.getMasechtaNumber()); + assertEquals(47, daf.getDaf()); System.out.println(hdf.formatDafYomiBavli(jewishCalendar.getDafYomiBavli())); } }