diff --git a/app/src/main/java/org/cutem/cutecalendar/util/CalendarUtil.java b/app/src/main/java/org/cutem/cutecalendar/util/CalendarUtil.java
index 6a7c7a0..1c3ffd6 100644
--- a/app/src/main/java/org/cutem/cutecalendar/util/CalendarUtil.java
+++ b/app/src/main/java/org/cutem/cutecalendar/util/CalendarUtil.java
@@ -1,7 +1,6 @@
package org.cutem.cutecalendar.util;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import java.util.Calendar;
@@ -186,13 +185,14 @@ public class CalendarUtil {
* Returns a calendar where each field is designated by the corresponding string.
*
* @param calendarString the string that matches "yyyy-mm-dd/hh:mm"
- * @return a {@code Calendar} instance if date is valid; {@code null} otherwise
+ * @return a {@code Calendar} instance
+ * @throws IllegalArgumentException if the only argument is bad formatted
* @see #isValidDateString(String)
*/
- @Nullable
+ @NotNull
public static Calendar constructCalendar(@NotNull String calendarString) {
if (!isValidCalendarString(calendarString)) {
- return null;
+ throw new IllegalArgumentException("bad formation");
}
String[] cal = calendarString.split("/");
return constructCalendar(cal[0], cal[1]);
@@ -203,14 +203,15 @@ public class CalendarUtil {
*
* @param date the string that matches "yyyy-mm-dd"
* @param time the string that matched "hh:mm"
- * @return a {@code Calendar} instance if both arguments are valid; {@code null} otherwise
+ * @return a {@code Calendar} instance
+ * @throws IllegalArgumentException if one of arguments is bad formatted
* @see #isValidDateString(String)
* @see #isValidTimeString(String)
*/
- @Nullable
+ @NotNull
public static Calendar constructCalendar(@NotNull String date, @NotNull String time) {
if (!isValidDateString(date) || !isValidTimeString(time)) {
- return null;
+ throw new IllegalArgumentException("bad formation");
}
String[] slices = date.split("-");
int y = Integer.parseInt(slices[0]);
diff --git a/app/src/test/java/org/cutem/cutecalendar/util/CalendarUtilTest.java b/app/src/test/java/org/cutem/cutecalendar/util/CalendarUtilTest.java
index 67ca010..a2f392b 100644
--- a/app/src/test/java/org/cutem/cutecalendar/util/CalendarUtilTest.java
+++ b/app/src/test/java/org/cutem/cutecalendar/util/CalendarUtilTest.java
@@ -125,8 +125,13 @@ public class CalendarUtilTest {
exp = new int[]{2018, 5, 2, 11, 30, 0, 0};
assertArrayEquals(exp, res);
- cal = CalendarUtil.constructCalendar(s3 + '/' + s2);
- assertNull(cal);
+ boolean ok = false;
+ try {
+ CalendarUtil.constructCalendar(s3 + '/' + s2);
+ } catch (IllegalArgumentException e) {
+ ok = true;
+ }
+ assertTrue(ok);
}
}
\ No newline at end of file